spec: named-unit declarations from an operator parameter
#114 follow-up. Root reads /carlos/host/named-units/<instance-id> (operator-written, box read-only) in its adopt pass and installs it as /etc/carlos/named-units.json under the config-sync lock, so declaring a unit needs no SSM session. Outcomes reach the operator through the heartbeat. Approach A and heartbeat visibility chosen by Paul, 2026-11-19. Draft for approval.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+325
−0
docs/superpowers/specs/2026-11-19-named-units-from-parameters-design.md+325 −0
CI cancelled — superseded by a newer push — run details
Intent
Attributed to this commit: 26.1 g CO₂e (2,435,802 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on named-units-param-114, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.
diff --git a/docs/superpowers/specs/2026-11-19-named-units-from-parameters-design.md b/docs/superpowers/specs/2026-11-19-named-units-from-parameters-design.md| new file mode 100644 |
| index 000000000..eb9894faf |
| --- /dev/null |
| +++ b/docs/superpowers/specs/2026-11-19-named-units-from-parameters-design.md |
| @@ -0,0 +1,325 @@ |
| +# Named-unit declarations from a parameter (#114 follow-up) |
| + |
| +Status: draft for Paul, 2026-11-19. Branch `named-units-param-114`. |
| + |
| +## Why |
| + |
| +#114 (bf4df27, released in v0.31.0) delivers an app's config to a |
| +systemd unit that is not `carlos-app@`, but only when root finds a line |
| +for that unit in `/etc/carlos/named-units.json`. Paul's ruling of |
| +2026-10-28: a root-owned declaration decides, and the registry selects |
| +but never authorizes. Today the only ways to get that file onto a box |
| +are provisioning before the agent starts, or a root shell running |
| +`carlos system named-units install <file>`. On an existing box that |
| +means an SSM session, and Paul's ask on #114 was to stop using SSM for |
| +this. So nothing has been declared anywhere yet, and the feature that |
| +#114 was filed for is still dark. |
| + |
| +This change gives root a second, remote source for the same file: a |
| +parameter an operator writes with their own AWS credentials, which root |
| +reads and installs during its normal pass. Nobody opens a shell on the |
| +box, and nobody handles a plaintext secret there. |
| + |
| +## Goals |
| + |
| +1. An operator declares, changes or clears a box's named units from |
| + their own machine, with one command and no session on the box. |
| +2. The declaration stays root-owned in the sense that matters: nothing |
| + that runs on the box (the agent, a tenant process, a box-role |
| + credential) can write or steer it. |
| +3. The box picks the change up within one config-only pass when anything |
| + triggers one, and within the hourly full pass otherwise. |
| +4. Every outcome is visible from the operator's machine: whether the |
| + box took the value, and if not, why. A bad, unreadable or unpermitted |
| + parameter leaves the installed file as it was. |
| + |
| +## Non-goals |
| + |
| +- **Base files** (`/etc/carlos/units/<unit>.base.env`). They are |
| + optional (`baseenv.go:60-69`; the drop-in lists them with `-`), and a |
| + unit that sets its own start-up values with inline `Environment=` |
| + lines needs none. Base files can hold secrets, which would need |
| + SecureString and `kms:Decrypt` on fixed boxes. The console's base file |
| + belongs to #453. |
| +- **Group-launched boxes.** They are replaceable and host no named units |
| + today. They also have no fixed instance identity to key on. A |
| + region-level declaration for them can come later under |
| + `/carlos/<deployment>/<region>/units/`, which their role can already |
| + read. |
| +- **Non-AWS boxes** (devboxes, other providers). They keep the local |
| + install verb. The source sits behind a small interface (below) so a |
| + provider adapter can be added later. |
| +- Any change to the declaration's shape, the delivery rails, or the |
| + release path's reading of the file. |
| + |
| +## Anti-goals |
| + |
| +- **A source the box can write.** The parameter must be written only by |
| + operator credentials. If a deployment's box role can `PutParameter` on |
| + the path, the design is broken there. |
| +- **Losing a working file to a transient failure.** A throttled, |
| + unreachable or denied read must never remove or empty the installed |
| + file. |
| +- **Churning the file.** Rewriting it with the same bytes gives it a new |
| + inode, and the release path then refuses to resume a recorded rollback |
| + for every named host on the box (`proofnamed.go:82-100`, |
| + `proofbinding.go:241-244`). |
| + |
| +## Constraints found in the code |
| + |
| +- **Fixed boxes don't know their deployment name.** host.env has no such |
| + key (`hostenv.go:40-111`). Their role's only parameter grant is |
| + `ssm:GetParameter` on `var.ssm_parameter_arn` (`region-host/main.tf:218-222`). |
| + Deployments set that to `parameter/carlos/*` or `parameter/carlos/host/*`. |
| + There is no `GetParametersByPath` and no `kms:Decrypt`. |
| +- **No box role can write parameters.** No `ssm:PutParameter` appears in |
| + any module. |
| +- **The box agent can read parameters.** It runs as `carlos`, reaches |
| + IMDS, and so holds the same read credentials. Reading grants no |
| + authority, so this is acceptable. The declaration holds no secrets. |
| +- **The release path reads the same file.** It uses |
| + `DisallowUnknownFields` and refuses an unknown account |
| + (`proofnamed.go:101-121`). appconfig's decoder ignores extra fields. A |
| + parameter that passes appconfig's decoder alone could still break |
| + releases for every named host. |
| +- **The root pass is `runAdopt`.** It runs hourly through |
| + `carlos-adopt.timer`, and as `--config-only` whenever the agent |
| + touches `/data/config-sync-requested` after a config generation moves |
| + (`agent.go:2371-2381`). `SyncUnits` runs in both, under the |
| + config-sync flock. |
| + |
| +## Approaches considered |
| + |
| +- **A. An operator-written parameter that root reads (chosen by Paul, |
| + 2026-11-19).** It matches how host.env reaches group boxes, uses |
| + credentials and IAM that already exist, and adds one read to a pass |
| + that already runs. |
| +- **B. A declaration signed with the release key and kept in the |
| + bucket.** Root would verify it with the public key every box already |
| + holds. It is provider-neutral, but every declaration change would need |
| + whoever holds the release key, and that key would gain a second job. |
| +- **C. A declaration signed by the console, set through a door |
| + command.** This is the friendliest option, but it makes the console an |
| + authority over root on boxes. That is the registry-steers-root problem |
| + the four #114 review rounds closed. Dropped. |
| + |
| +## Design |
| + |
| +### Where the parameter lives |
| + |
| +One parameter per fixed box: |
| + |
| + /carlos/host/named-units/<instance-id> |
| + |
| +It is a `String` parameter, not a SecureString, in the box's own AWS |
| +region. Its value is the whole `named-units.json` document, byte for |
| +byte. The path fits under both scopes deployments use today |
| +(`/carlos/*` and `/carlos/host/*`), so most fixed boxes can read it |
| +without an IAM change. |
| + |
| +Root takes the instance ID and the AWS region from the IMDSv2 identity |
| +document. It reads them itself, the way `haself.go` already does, and |
| +never from the environment, host.env or the bucket. Keying on the |
| +instance ID means that when a box is replaced, the new box has no |
| +declaration until an operator writes one. That is the safe default: |
| +delivery to its units is refused with the reason, as it is today with no |
| +file. |
| + |
| +### What root does each pass |
| + |
| +The fetch is one new step in `runAdopt`, ahead of the `SyncUnits` call |
| +and outside it. It takes the config-sync flock itself, does its work and |
| +releases the lock. `SyncUnits` then takes the flock and reads the file |
| +as it does today. Both the full and the config-only passes run the step. |
| +It does not depend on `CARLOS_SECRETS_KEY`: the release path reads the |
| +same file, so a box without the key still installs declarations. (My |
| +call, from the builder check: placing the step inside `SyncUnits` would |
| +silently skip boxes without the key.) |
| + |
| +1. Skip on boxes that can't take a per-box declaration, without any |
| + network call: no IMDS identity (not EC2), a group-launched box |
| + (`/etc/carlos/group.json` present), or a managed-fleet box (fleet |
| + identity resolves). These would otherwise fail every pass with |
| + AccessDenied. (My call.) |
| +2. `GetParameter` on the box's path. |
| +3. Act on the result: |
| + |
| + | Read result | Root does | |
| + |---|---| |
| + | `ParameterNotFound` | Nothing. The installed file, if any, stays. This keeps boxes that were provisioned or hand-installed working, and makes the feature opt-in per box. | |
| + | Any other error (denied, throttled, network) | Nothing to the file. Log once per pass: `named-units: parameter <path> unreadable: <err>; the installed declarations stand`. | |
| + | A value | Validate it (next section). If it is invalid, log the reason and leave the file. If it is valid and its bytes equal the installed file, do nothing. Otherwise install it. | |
| + |
| +4. **Hold the install while a rollback is recorded.** If the release |
| + path has a recorded restart or rollback binding for any host the |
| + current file names (`/var/lib/carlos-release/private/restarts`), |
| + don't install. Report `held: a recorded rollback of <host> needs the |
| + current declarations` and try again next pass. A new file identity |
| + would otherwise strand that rollback, with nobody on the box to |
| + notice. (My call, from the builder check.) |
| +5. Installing goes through the existing `InstallNamedUnits` body |
| + (validate, temp file, fsync, rename, directory fsync). The step |
| + already holds the lock, so the builder splits the function into a |
| + locked and an unlocked half rather than taking the flock twice. |
| +6. Write the status record (see Visibility), then release the lock. |
| +7. The pass then continues exactly as it does today. `loadDeclarations` |
| + reads the file once, and the snapshot serves the whole pass. |
| + |
| +To clear a box's declarations, the operator writes |
| +`{"schema":1,"units":[]}`. Deleting the parameter means "this box no |
| +longer takes declarations remotely" and leaves the file alone. Root |
| +cannot tell a deleted parameter from one that never existed, so it never |
| +acts on absence. |
| + |
| +This keeps Paul's serialisation ruling: the file changes only under the |
| +lock the delivery pass holds. |
| + |
| +### Validation (one gate for both readers) |
| + |
| +A value is installed only if both readers of the file accept it: |
| + |
| +- `appconfig.ValidateDeclarations` (the delivery decoder), and |
| +- the release path's decoder, shared with `proofnamed.go` rather than |
| + copied: unknown fields refused, schema 1, valid host, app and account, |
| + at most one entry per host, and |
| +- the release path's per-entry rules in their strictest form, applied to |
| + every entry: non-empty `addr`, a `health` with a path, and a unit not |
| + named `carlos-app@`. The release path applies these only to an entry |
| + whose host has no provisioning record in the bucket. The gate can't |
| + know that off the box, so it requires them always. A declaration |
| + therefore always names the unit's address and health path, even when |
| + it is only wanted for config. (My call, from the builder check: this |
| + is what keeps "both readers accept it" true.) |
| + |
| +Root also applies, at install time only, the one rule that depends on |
| +the box: on a box with the console guard, entries must be the console's. |
| + |
| +The builder extracts the release decoder and per-entry rules into one |
| +function that both `proofnamed.go` and the installer call. The local |
| +install verb gets the same gate, which closes the gap there as well. |
| + |
| +Size: refuse a value over 4 KB (the standard-tier limit), and refuse |
| +anything that isn't valid UTF-8 JSON as both decoders already do. |
| + |
| +### The operator's command |
| + |
| + carlos system named-units put --instance i-0abc... [--aws-region R] FILE |
| + carlos system named-units show --instance i-0abc... [--aws-region R] |
| + |
| +- `put` runs the same validation gate locally, then calls `PutParameter` |
| + with `Type=String` and `Overwrite=true` using the operator's AWS |
| + profile. Like `host-env seed` it runs off the box and needs no root. |
| +- `show` prints the stored value, or that there is none. |
| +- `put` prints the parameter path, the version AWS returns, and one line |
| + saying when the box will pick it up: "the box installs it on its next |
| + config pass (any config write to an app on that box starts one) or |
| + within the hour". |
| + |
| +The existing `carlos system named-units install FILE` stays for boxes |
| +without the feature and for provisioning. |
| + |
| +### Provider shape |
| + |
| +The core asks for one thing: "give me this box's declaration bytes, or |
| +say there are none, or say the read failed". That interface lives with |
| +the declarations code. The AWS adapter (IMDS identity plus SSM |
| +`GetParameter`) sits alongside `internal/hostenv/awsssm.go` and reuses |
| +its client setup. This follows the provider-neutral core rule. |
| + |
| +### Visibility (Paul, 2026-11-19: through the heartbeat) |
| + |
| +An operator must be able to see, from their own machine, whether the box |
| +took what they wrote and why not if it didn't. The journal alone would |
| +need a shell on the box, which is what this change removes. |
| + |
| +- **Root writes a status record** each time the step runs: |
| + `/var/lib/carlos/named-units-status.json`, root-owned, mode 0644, |
| + replaced atomically. It holds: |
| + - the parameter path and the version last read (or none), |
| + - the outcome: `installed`, `unchanged`, `not-found`, `unreadable`, |
| + `invalid`, `held` or `skipped`, with the reason, |
| + - the sha256 of the installed file, and when the step ran, |
| + - each declared unit's delivery state from the last `SyncUnits` pass: |
| + delivered, or refused with the rail's reason. `SyncUnits` adds this |
| + part after it runs, still under its lock. |
| +- **The agent adds it to the heartbeat** it already sends. It reads the |
| + file, size-capped, and includes it as one new snapshot field next to |
| + the box's other root-side facts. The field is optional, and an old |
| + console ignores it. No new bucket or parameter requests. |
| +- **`carlos system named-units show --instance <id>`** prints the stored |
| + parameter and, beside it, what the box last reported: version taken, |
| + outcome, and each unit's delivery state. It reads the heartbeat |
| + through the console API the operator CLI already uses for box status. |
| + If the box hasn't reported since the put, it says so with the |
| + heartbeat's age. |
| +- Each outcome is also logged in the journal, once per pass. |
| + |
| +The record only reports. Nothing reads it as authority, so a box that |
| +tampers with it can mislead the report but can't change what root does. |
| + |
| +## Security argument |
| + |
| +- **Who can write the parameter:** principals with `ssm:PutParameter` |
| + on the path. On every deployment in our infra, that is operator |
| + credentials only. No box role or console role has it. The rollout |
| + check (below) confirms this per deployment before the feature is used |
| + there. |
| +- **Who can choose which parameter root reads:** nobody on the box. The |
| + instance ID and region come from IMDS, read by root. |
| +- **What the agent can do:** read the parameter, which grants nothing, |
| + and trigger a config-only pass, which makes root fetch sooner but |
| + doesn't change what it fetches. |
| +- **What a bad value can do:** nothing beyond what a bad local install |
| + can do today. Both decoders gate it, and the delivery rails from #114 |
| + still apply to every entry. |
| +- **Instance-ID reuse:** AWS never reuses instance IDs, so a stale |
| + parameter can't land on a different box. |
| + |
| +## Testing |
| + |
| +- **Unit tests:** the source table above, as table tests over a fake |
| + source: not found, error, invalid for each decoder, equal bytes (no |
| + write, same inode), a new value (installed), and a cleared value. |
| +- **The validation gate:** a value with an extra field is refused even |
| + though appconfig accepts it. |
| +- **The lock:** the fetch-and-install runs under the pass's flock, and a |
| + concurrent `named-units install` queues behind it. Reuse the existing |
| + lock tests' shape. |
| +- **The CLI:** `put` refuses an invalid file before any AWS call, using |
| + a fake params client. |
| +- **Skips and holds:** group, fleet and non-EC2 boxes make no read; a |
| + recorded rollback for a declared host holds the install, and the next |
| + pass installs once it clears. |
| +- **Status record:** each outcome writes the record; the heartbeat field |
| + carries it; an oversized or unreadable record is left out of the |
| + heartbeat rather than failing it; `show` renders a box that hasn't |
| + reported since the put. |
| +- **Production wiring:** one test drives the real root-pass entry point |
| + with the source injected, so the step can't be wired only in tests. |
| +- **Cross-compile:** the adapter builds on darwin and windows (the CI |
| + cross-compile gate). IMDS code is not linux-only. |
| + |
| +## Rollout |
| + |
| +1. Merge and release. |
| +2. Per deployment that wants it: confirm that the fixed box role can |
| + `GetParameter` on `/carlos/host/named-units/*` (true for `/carlos/*` |
| + and `/carlos/host/*` scopes), and that no role on any box can write |
| + it. |
| +3. Per box: `named-units put`, then any config write to the app (or |
| + `carlos env sync`) to start a pass. `named-units show` then reports |
| + the version taken and each unit as delivered. |
| + |
| +The first box is the one #114 was filed for. Its relay sets its one |
| +start-up value inline with `Environment=`, so it needs a declaration |
| +only, no base file. After the put, setting the secret again through the |
| +door delivers it. |
| + |
| +## Left to the builder |
| + |
| +- The exact placement of the fetch step in `runAdopt`, before |
| + `SyncUnits` under its flock, and the split of `InstallNamedUnits`. |
| +- Which console API `show` reads the heartbeat field through, and the |
| + snapshot field's name and placement. |
| +- The copy for the log lines and the CLI output, which goes through copy |
| + review before merge. |