Repository navigation
Conversation
bbcac51 to
978e121
Compare
978e121 to
f89cfe7
Compare
f89cfe7 to
ae6b1ca
Compare
ae6b1ca to
4c9accd
Compare
4c9accd to
3128d83
Compare
3128d83 to
9606c1b
Compare
evanphx
left a comment
There was a problem hiding this comment.
The sealing and BuildKit-secrets parts look solid. My main question is the deferral layer: nodecaps, the Node schema fields, seal_deferred_runners on three RPCs, PinSecretsReport, and the CLI warnings.
v0.18 runners already resolve secrets through Secrets.Resolve. The only thing that turns them away from owned secrets is the empty-app_id refusal in servers/secret/server.go. Per ownership.go, runners aren't narrowed, and app_id is self-reported, so that refusal guards a runner from its own mistake rather than enforcing a boundary. The cross-app guarantee comes from secret.Pin when each config version is created, which this PR keeps.
Could we instead let an unbound (runner) caller with an empty app_id resolve owned secrets for one release, with a TODO to remove it? Then sealing always happens, and the whole deferral path, its RPC fields, and its warnings go away. It also covers a case the gate misses: an old runner that becomes ready after a config was sealed (runner upgrade rollback, or an offline runner rejoining) currently fails that config's sandboxes, since scheduling ignores capabilities.
| // A runner that can't name the app it resolves for is refused every owned | ||
| // secret, so sealing while one is ready would stop that app's sandboxes from | ||
| // starting there. Leave the value inline until it's upgraded. | ||
| ok, missing, err := nodecaps.AllNodesSupport(ctx, s.nodes, nodecaps.SecretOwner) |
There was a problem hiding this comment.
This asks once, when the config version is created, but the risk shows up later, when a sandbox is scheduled. A runner that becomes ready after sealing still gets these configs. Should the compatibility allowance live in Resolve instead?
Nit, only if the gate stays: AllNodesSupport lists every node once per sensitive var. Check it once in sealSensitive before the loops.
There was a problem hiding this comment.
I checked this against the code, and the timing gap is real. I missed it in my earlier reviews. AllNodesSupport deliberately skips nodes that aren't READY (pkg/nodecaps/nodecaps.go). Its doc comment says an old node that comes back "counts from then on", but that only affects writes made after it returns. A config sealed while the old runner was offline, or before an old-build runner joined, still holds the owned cluster ref. If such a runner is then picked for a sandbox, it can't name the app, so the secret is refused and the sandbox fails to start there. Nothing leaks, but the gate gives no promise about scheduling time.
I'll leave the design choice to you and the author: an allowance in Resolve, or something like keeping old runners out of placement for sealed configs. Moving it to Resolve would also remove the reason for nodecaps and for PinReport/SealDeferredError, which your other two threads point out. Your nit about calling AllNodesSupport once per sensitive var is right too: Seal lists every node on each call.
There was a problem hiding this comment.
You're right, and this was the stronger argument. Runners aren't narrowed and app_id is self-reported, so the empty-app_id refusal only protected an old runner from its own mistake. The line between apps is secret.Pin. I moved the allowance into Resolve: a caller that's bound to no app and sends no app_id can resolve an owned secret for this release, with a TODO to take it out in the next one. Sealing now always happens, which also covers the rolled-back or rejoining runner. The gate is gone, and the nit went with it.
There was a problem hiding this comment.
I checked the new head. The gate is gone from secret_sealer.go, and sealSensitive seals on every write. In Resolve (server.go:427), an owned secret now goes to a caller only if it sends no app_id, isn't bound to an app, and isn't under Cloud authorization. A bound caller or a Cloud-authorized caller is still refused, and so is a caller that names the wrong app. ownership_test.go covers each of those cases. This also closes the timing gap I'd confirmed earlier, for a runner that rejoins after sealing. I'm leaving this thread for you to resolve.
| // so each runner advertises its features on its node entity whenever it | ||
| // registers presence, and the coordinator asks whether every ready node has the | ||
| // one it is about to rely on. | ||
| package nodecaps |
There was a problem hiding this comment.
Is anything besides sealing planned to use this? With one capability and one caller, a general capabilities framework plus two schema fields looks premature, especially if a Resolve allowance makes it unnecessary.
There was a problem hiding this comment.
The only other planned caller was secret.typed in #1459, which a later release would have checked before it stopped writing sentinel env values. With the Resolve allowance neither one earns its keep, so nodecaps and the two Node fields are out of both PRs. When the sentinel does go, that release will require runners from this one or newer and say so in its upgrade notes.
|
|
||
| // PinReport describes what PinSecretsReport did beyond pinning, for a caller | ||
| // that tells the user about it. | ||
| type PinReport struct { |
There was a problem hiding this comment.
If deferral goes away, PinReport/PinSecretsReport can go too, and PinSecrets keeps its original signature.
There was a problem hiding this comment.
Done. PinReport and PinSecretsReport are gone and PinSecrets has its original signature back. The seal_deferred_runners fields, build saga v5, and the CLI warnings went with them.
A sensitive env var was only masked in the CLI. Its value sat in every config version in plaintext, and every build received it as a BuildKit build-arg, which writes it into the image's layers and cache. Cluster secrets already do this properly, so sensitive values now become secrets. Sealing happens inside PinSecrets, which every path that mints a config version already calls, so none of the six can forget to. Each inline sensitive value is written to <app>/<KEY> as a secret the app owns, and the config keeps a reference that is then pinned like any other. A service's env goes to <app>/<service>/<KEY>. A task's env goes to <app>/tasks/<task>/<KEY>, whose extra segment keeps it from ever meeting a service's path; task env gains a backend attr for this, and is pinned, resolved and kept from secret GC like service env. The whole config is sealed, not just what the caller changed, so an existing app moves over on its next deploy or env change. Old config versions are not rewritten: they age out with retention, and the changelog tells people to rotate what they care about. An env var name only has to leave out "=", but a cluster secret path segment must match [a-zA-Z0-9][a-zA-Z0-9_-]*. A name like _API_TOKEN or spring.datasource.password would fail to seal and block every write to its app, and web/KEY would land on service web's path. So each name and service or task goes through PathSegment: a valid one is used as is, and anything else, or anything already starting with x-, is escaped behind an x- prefix. Plain segments never carry the prefix and the escape is reversible, so two names can't share a path. Only the coordinator can seal, through a Sealer wrapped around its registry. The write requires ownership, so an operator's unowned secret already sitting at the path fails the write rather than quietly receiving an app's value. A runner from before ownership sends no app_id, and Resolve refused it every owned secret. Sealing would then stop sandboxes on any runner not yet upgraded, including one that comes back on an old build after the config was written. So for this release Resolve lets a caller bound to no app resolve an owned secret without naming one, with a TODO to refuse it again next release. That loosens nothing real: an unbound caller chooses its own app_id and could already name the owner. What keeps one app from another's secret is secret.Pin at config time, and that is unchanged. Builds no longer get sensitive vars as build-args. Their values go through the secrets session instead. Of the secret-backed vars, only one whose reference is its own sealed path comes along, since those values used to reach builds as build-args; a reference written by hand stays runtime-only, as it always was, and a build that needs one declares a build secret. An automatic language build exposes them as secret env on the steps that see user env (Elixir's mix steps, Rails asset precompile, the Next.js build, onbuild commands), so those apps keep working. A Dockerfile build gets each one as a secret named after the variable; an ARG with that name is now empty, and the build warns with the RUN --mount line to use instead. A [[build.secrets]] entry with the same id wins. miren env get --unmask is removed: secrets are write-only. The flag stays, hidden, only to say so. MIR-2144
9606c1b to
85ff1f0
Compare
There was a problem hiding this comment.
🍪 biscuit: ✅ ready to merge — auto-review, non-blocking
The latest push replaces the seal-time capability gate with a compatibility allowance in Resolve. I think that's the right fix for the scheduling-time gap evanphx raised. I found one bug elsewhere in the PR, though, and it should be fixed before merge: the conflict advice for task env tells users to do something the build silently throws away.
Task-env conflict advice leads to an empty variable. This happens when a shared secret already sits at <app>/tasks/<task>/<KEY>. refAdvice (components/coordinate/secret_sealer.go:75) then tells the user to reference it from the task's env in app.toml with backend and ref. But buildTasksConfig (servers/build/build.go:376-383) copies only Key, Value, Required, Sensitive and Description. It drops ev.Backend and ev.Ref, unlike the global path (line 729) and the service path (line 953), which both turn Ref into the value and keep Backend. appconfig.validateTasks also never calls validateReference.
So a user who follows the advice gets a task variable with an empty literal value and no backend. Sealing skips it because the value is empty, so the error goes away. Unless the variable is required, the deploy goes green and the task runs with no credential. TestRefAdviceMatchesTheVariableKind checks the advice text, but nothing checks that the advice works. To fix it, either:
- carry
BackendandRefthroughbuildTasksConfigthe way services do, addvalidateReferencetovalidateTasks, and add a test for a task env reference from app.toml; or - change the task branch of the advice to say only "move the shared secret".
The Resolve allowance (servers/secret/server.go:427). An owned secret now goes to a caller only when all three hold: the caller sends no app_id, isn't bound to an app, and isn't under Cloud authorization. A bound caller or a Cloud-authorized caller with no app_id is still refused, and so is a caller that names the wrong app. ownership_test.go covers each case plus the allowance. Your reasoning matches the code: an unbound caller could already name any app, so this doesn't loosen anything that was actually protecting secrets, and secret.Pin is still what keeps one app off another's secret. I found nothing left of nodecaps, PinReport or the deferral warnings, and PinSecrets has its original signature back.
For the human reviewer: two decisions are yours. The product question from my earlier reviews still stands: if an operator's unowned secret already sits at a seal path, writes to that app fail instead of the value being left inline. Also decide whether you accept the one-release window in which an unbound caller, such as an mTLS admin CLI, can resolve an owned secret without naming its app. I'm not recommending approval without a person's read, given the bug above and how security-sensitive the change is across the coordinator, the secrets server and the build server.
🍪 full review note · reviewed at 85ff1f0
Inline comments
components/coordinate/secret_sealer.go:75
This advice doesn't work today. buildTasksConfig (servers/build/build.go:376-383) drops ev.Backend and ev.Ref for task env, so a task [[env]] with backend/ref becomes Key=K, Value="" with no backend. sealSensitive skips an empty value, so the conflict error goes away and the task runs with an empty variable. Either make task references work end to end, or change this branch to say only "move the shared secret to another path".
servers/build/build.go:378
Task env loses Backend and Ref here, while the global path (line 729) and the service path (line 953) both turn Ref into the value and keep Backend. This PR gives task env a backend attr and advises task-env references in refAdvice, so this path needs the same treatment: value, sensitive = ev.Ref, true when ev.Backend != "", plus Backend: ev.Backend. appconfig.validateTasks should also call ev.validateReference, like services and global env do. A test with a task env reference from app.toml would pin it down.
A sensitive env var (
-s, orsensitive = truein app.toml) was only masked in the CLI. Its value sat in plaintext in every config version, and every build got it as a BuildKit build-arg, which bakes it into image layers and cache. We already have real cluster secrets, so sensitive values now become secrets that belong to their app.Sealing happens in
PinSecrets, which every path that mints a config version already runs, so an existing app moves over on its next deploy or env change. Old versions aren't rewritten. They age out, and the changelog tells people to rotate what they care about. Builds get the values through BuildKit's secrets session: language stacks see them as secret env on the steps that read user env, and a Dockerfile build gets one secret per var and warns if it still declares a matchingARG.env get --unmaskis gone since secrets are write-only; the flag stays, hidden, just to say so.A runner from before MIR-2235 sends no
app_id, andResolverefused it every app-owned secret, so sealing would have stranded sandboxes on any runner not yet upgraded. For this releaseResolvelets an unbound caller with noapp_idthrough, with a TODO to refuse it again next release. That doesn't loosen anything that was holding: an unbound caller picks its ownapp_id, and what keeps one app off another's secret issecret.Pinwhen the config is written.The one real behavior break is a Dockerfile that reads a sensitive var through
ARG. The upgrade notes cover it. The typed secret field from MIR-2250 is stacked on top of this.Closes MIR-2144