Give secrets an owning app and scope access to it
The Secrets service doesn't know about apps. Any authenticated caller can resolve, overwrite, or list any secret. RFD-90 left this open as "per-secret access scoping." That's been tolerable while secrets are things operators create by hand. It stops being tolerable once MIR-2144 stores every app's sensitive env vars as secrets. At that point a caller bound to one app could read or replace another app's credentials.
A secret gets an optional owning app, stored as a ref on the secret entity. The server sets it when it creates a secret on an app's behalf. When a caller bound to an app (OIDC bound_app or workload identity) runs miren secret set, the new secret belongs to that app too. Ownership comes from that attribute, not from the secret's path, so the namespace stays open. Deleting an app deletes the secrets it owns, so an app recreated under the same name starts with none. App ids are derived from the name today, so the ref alone wouldn't prevent that.
A bound caller has full access to secrets its own app owns. Secrets owned by another app are hidden from list. They're denied for resolve, set and setState. Under Cloud logical authorization, owned secrets are checked against the owning app: reads as read, writes as configure.
A secret owned by an app can only be referenced from that app's own config, whether the reference comes through env set --ref, deploy, or app.toml. A deployed reference ends up in a container's environment, so referencing a secret counts as reading it. The check looks at the config's app rather than the caller, so it holds for operators too, and for a build that a saga resumes with no caller attached. A secret meant for several apps stays unowned.
Unowned secrets work exactly as they do now, for every caller. Unbound callers keep today's access. That covers runners, which resolve every app's secrets to start sandboxes, internal components, and operators, so secret list on a cluster still shows an operator everything.
+++ Agent notes
- Schema: add an indexed
appref tosecretinapi/core/schema.yml, then regenerate. Name itapp, notowner, so it doesn't collide withApp.OwnedBy, which Cloud RBAC already uses. - RPC handlers:
servers/secret/server.go. Helpers:rpc.BoundApp/rpc.AllowApp(pkg/rpc/authenticator.go) andrpc.AuthorizeResource. Read the warning onrpc.AppAction(pkg/rpc/authorization.go) before deciding whether the secrets methods go on that list. - Reference-time checks:
mergeIntoSpec/pinSecretsinapi/app/envvar.go, andbuildVariablesFromAppConfig/resolveBuildSecretsinservers/build/build.go. Today pinning resolves in-process and never goes through the RPC gate. Build pinning runs in thecreateConfigVersionsaga action, where a recovered build has no caller identity, which is why the rule keys on the config's app. - App deletion: delete owned secrets via the indexed
appattribute. App ids areapp/<name>(api/app/client.go), so without this a recreated app inherits them. - Rewrite the "per-secret scoping" paragraph in the
Resolvedoc comment to match. - There's no service-level ownership. No principal is scoped smaller than an app, and per-service delivery is already handled by
spec.Services[].Env.
+++