Submit an issue View all issues Source
MIR-2250

Carry secrets in a typed field on the sandbox spec instead of a `miren+secret://` env prefix

Open public
phinze phinze Opened Nov 12, 2026 Updated Nov 12, 2026

Today a secret reaches a container as an ordinary env entry whose value starts with miren+secret://. The sandbox spec's env is a flat KEY=VALUE list, and the runner resolves any value that matches the prefix. So whether something is a secret gets decided by matching a pattern on a string that many sources write.

That leaves the line between a literal and a reference for every producer to enforce. Reviewing MIR-2235 turned up four separate ways to slip a matching string past it:

  • a literal value
  • a literal in task env
  • env supplied at deploy time
  • an env key containing =

Each is now refused at pin time, and the coordinator and runner only hand an owned secret to its own app's sandboxes, so none of these leaks anymore. But the defence is still a list of things to reject. It also ties secrets to env, when apps often need them as files instead (MIR-722).

The proposal is to give the container spec a secrets field that is separate from env. Each entry names a secret (backend and ref) and how to project it into the container:

secrets:
  - backend: cluster
    ref: shop/db-password@k2T
    env: DATABASE_PASSWORD           # as an env var
  - backend: cluster
    ref: shop/tls-key@m4Q
    file: /etc/shop/tls.key          # as a file
    mode: "0400"

appspec.Build puts every secret-backed variable here. Plain env only ever holds literals, and the runner never interprets it. Projection is a per-entry choice, so file delivery (MIR-722) becomes a new projection on the same field rather than another path. It would also let the same secret appear both ways, if that's ever useful.

A literal can then never become a reference. The sentinel scheme and rejectLiteralsPosingAsReferences go away, and the = check becomes ordinary input hygiene.

The catch is version skew. An older runner given a spec with secrets would start the container without them. That needs one release where both forms are written, or a runner capability check before the coordinator stops writing the prefix.

This should land before the write-as-secret work in MIR-2144, since that's what will make secrets common.

Later, separately: the coordinator currently trusts the app a runner names when resolving. Kubernetes' Node authorizer and Swarm only deliver a secret to a node running a workload that uses it. The equivalent here is to check that the requesting runner actually hosts a sandbox of that app. This protects against a compromised runner, which is a different threat model from this ticket.

+++ Agent notes

  • Today's flow. pkg/appspec/appspec.go builds appCont.Env with secret.EnvValue(backend, value), which emits the sentinel for secret-backed variables. controllers/sandbox/sandbox.go calls secret.MaterializeEnv on co.Env.
  • Code that goes away. rejectLiteralsPosingAsReferences and rejectKeysWithEquals in api/core/secretpin.go, and pkg/secret/sentinel.go.
  • Ownership enforcement from MIR-2235 to keep. It applies unchanged to the typed field:
    • MaterializeEnv → CheckOwner with the sandbox's app (sandboxAppID, via the spec's version).
    • The app is passed to any secret.AppResolver.
    • Secrets.Resolve returns an owned secret only when the request's app names its owner.
  • File projection. The sandbox controller already writes literal config files (cf.Mode/cf.Data handling in buildSubContainerSpec). A file projection of a secret should write to tmpfs rather than the sandbox's on-disk path, so plaintext never touches disk.
  • Version skew. Distributed runners resolve through pkg/secret/remote. rpc.NetworkClient.HasMethodParam is the existing capability-probe pattern.

+++