Vault
A Vault is a store for the secrets your software creates or changes while it runs, such as tokens from an integration or keys it rotates, in the cloud's own secret service. The values stay in the customer's environment, encrypted by the cloud provider, and the customer can audit access with their own tools.
import * as alien from "@alienplatform/core"
const credentials = new alien.Vault("credentials").build()
const api = new alien.Worker("api")
.code({ type: "source", src: "./api", toolchain: { type: "typescript" } })
.link(credentials)
.permissions("execution")
.build()
export default new alien.Stack("acme")
.add(credentials, "frozen")
.add(api, "live")
.permissions({
profiles: { execution: { credentials: ["vault/data-read", "vault/data-write"] } },
})
.build()In this stack:
.link(credentials)connects the vault to theapiWorker, the workload (the running code) that uses it. Alien injects the vault's connection details, its binding, into the Worker, read by the SDK client.- The
executionpermission profile, the named set of cloud permissions a workload runs with, grantsvault/data-readandvault/data-write. "frozen"means the customer's admin creates the vault during initial setup."live"resources, like the Worker, are created and updated by Alien on every release. See Frozen and live.
The api Worker writes and reads secrets at runtime:
import { vault } from "@alienplatform/sdk"
const credentials = vault("credentials")
await credentials.putJson("github", { token: "ghp_example" })
const github = await credentials.getJson<{ token: string }>("github")Platforms
credentials becomes secrets in the environment's native secret service:
| Platform | Backing service | Created by |
|---|---|---|
| AWS | SSM Parameter Store SecureString parameters named <prefix>-<secret> | Nothing to create. The vault is a name prefix. |
| GCP | Secret Manager secrets named <prefix>-<secret>, automatic replication | Nothing to create. The vault is a name prefix. |
| Azure | One Key Vault per Vault resource, Standard SKU, Azure RBAC | Alien |
| Kubernetes | Kubernetes Secrets in the deployment's namespace | Nothing to create. Secrets are created on first write. |
| Machines | A vault the customer provides | The customer, through an external binding. The resource must be "frozen". See Machines. |
| Local | vault/<id>/secrets.json in the local state directory, not encrypted | Alien |
<prefix> is the stack's resource prefix followed by the Vault's ID.
Frozen or live
Vault can be "frozen" (created once during initial setup by the customer's admin) or "live" (created and updated by Alien on releases). See Frozen and live.
The ID may contain letters, digits, -, and _. On Azure it becomes part of a Key Vault name, which limits the ID to 15 characters.
Alien reserves two IDs for its own vaults. Don't declare a Vault with either:
secretsholds environment secrets.deployer-secretsholds secrets the deployer (the person who runs the initial setup, usually the customer's admin) writes with their own credentials.
Alternatives
Vault is for secrets your code writes at runtime. For secrets the deployer enters during initial setup, or that you set per deployment, use stack inputs and environment secrets:
| Inputs and environment secrets | Vault | |
|---|---|---|
| Set by | The deployer at initial setup, or you per deployment | Your code at runtime |
| Read by | Environment variables | SDK calls |
| Changes take effect | On the next deployment | On the next get |
Use KV for non-secret state, and Key to encrypt data with a customer-managed key.
Options
| Method | Type | Default | Notes |
|---|---|---|---|
.enabled(input) | boolean stack input | always on | Creates the resource only when the input is true. |
The backing service follows the platform. There are no other options.
Use it from code
import { vault } from "@alienplatform/sdk"
const credentials = vault("credentials")
await credentials.putJson("github", { token: "ghp_example" })
const github = await credentials.getJson<{ token: string }>("github")
await credentials.delete("github")Every method is in the API reference.
Common patterns
Name secrets so they work everywhere
Use lowercase letters, digits, and hyphens, such as github-token. Azure turns _ into - and Kubernetes lowercases names, so API_KEY and api-key can end up as the same secret.
Keep values under 4 KB, the smallest limit across platforms. See Behavior and limits.
Store structured secrets
putJson and getJson (TypeScript) serialize to and from a JSON string, so you can keep related values, such as a client ID and secret, under one name. In Python and Rust, serialize with json or serde_json.
Cache reads
Every get is a call to the cloud's secret service, and some services throttle reads. Read a secret once at startup, or cache it for a few minutes, instead of reading it on every request.
Keep a list of names yourself
list() works only on Kubernetes and Local. On AWS, GCP, and Azure it fails with OPERATION_NOT_SUPPORTED.
To enumerate secrets, store the names you've written in a KV entry or a separate secret.
Management access
By default, only workloads you grant can read or write a Vault you declare. Alien's management identity, which runs remote bindings for your hosted software, can't.
To let your hosted software write secrets into a customer's vault, for example after an OAuth flow, extend management permissions:
export default new alien.Stack("acme")
.add(credentials, "frozen")
.permissions({
profiles: { execution: { credentials: ["vault/data-read"] } },
management: { extend: { credentials: ["vault/data-write"] } },
})
.build()vault/data-write creates, updates, and deletes secrets but can't read values back. Grant vault/data-read to management only if your hosted software must read secret values.
Permissions
| Set | Grants |
|---|---|
vault/data-read | Reading secret values. |
vault/data-write | Creating, updating, and deleting secrets, without reading values. |
vault/certificate-management | Managing application TLS certificates in the shared vault. |
vault/provision, vault/management, vault/heartbeat | Used by initial setup and by Alien's management identity. |
Linking a Vault to a workload with no permission set named for it grants vault/data-read and vault/data-write. See Permissions.