Stash
This feature is alpha. Names, fields, and behavior can change or be removed at any time without notice.
The stash keeps small values about your infrastructure next to the project, environment, component, instance, or deployment they describe. People, the Massdriver UI, the CLI, automations, and later deployment steps can all read them.
Each project, environment, component, instance, and deployment has its own stash. A stash holds key and value entries, such as db/hostname = billing-dev.cluster-abc.us-east-1.rds.amazonaws.com or md/v1/health = {"state": "healthy"}. Massdriver keeps an entry until you delete it or until it expires.
Who writes to the stash​
| Writer | How it signs in | Example |
|---|---|---|
| A provisioner during a deployment | The deployment's token. Massdriver sets it in every step. Use mass alpha stash or the Terraform provider. | A Terraform step records the database host for a later step. |
| A CI job or a script | A service account's access token, with mass alpha stash, the Terraform provider, or the GraphQL API | A release job records the version that it deployed. |
| An automation | A service account's access token | The stash-sync automation copies CloudWatch and Prometheus metrics into widget keys. |
| A person | Your own login, with the CLI or the API | You set a maintenance banner on an environment. |
Who reads the stash​
| Reader | What it reads |
|---|---|
| The Metadata panels in the UI | Entries that have a label. See Metadata. |
| Automatic widgets in the UI | Well-known md/v1/ keys. See Well-known keys. |
| Notes and widgets that you pin | Any key that you choose. See Annotations. |
| Later deployment steps | Any entry in the stashes that the deployment's token can read |
| Event destinations | stash_entry.set and stash_entry.deleted events. See Events. |
| Other automations and scripts | Any entry that their service account can read |
Use cases​
Pass a value between deployment steps​
One step writes a value to the deployment's stash. A later step reads it.
mass alpha stash set "$MASSDRIVER_DEPLOYMENT_ID.db/hostname" "$DB_HOST"
DB_HOST=$(mass alpha stash get "$MASSDRIVER_DEPLOYMENT_ID.db/hostname")
In Terraform, the massdriver_stash_entry resource writes an entry, and the massdriver_stash_entry data source reads one.
Record what a deployment did​
Write the result of each step to a well-known deployment result key. The deployment's details show a Results section, and the instance's Signals tab shows the latest results.
mass alpha stash set "$MASSDRIVER_DEPLOYMENT_ID.md/v1/changes/$MASSDRIVER_STEP_PATH" \
'{"tool": "opentofu", "add": 2, "change": 3, "destroy": 0}' --format json
mass alpha stash set "$MASSDRIVER_DEPLOYMENT_ID.md/v1/cost_estimate" \
'{"tool": "infracost", "currency": "USD", "monthly_before": 41.20, "monthly_after": 41.58}' --format json
Show live health, usage, and traffic on the canvas​
Write md/v1/health, md/v1/usage, or md/v1/traffic on an instance. A status dot, a usage bar, or traffic on its lines shows on the canvas for everyone with stash:view. Set a TTL so that the widget goes away when the writer stops.
mass alpha stash set billing-dev-app.md/v1/health '{"state": "degraded"}' --format json --ttl 600
mass alpha stash set billing-dev-app.md/v1/traffic '{"rps": 240, "errors_5m": 2, "p95_ms": 180}' --format json --ttl 600
Put runbook and product links in an environment's header​
Write md/v1/links on the environment. Each link is a button in the environment header.
mass alpha stash set billing-dev.md/v1/links \
'{"links": [{"label": "Runbook", "url": "https://wiki.example.com/billing"}, {"label": "Shop", "url": "https://shop.example.com"}]}' \
--format json
Show a banner for a maintenance window​
Write md/v1/banner on the environment with a TTL that ends with the window. The banner goes away when the entry expires.
mass alpha stash set billing-dev.md/v1/banner \
'{"message": "Database upgrade from 22:00 to 23:00 UTC", "level": "warning"}' \
--format json --ttl 7200
Mark a one-time task as done​
An immutable entry cannot be set again until it expires or is deleted. The write fails when the key already has a value, so a step can use it to run only once.
if mass alpha stash set "$MASSDRIVER_DEPLOYMENT_ID.migrations/ran" true --immutable; then
./run-migrations.sh
fi
Keep a value for a set time​
Set a TTL in seconds. The entry is deleted when the time ends. Compute the value again when it is missing.
AMI=$(mass alpha stash get billing-dev-app.ami-id) || {
AMI=$(./find-latest-ami.sh)
mass alpha stash set billing-dev-app.ami-id "$AMI" --ttl 86400
}
Keep a secret that a later step needs​
A sensitive entry is encrypted with your organization's key. Only callers with stash:export, and deployment tokens that can write the stash, can read the value. It never shows in events, notes, or widgets.
terraform output -raw kubeconfig | mass alpha stash set billing-dev.kubeconfig - --sensitive
How it works​
- Stashes do not inherit. A key on an environment is not visible from the stash of its instances or deployments. To read it, read the environment's stash.
- A set replaces the whole entry. The value, format, label, TTL, and flags all come from the new write. A setting that you leave out goes back to its default.
- Well-known keys. Keys that start with
md/are reserved. The server checks eachmd/write against the key's schema. See Well-known keys.
Entries​
| Field | Rules |
|---|---|
| Key | Letters, digits, and the characters _, ., /, and -. Up to 255 characters. |
| Value | Always a string. Massdriver returns it exactly as written. It cannot contain the null character. |
| Format | TEXT (the default) or JSON. A JSON value must be a JSON object. The API also returns a JSON value parsed, in the data field. |
| Label | Optional. A name for the entry, up to 255 characters. An entry with a label shows as a row on the Metadata panels. A label is not encrypted. |
| TTL | Optional. Seconds until the entry expires, up to 315360000 (10 years). An expired entry is not returned, and is deleted within 10 minutes. Without a TTL, the entry stays until you delete it. |
| Immutable | Optional. When true, the key cannot be set again until the entry expires or is deleted. You can delete it. An immutable write fails when the key already has a value. |
| Sensitive | Optional. When true, the value is encrypted with your organization's key and masked for callers without stash:export. It is never sent in events and never available to notes or widgets. A well-known md/ key cannot be sensitive. |
Limits​
| Limit | Default | Setting for self-hosted installations |
|---|---|---|
| Value size | 65536 bytes | MD_STASH_MAX_VALUE_BYTES |
| Keys in one stash | 1000 | MD_STASH_MAX_KEYS_PER_SCOPE |
Expired entries do not count toward the key limit.
Permissions​
The stash has its own access control actions.
| Action | Lets you |
|---|---|
stash:view | Read entries, without sensitive values, and subscribe to their changes |
stash:write | Set and delete entries |
stash:export | Read sensitive values |
Each action is checked against the entity that holds the entries: the project, environment, component, or instance. A deployment's entries belong to its instance. Conditions on that entity's attributes apply. stash:view does not come with project:view. Grant it on its own.
A deployment's own credentials do not use these actions. A deployment can read and write the stash of that deployment and of its instance, environment, component, and project. It can also read, but not change, the stash of each instance whose resources its instance uses as dependencies, without their sensitive values.
Events​
Each set and delete sends an event. An entry that expires sends no event. A key that Massdriver sets itself, such as a UI notice, sends only the alphaStashEvents event.
- The
projectEvents,environmentEvents,instanceEvents, anddeploymentEventssubscriptions send anAlphaStashEntryEvent. Which subscriptions get it depends on the entity that holds the entry. - The audit log and event destinations get
stash_entry.setandstash_entry.deletedevents. - A sensitive entry never includes its value in an event.
| Stash | Subscriptions |
|---|---|
| Project | projectEvents |
| Environment | projectEvents, environmentEvents |
| Component | projectEvents |
| Instance | environmentEvents, instanceEvents |
| Deployment | environmentEvents, instanceEvents, deploymentEvents |
The alphaStashEvents subscription also sends sets and deletes for a project and one environment.
Where stash values show​
| Place | What shows |
|---|---|
| The Signals tab of an instance | The instance's widgets, its latest deployment results, its scorecards, and its labeled entries |
| The deployment's details | A Results section and a Deployment metadata section with the deployment's labeled entries |
| The Metadata card on the project overview | The project's labeled entries |
| The canvas and the environment header | Automatic widgets from md/v1/ keys, and widgets and notes that you pin |
| The notice bell in the app header | Notices when a project or environment is created, and when a deployment is proposed, approved, started, or finished |
These places update when a stash value changes. You do not need to reload the page. An entry that expires does not send an update. The UI removes it when its time ends.
Next​
- Well-known keys
- For provisioners
- CLI
- Terraform
- GraphQL API
- Recipes
- Annotations: notes and widgets that show stash values in the UI