sandbox-on-join
When a person joins a configured group, fork a template environment for them. When they leave, decommission the fork and, if configured, delete it.
The fork gets two attributes:
owner=<email>, the email of the personsandbox=true
The fork identifier comes from the local part of the email, lowercased, with every character other than a-z
and 0-9 removed, and cut to 20 characters. Sam.Lee@example.com in project api gets api-samlee. When the
project already has that environment, the next free one of samlee2 to samlee99 is used.
A person gets one sandbox for each template. When they join a group and already have a sandbox from the same template, nothing happens.
When a person leaves a group, every sandbox they own from that group's templates is decommissioned, unless
another of their groups gives them the same template. A sandbox with no PROVISIONED or FAILED instances
is deleted right away if deleteAfterDecommission is set.
Each instance that finishes a DECOMMISSION sends a deployment.completed event. When the sandbox then has
no PROVISIONED or FAILED instances, its owner is not in a group that gives its template, and Massdriver
reports it as deletable, the sandbox is deleted. A sandbox that the owner decommissions while still in the
group is kept.
Before each action, the current group memberships of the person are read from the API. Events that arrive out of order or twice do not fork or tear down a second time.
Service accounts that join a group are ignored.
Settings​
The config file holds a list of rules under sandboxes. At least one rule is required. A group can have more than
one rule. An unknown key stops the automation at start.
| Key | Default | |
|---|---|---|
sandboxes[].group | Required. The group name, as shown in Massdriver, or the group ID. | |
sandboxes[].project | Required. The project of the template environment. Forks go into the same project. | |
sandboxes[].environment | Required. The template environment. | |
sandboxes[].deploy | false | Deploy the fork after it is created. |
sandboxes[].deleteAfterDecommission | false | Delete the fork after its decommission completes, when the person leaves. |
sandboxes[].copyEnvironmentDefaults | false | Copy the template's environment defaults. |
sandboxes[].copySecrets | false | Copy the secrets of the template's instances. |
sandboxes[].copyRemoteReferences | false | Copy the template's remote references. |
sandboxes:
- group: Developers
project: api
environment: staging
deploy: true
deleteAfterDecommission: true
copyEnvironmentDefaults: true
copySecrets: false
copyRemoteReferences: false
The bundle's Settings params have the same keys as the config file. Rules lists the groups and projects of
your organization to pick from. The full commented file is
config.example.yaml.
Custom attributes​
If your organization declares any custom attributes,
at any scope, Massdriver accepts only declared keys with declared values on an environment. Declare owner at the
ENVIRONMENT scope with the email of every person who can get a sandbox, and sandbox with the value true.
Without them, every fork fails with the message rollback. An organization with no custom attributes accepts any
key and value.
Secrets​
sandbox-on-join has no secrets of its own. It uses the MASSDRIVER_* variables of the
common settings.
Permissions​
The service account needs:
project:viewon the template's project, andenvironment:createfor environments with the attributesownerandsandboxenvironment:deploy,environment:decommission, andenvironment:deleteon the forks- with the
copy*options:resource:viewand a resource grant for each copied environment default and remote reference, andinstance:configureon each template instance with secrets - with the bundle:
organization:manageEventDestinations
Host​
Massdriver sends events to https://<host>/hooks/massdriver, set in Ingress > Host. That path must be public.
On ECS, an empty host uses sandbox-on-join.<domain of the cluster's hosted zone>. Refer to
Deploy for the platform details.
Event destination​
The bundle creates a destination for group_membership.added, group_membership.removed, and
deployment.completed, with no attribute filter. Its condition passes membership events of a person (not a service
account) in a group that a rule names, by name or by ID, and DECOMMISSION deployments of environments with
sandbox=true.
To create the destination yourself:
mass event destination create \
--name sandbox-on-join \
--url https://sandbox.example.com/hooks/massdriver \
--event-type group_membership.added \
--event-type group_membership.removed \
--event-type deployment.completed \
--condition '((.type | startswith("group_membership.")) and .data.entity.account_id != null and .data.entity.group_name == "Developers") or (.type == "deployment.completed" and .data.metadata.deployment_action == "DECOMMISSION" and .data.attributes.sandbox == "true")'
List each configured group in the condition, for example
(.data.entity.group_name | IN("Developers", "Contractors")), or .data.entity.group_id for a group named by ID.
Do not set --attribute: group membership events have no attributes, so an attribute filter drops them.
Copy the signing secret from the destination into MASSDRIVER_SIGNING_SECRET.
Run​
docker run -p 8080:8080 \
-v "$PWD/config.yaml:/etc/massdriver-automations/config.yaml:ro" \
-e MASSDRIVER_ORGANIZATION_ID=acme \
-e MASSDRIVER_API_KEY=md_... \
-e MASSDRIVER_SIGNING_SECRET=whsec_... \
ghcr.io/massdriver-cloud/massdriver-automations:0.3 run sandbox-on-join
Limits​
- Duplicate events are dropped by id for one hour, in memory. Run one replica.
- The automation responds before it forks, deploys, decommissions, or deletes. A failed call is logged, and Massdriver does not retry it.
- Deleting a group does not send
group_membership.removedfor its members. Their sandboxes stay. - A person who joins a group before they register gets their sandbox when they accept the invitation.
- A decommission that fails leaves a
FAILEDinstance, and the sandbox is not deleted. Decommission it again to finish the teardown. - The owner is matched by email. When a person changes their email, the old sandbox is not found.