durability 3a: sealed platform items in hostfiles
Instance secrets must leave a box only sealed (durability spec §5.4).
hostfiles gains sealed platform items for Tasks 3 to 5 to use:
- Entry.Sealed ("v2": Object holds an appconfig v2 envelope) and
Entry.PlainMAC, both omitempty, so older manifests and their bytes are
unchanged. SHA256 and Size stay the envelope's, so checkEntry and fetch
verify the object as before.
- ItemSealer (NewItemSealer over the box's CARLOS_SECRETS_KEY, an
account/app binding and a host), MAC (HMAC-SHA256 under an HKDF key of
the private key, over length-prefixed account, app, host, item, then
the plaintext) and seal, the one funnel to appconfig.SealBound.
- Publisher.StageSealed, typed on pubclass.SealedRel and refusing a
verdict for another host; a no-op while the item's MAC matches. It
stages the plaintext marker CutoverItem ("sealed.cutover", {"v":1})
after the item whenever the manifest lacks it.
- ReadSealed: fetch as ReadPlatform does, refuse an unmarked entry or a
v1 envelope (which would open under any binding), open under the
sealer's key and binding, then check the MAC, so an envelope moved to
another host or item is refused.
- SealedAcknowledged: compare the MAC, no read.
- Publisher.DropRawSecrets: manifest only, drops EnvItem and tombstones
the named live entries; nothing read or deleted.
- SealedEnvItem ("env.sealed"); tests pin the three sealed item names to
pubclass.SealedRels and pin EnvItem to pubclass's raw env item
("host.env") through IsRawSecretItem.
The zero ItemSealer seals, opens and acknowledges nothing.
The sealing guard (TestOnlySealKeyForBuildsSealers) gains one row,
(*hostfiles.ItemSealer).seal -> SealBound; without it the guard fails
naming sealed.go's SealBound in ItemSealer.seal.
Census: new unit hostfiles/sealed.go:ReadSealed (its "Open" is
appconfig.Open, an in-memory decryption, not a file open); the hostfiles
envelope is re-pinned. Claims appended and census-propose re-run.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
docs/superpowers/notes/census-durability-3a-escrow-claims.md+1 −0docs/superpowers/notes/census-proposal-durability-3a-escrow.md+4 −3internal/console/sealkey_guard_test.go+4 −0internal/hostfiles/manifest.go+7 −0internal/hostfiles/sealed.go+248 −0internal/hostfiles/sealed_test.go+472 −0internal/provision/testdata/plan14-root-reads-chain.tsv+1 −1internal/provision/testdata/plan14-root-reads-durability-3a-escrow.tsv+5 −2
Intent
<task-notification> <task-id>a5c29ab4853bc6216</task-id> <tool-use-id>toolu_016JYwReXmPGTQz4E4eV57Ay</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/953e7524-2e06-4308-b9ce-fd1b38579971/tasks/a5c29ab4853bc6216.output</output-file> <status>completed</status> <summary>Agent "Implement Task 1: publish classifier" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>Status: DONE_WITH_CONCERNS Commit: d97e9687 durability 3a: one publish classifier and the file inventory (pubclass) Tests: all new pubclass, guard and Inventory tests pass. They failed first (RED) and passed after (GREEN). The brief's Step 4 run, the whole layout package, the offline-seal tests in `host` and the census tests pass. `PlanFor` paths and `NestedPlatformNames` are byte-identical before and after. gofmt is clean and the darwin and windows builds pass. Concerns: 1. A host whose own name looks like another host's platform file (say `a.example.com.db`) gets its whole files directory classed Never by rule 1, so nothing is published. I kept the rule as written. Changing it needs a ruling. 2. `Of` judges by name only and ignores `isDir`, so a directory named `instance.key` or `report.token` is now skipped, where HA's current skip would publish it. Unclean paths and unknown layouts are Never. A zero `ItemContext` refuses every name. All of these are stricter than the brief, never looser. 3. The pin that `hostfiles.EnvItem` equals "host.env" is left for Task 2, which owns hostfiles. 4. The census needs a reviewer's verdict on #280. It covers the new `Inventory`, the retired `NestedPlatformNames` and three re-pinned packages. The `nestedFiles` record-write re-pin is in `durability_3a_escrow_census_test.go`. 5. I did not advance the amadan task for Task 1. Report: /home/paulca/amadan.net/carlos/platform/.claude/worktrees/durability-3a/.superpowers/sdd/2026-10-30-durability-step3-escrow-fence-restore/task-1-report.md</result> <usage><subagent_tokens>154271</subagent_tokens><tool_uses>52</tool_uses><duration_ms>689126</duration_ms></usage> </task-notification>
<task-notification> <task-id>a63c64e2e21dd2b96</task-id> <tool-use-id>toolu_01Knjytb7sjHPLrJDpb1uYoB</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/953e7524-2e06-4308-b9ce-fd1b38579971/tasks/a63c64e2e21dd2b96.output</output-file> <status>completed</status> <summary>Agent "Review Task 1 (spec + quality)" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>### Spec Compliance - ✅ Spec compliant. Every file in the brief's list has its hunk. - **Created:** `pubclass/{names,pubclass,pubclass_test}.go`, `inventory.go`, `inventory_test.go`, `pubclass_guard_test.go`. - **Modified:** `extras.go`, `plan.go`, `activator/seedplace.go:93`. - **Interface:** every exported name and signature in the brief's interface block is present (`pubclass.go:947–1204`, `inventory.go:325`). - **`Of`:** the eight rules run in the brief's order (`pubclass.go:1056–1094`), with rule 5 before the nested App fallback. - **Imports:** `pubclass` imports only `controlname`, `instancectl`, `instancekey` and the standard library (`names.go:779–786`). - **Wrappers:** `layout.NestedPlatformNames` and `layout.IsNestedPlatformName` are one-line wrappers (`plan.go:737,760`). - **Byte-identity:** - `flatFiles` and `nestedFiles` now build through `artifactPaths` from `FileBases` (`plan.go:650–688`). - I checked the changed `flatFiles` path against `provision.DefaultDBPath` (`provision.go:3148`, `filepath.Join(dataDir, host+".db")`). They are equal. - The nested paths are identical. - The `FileBases` names match the deleted literals one for one. - **Flat inventory:** `hostEntries` covers `belongsTo`'s `.activator-<host>.` prefixes (`extras.go:58`), so shadow directories reach the flat inventory. - ⚠️ Cannot verify from the diff: - The census digests and the re-pinned envelope hashes (`plan14-root-reads-durability-3a-escrow.tsv`, the `nestedFiles` pin in `durability_3a_escrow_census_test.go:1522`). They need the independent reviewer's verdict on #280. This is the report's concern 4, and I agree. - The `hostfiles.EnvItem == "host.env"` pin comes from the interface comment (`pubclass.go:1003–1004`). It is not in Task 1's file list and the report defers it to Task 2. The controller should make sure Task 2 writes it. Until it exists, `rawEnvItem` can drift from `hostfiles.EnvItem` with nothing to catch it. - Extra, all necessary or fail-closed: - **Census files:** the AGENTS.md census gate requires them. - **`Layout.String()`:** an addition to the interface. - **Unclean-path guard:** `Of` returns Never for an unclean `rel` or an unknown layout (`pubclass.go:1049`). Without it `h/../h.env` would read as App. - **Cleaned names:** `IsRawSecretItem` cleans names before judging them. - **Fail-closed default:** a zero `ItemContext` returns true. ### Strengths - The classifier is a pure function of the name, with no extension sniffing, and the table test is the brief's table verbatim. Unclean-path and directory-at-reserved-name cases are tested separately (`pubclass_test.go:1256–1281`). - `SealedRel` has unexported fields, so the only way to make one is a classifier verdict. `TestSealedRelsAreTheTrioInBothLayouts` round-trips it. - The guard test is stronger than the brief's. It also checks that `FileBases` keys are exactly `artifactNames` minus the socket (`pubclass_guard_test.go:1471–1479`), which `artifactPaths` depends on. That catches a new artifact with no base name. - The names moved out of `layout` break the `activator` to `layout` import tangle, and `plan.go` no longer imports `activator`, `instancectl` or `instancekey`. - The `FixedShapeHost` test moved to `pubclass_test.go` with its body unchanged, so it now runs on every OS. - `Inventory` validates the host and layout before it lists anything. A missing directory is empty, and the result is sorted. - Before-and-after byte-identity and mutation checks are reported. ### Issues #### Critical (Must Fix) None. #### Important (Should Fix) None. #### Minor (Nice to Have) 1. `pubclass.go:1075` and `names.go:869`: in the Nested layout `Of` calls `IsNestedPlatformName`, which rebuilds `NestedPlatformNames` (two maps, `FileBases` plus about 12 entries) on every call. - `FilesDirSkip` calls `Of` once per walked path, and `Of` also runs `FixedShapeHost` (`ValidHostShape`) each time. A large files directory therefore allocates per file. - It is correct, but the cost is avoidable. Hoist the set into `FilesDirSkip`'s closure, or short-circuit when `first == host` before rules 1 to 5. That is safe for the files-directory use, where `first` is always the host. 2. `inventory_test.go:396–412`: the flat test does not cover a shadow directory (`.activator-<h>.db-litestream`), `<h>.db-wal`, or a name owned by a longer host through the `.activator-` prefix. Add one or two entries so `Replicated` in Flat is pinned through `Inventory`. 3. `pubclass.go:1049`: `Of` ignores `isDir`, which makes the parameter dead. The doc comment says so, so the behaviour is intentional. - It now skips a directory named `instance.key` or `report.token` at the files root, where HA's `snapshotSkip` publishes it (report concern 2). - It is stricter and safe. Task 3 should note it when `snapshotSkip` becomes a classifier call. 4. Report concern 1 (rule 1 on a host whose own name has another host's fixed shape) is fail-closed and follows the brief's text. I judge it theoretical, since no served host name ends in `.db` or `.env`. It needs no ruling now. ### Assessment **Task quality:** Approved **Reasoning:** The classifier follows the brief's eight rules in order, fails closed on unclean input, and is tested against the full table plus the guard test. The `layout` refactor changes none of the plan's artifact paths. The only gaps are the Task 2 `EnvItem` pin and the #280 census verdict, and neither blocks this task.</result> <usage><subagent_tokens>96098</subagent_tokens><tool_uses>8</tool_uses><duration_ms>69973</duration_ms></usage> </task-notification>
Attributed to this commit: 28.2 g CO₂e (3,627,885 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on durability-3a-escrow, 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/notes/census-durability-3a-escrow-claims.md b/docs/superpowers/notes/census-durability-3a-escrow-claims.md| index beebf7f51..6c329079a 100644 |
| --- a/docs/superpowers/notes/census-durability-3a-escrow-claims.md |
| +++ b/docs/superpowers/notes/census-durability-3a-escrow-claims.md |
| @@ -4,3 +4,4 @@ |
| internal/layout/inventory.go:Inventory durability 3a Task 1: new. One os.ReadDir of the host's inventory root, provision.InstanceDir(dataDir, host) nested or dataDir flat, after refusing a host that fails controlname.ValidHostShape and a layout that is neither flat nor nested; reads only the listing's names and types (DirEntry.IsDir), opens and follows nothing; flat ownership is the extras scan's own (hostEntries over knownHosts); each top-level name is classified by pubclass.Of, a pure function of the name. A missing directory is an empty inventory. No caller in this task; later tasks call it from the publisher. |
| internal/layout/plan.go:NestedPlatformNames durability 3a Task 1: now a one-line wrapper for pubclass.NestedPlatformNames, which builds the same set (byte-identical, checked before and after) from pubclass.FileBases and the same instancectl/instancekey names, without nestedFiles or rawInstanceDir; it never read anything, and reads nothing now |
| +internal/hostfiles/sealed.go:ReadSealed durability 3a Task 2: new. Reads one sealed platform item of a files manifest the caller already loaded: the object at exactly the key the entry names, through the existing fetch (checkEntry: origin admitted, key shape, sha256 and size verified), only for an entry marked sealed "v2". The "Open" the scanner sees is appconfig.Open, an in-memory AES-GCM decryption of the fetched bytes, not a file open: no filesystem path is opened, read or followed. It refuses a v1 envelope (appconfig.EnvelopeBound), and after opening under the caller-supplied key and (account, app) binding it checks the HMAC digest over account, app, host and item against the entry. Writes nothing. No production caller in this task; Tasks 3 and 4 call it from the activator. |
diff --git a/docs/superpowers/notes/census-proposal-durability-3a-escrow.md b/docs/superpowers/notes/census-proposal-durability-3a-escrow.md| index 439d18249..8eb0ab6ea 100644 |
| --- a/docs/superpowers/notes/census-proposal-durability-3a-escrow.md |
| +++ b/docs/superpowers/notes/census-proposal-durability-3a-escrow.md |
| @@ -1,16 +1,17 @@ |
| # Census approval: durability-3a-escrow |
| -Ruling `census-ruling-durability-3a-escrow`. The independent reviewer approves or rejects every change below, 2 with a new disposition; nothing goes to the census owner (Paul, #280, 2026-10-26). |
| +Ruling `census-ruling-durability-3a-escrow`. The independent reviewer approves or rejects every change below, 3 with a new disposition; nothing goes to the census owner (Paul, #280, 2026-10-26). |
| -Envelopes re-pinned: `internal/activator`, `internal/layout`, `internal/layout/pubclass`. |
| +Envelopes re-pinned: `internal/activator`, `internal/hostfiles`, `internal/layout`, `internal/layout/pubclass`. |
| Review: a model from the other family than the author reads the branch's diff against main on the amadan.net remote (`origin` or `amadan`, whichever points at amadan.net) and gives a verdict for every unit and every re-pinned envelope above. For a unit, compare the change with its recorded disposition and basis below; for an envelope, read every changed function in the package and what it reaches. Reject if the change lets root open, run, query or follow anything it did not before from a path or input a tenant, an app or a box agent can create, write or name; if it weakens a check, refusal, validation, argument or environment the basis relies on; or if the diff cannot settle either. Otherwise approve. Record each verdict on #280 with the tip. A rejected unit goes back to the author to correct; nothing escalates to the census owner. |
| New dispositions, which census-propose wrote and the reviewer checks against the unit's reads and the diff: |
| +- new `internal/hostfiles/sealed.go:ReadSealed`: reads +file:Open; written legacy, accepted-legacy, frozen |
| - new `internal/layout/inventory.go:Inventory`: reads +file:ReadDir; written legacy, accepted-legacy, frozen |
| - quiet `internal/layout/plan.go:NestedPlatformNames`: reads nothing now; retired while it reads nothing (or its row keeps no sites) |
| -Seal: `eaeb153ab7a7a849edc9c6e92f2ac5c709c6e39044a647971cf1fa5ebcb660c8` → `d1cf6e6d51e2b3451a4f3343b6d1ab66374c4dcde6c6f9bb21b52ccb1cf98350`. |
| +Seal: `eaeb153ab7a7a849edc9c6e92f2ac5c709c6e39044a647971cf1fa5ebcb660c8` → `0da3b2b5686a83332323f61821f53b7f3070135f4ca54005946c4c4b1ee70f09`. |
| Overlay: `internal/provision/testdata/plan14-root-reads-durability-3a-escrow.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`. |
diff --git a/internal/console/sealkey_guard_test.go b/internal/console/sealkey_guard_test.go| index 66ab63ce1..71f64d91a 100644 |
| --- a/internal/console/sealkey_guard_test.go |
| +++ b/internal/console/sealkey_guard_test.go |
| @@ -111,6 +111,10 @@ var sealGuardAllowed = map[string][]string{ |
| sgArchiveSeal: {sgSealBound}, |
| "(*" + sgHost + ".movesWorker).buildArchive": {sgArchiveSeal}, |
| "(*" + sgHost + ".movesWorker).offlineArchive": {sgArchiveSeal}, |
| + // An instance's escrowed secrets, sealed on the box to the box's own |
| + // CARLOS_SECRETS_KEY: the deployment key on a platform box, the fleet's |
| + // on a fleet box (durability §5.4, plan 3a choice 2). |
| + "(*" + sgModule + "/internal/hostfiles.ItemSealer).seal": {sgSealBound}, |
| } |
| // sgFinding is one use the allowlist does not admit. |
diff --git a/internal/hostfiles/manifest.go b/internal/hostfiles/manifest.go| index 51ec0843c..8a4046362 100644 |
| --- a/internal/hostfiles/manifest.go |
| +++ b/internal/hostfiles/manifest.go |
| @@ -39,6 +39,13 @@ type Entry struct { |
| Deleted bool `json:"deleted,omitempty"` |
| Torn bool `json:"torn,omitempty"` |
| Skipped string `json:"skipped,omitempty"` |
| + // Sealed is "v2" for a sealed platform item (sealed.go): Object holds |
| + // an appconfig v2 envelope of the item, and SHA256 and Size are the |
| + // envelope's, so checkEntry and fetch verify it as any other object. |
| + // PlainMAC is ItemSealer.MAC of the plaintext. Both are additive: an |
| + // entry without them is as before. |
| + Sealed string `json:"sealed,omitempty"` |
| + PlainMAC string `json:"plain_mac,omitempty"` |
| } |
| // ManifestVersion is the manifest format this binary reads and writes. |
diff --git a/internal/hostfiles/sealed.go b/internal/hostfiles/sealed.go| new file mode 100644 |
| index 000000000..de38aaa6c |
| --- /dev/null |
| +++ b/internal/hostfiles/sealed.go |
| @@ -0,0 +1,248 @@ |
| +package hostfiles |
| + |
| +import ( |
| + "context" |
| + "crypto/ecdh" |
| + "crypto/hkdf" |
| + "crypto/hmac" |
| + "crypto/sha256" |
| + "encoding/binary" |
| + "encoding/hex" |
| + "errors" |
| + "fmt" |
| + "os" |
| + |
| + "github.com/carlosframework/platform/internal/appconfig" |
| + "github.com/carlosframework/platform/internal/controlname" |
| + "github.com/carlosframework/platform/internal/layout/pubclass" |
| + "github.com/carlosframework/platform/internal/release" |
| +) |
| + |
| +// Sealed platform items (durability spec §5.4, plan 3a choices 2 to 4). |
| +// An instance's secrets (<host>.env, instance.key, report.token) never go |
| +// to the bucket as plain bytes: each goes as a platform item whose object |
| +// is an appconfig v2 envelope, bound to the instance's account and app and |
| +// sealed to the box's own CARLOS_SECRETS_KEY, with a keyed digest of the |
| +// plaintext beside it in the manifest. |
| + |
| +// SealedEnvItem is the sealed env file among the manifest's platform |
| +// items. The trio's are "instance.key.sealed" and "report.token.sealed". |
| +// pubclass's item names are these three; a test pins them equal. |
| +const SealedEnvItem = "env.sealed" |
| + |
| +// CutoverItem is the platform item "sealed.cutover" (plaintext, non-secret: |
| +// {"v":1}). StageSealed stages it when absent, so the first sealed commit |
| +// carries it, and no code of 3a's release deletes it. An older publisher |
| +// keeps it: Commit writes back every Platform item it decoded and stages a |
| +// delete only for the EnvItem. |
| +const CutoverItem = "sealed.cutover" |
| + |
| +// sealedV2 is Entry.Sealed for an item whose object is an appconfig v2 |
| +// envelope. |
| +const sealedV2 = "v2" |
| + |
| +// macInfo is the HKDF info of the digest key: apart from every other use |
| +// of the sealing key. |
| +const macInfo = "carlos/hostfiles/sealed-mac/v1" |
| + |
| +var cutoverBody = []byte(`{"v":1}`) |
| + |
| +// ItemSealer seals and opens one host's sealed items. Named apart from |
| +// appconfig.Sealer, which the module's sealing guard reserves for sealKeyFor. |
| +// |
| +// Its key is the box's own CARLOS_SECRETS_KEY: the deployment key on a |
| +// platform box, the fleet's on a fleet box, exactly what sealKeyFor picks |
| +// for every app the box can render (plan 3a choice 2). So every holder of |
| +// the key may already hold the secret (§5.4). |
| +type ItemSealer struct { |
| + pub *ecdh.PublicKey |
| + priv *ecdh.PrivateKey |
| + binding appconfig.Binding |
| + host string |
| + macKey []byte |
| +} |
| + |
| +// NewItemSealer is a sealer for host's items, bound to b, under priv. |
| +func NewItemSealer(priv *ecdh.PrivateKey, b appconfig.Binding, host string) (*ItemSealer, error) { |
| + if priv == nil { |
| + return nil, errors.New("hostfiles: item sealer: no key") |
| + } |
| + if !release.ValidAccount(b.Account) || !release.ValidApp(b.App) { |
| + return nil, fmt.Errorf("hostfiles: item sealer: invalid account/app %q/%q", b.Account, b.App) |
| + } |
| + if !controlname.ValidHostShape(host) { |
| + return nil, fmt.Errorf("hostfiles: item sealer: invalid host %q", host) |
| + } |
| + key, err := hkdf.Key(sha256.New, priv.Bytes(), nil, macInfo, sha256.Size) |
| + if err != nil { |
| + return nil, fmt.Errorf("hostfiles: item sealer: %w", err) |
| + } |
| + return &ItemSealer{pub: priv.PublicKey(), priv: priv, binding: b, host: host, macKey: key}, nil |
| +} |
| + |
| +// usable reports whether s came from NewItemSealer: the zero ItemSealer |
| +// holds no key, seals nothing and acknowledges nothing. |
| +func (s *ItemSealer) usable() bool { return s != nil && s.priv != nil } |
| + |
| +// MAC is hex HMAC-SHA256 under HKDF(priv bytes, info |
| +// "carlos/hostfiles/sealed-mac/v1") over length-prefixed account, app, |
| +// host and item, then plain. Only holders of the key can compute it: the |
| +// same set that can open the envelope. Randomized sealing makes the |
| +// envelope's own hash useless for "unchanged"; this is what tells it. |
| +func (s *ItemSealer) MAC(item string, plain []byte) string { |
| + h := hmac.New(sha256.New, s.macKey) |
| + for _, f := range []string{s.binding.Account, s.binding.App, s.host, item} { |
| + h.Write(binary.BigEndian.AppendUint32(nil, uint32(len(f)))) |
| + h.Write([]byte(f)) |
| + } |
| + h.Write(plain) |
| + return hex.EncodeToString(h.Sum(nil)) |
| +} |
| + |
| +// seal is the escrow's one sealing funnel: the only caller of |
| +// appconfig.SealBound outside appconfig and the CLI (sealkey_guard_test.go row). |
| +func (s *ItemSealer) seal(plain []byte) ([]byte, error) { |
| + env, err := appconfig.SealBound(s.pub, s.binding, plain) |
| + if err != nil { |
| + return nil, err |
| + } |
| + return []byte(env), nil |
| +} |
| + |
| +// sealedMatches reports whether e is a sealed item whose plaintext digest |
| +// is mac. |
| +func sealedMatches(e Entry, mac string) bool { |
| + return !e.Deleted && e.Skipped == "" && e.Sealed == sealedV2 && |
| + hmac.Equal([]byte(e.PlainMAC), []byte(mac)) |
| +} |
| + |
| +// StageSealed seals plain and stages it as r.Item(); a no-op when the |
| +// item's PlainMAC already matches. It also stages CutoverItem when the |
| +// manifest lacks it (Task 5). Only a classifier verdict can be passed. |
| +// |
| +// r must be one of s's host's own sealed paths: a verdict for another host |
| +// is refused. The cutover marker is staged after the item, so a manifest |
| +// gains it only beside a sealed item, and it is staged whenever it is |
| +// missing, the item unchanged or not. |
| +func (p *Publisher) StageSealed(ctx context.Context, r pubclass.SealedRel, plain []byte, s *ItemSealer) error { |
| + if !s.usable() { |
| + return errors.New("hostfiles: stage sealed: no sealer") |
| + } |
| + if want, ok := pubclass.SealedPath(pubclass.Nested, s.host, r.Rel()); !ok || want != r { |
| + return fmt.Errorf("hostfiles: stage sealed: %q is not a sealed path of %s", r.Rel(), s.host) |
| + } |
| + item := r.Item() |
| + mac := s.MAC(item, plain) |
| + p.mu.Lock() |
| + defer p.mu.Unlock() |
| + if cur, ok := p.man.Platform[item]; !ok || !sealedMatches(cur, mac) { |
| + env, err := s.seal(plain) |
| + if err != nil { |
| + return fmt.Errorf("hostfiles: seal %s: %w", item, err) |
| + } |
| + if len(env) > MaxFileBytes { |
| + return fmt.Errorf("hostfiles: seal %s: the envelope is %d bytes, over the %d-byte limit", item, len(env), MaxFileBytes) |
| + } |
| + e, err := p.put(ctx, env, 0o600, false) |
| + if err != nil { |
| + return err |
| + } |
| + e.Sealed, e.PlainMAC = sealedV2, mac |
| + p.man.Platform[item], p.dirty = e, true |
| + } |
| + if _, ok := p.man.Platform[CutoverItem]; !ok { |
| + e, err := p.put(ctx, cutoverBody, 0o600, false) |
| + if err != nil { |
| + return err |
| + } |
| + p.man.Platform[CutoverItem], p.dirty = e, true |
| + } |
| + return nil |
| +} |
| + |
| +// ReadSealed returns a sealed item's plaintext: the object fetched and |
| +// verified as ReadPlatform does, opened as a v2 envelope under s's key and |
| +// binding, and its digest checked against the entry's PlainMAC, which |
| +// names the host and the item. A name the manifest does not hold is |
| +// os.ErrNotExist; an entry not marked sealed, a v1 envelope (it would open |
| +// under any binding), another key, binding, host or item is refused. |
| +// prefix and origins are as for ReadPlatform. |
| +func ReadSealed(ctx context.Context, st release.Store, prefix string, m Manifest, item string, origins []string, s *ItemSealer) ([]byte, error) { |
| + if !s.usable() { |
| + return nil, errors.New("hostfiles: read sealed: no sealer") |
| + } |
| + if err := checkPrefix(prefix); err != nil { |
| + return nil, err |
| + } |
| + origins, err := admitted(prefix, origins) |
| + if err != nil { |
| + return nil, err |
| + } |
| + e, ok := m.Platform[item] |
| + if !ok { |
| + return nil, fmt.Errorf("hostfiles: sealed item %q: %w", item, os.ErrNotExist) |
| + } |
| + if e.Sealed != sealedV2 { |
| + return nil, fmt.Errorf("hostfiles: platform item %q is not sealed (sealed %q)", item, e.Sealed) |
| + } |
| + body, err := fetch(ctx, st, e, origins) |
| + if err != nil { |
| + return nil, fmt.Errorf("hostfiles: sealed item %q: %w", item, err) |
| + } |
| + if !appconfig.EnvelopeBound(string(body)) { |
| + return nil, fmt.Errorf("hostfiles: sealed item %q is not a v2 envelope", item) |
| + } |
| + plain, err := appconfig.Open(s.priv, s.binding, string(body)) |
| + if err != nil { |
| + return nil, fmt.Errorf("hostfiles: sealed item %q: %w", item, err) |
| + } |
| + if !hmac.Equal([]byte(s.MAC(item, plain)), []byte(e.PlainMAC)) { |
| + return nil, fmt.Errorf("hostfiles: sealed item %q: its digest is not this host's and item's", item) |
| + } |
| + return plain, nil |
| +} |
| + |
| +// SealedAcknowledged: m holds item, live, sealed, with PlainMAC == s.MAC(item, plain). No read. |
| +func SealedAcknowledged(m Manifest, item string, plain []byte, s *ItemSealer) bool { |
| + if !s.usable() { |
| + return false |
| + } |
| + e, ok := m.Platform[item] |
| + return ok && sealedMatches(e, s.MAC(item, plain)) |
| +} |
| + |
| +// DropRawSecrets stages, in the manifest only, the end of raw secret |
| +// items an older publisher wrote: the EnvItem platform item is dropped and |
| +// each named live Entry is tombstoned. No object is read or deleted. |
| +// |
| +// Every path is checked before anything changes. A path the manifest does |
| +// not hold, or holds as a tombstone already, is left as it is, so a drop |
| +// with nothing to drop stages nothing. |
| +func (p *Publisher) DropRawSecrets(paths []string) error { |
| + clean := make([]string, 0, len(paths)) |
| + for _, path := range paths { |
| + c, err := CleanPath(path) |
| + if err != nil { |
| + return err |
| + } |
| + if err := withinTreeCap(c); err != nil { |
| + return err |
| + } |
| + clean = append(clean, c) |
| + } |
| + p.mu.Lock() |
| + defer p.mu.Unlock() |
| + if _, ok := p.man.Platform[EnvItem]; ok { |
| + p.next++ |
| + delete(p.man.Platform, EnvItem) |
| + p.dirty = true |
| + } |
| + for _, c := range clean { |
| + if cur, ok := p.man.Entries[c]; !ok || cur.Deleted { |
| + continue |
| + } |
| + p.next++ |
| + p.man.Entries[c], p.dirty = Entry{Seq: p.next, Deleted: true}, true |
| + } |
| + return nil |
| +} |
diff --git a/internal/hostfiles/sealed_test.go b/internal/hostfiles/sealed_test.go| new file mode 100644 |
| index 000000000..acf154b6f |
| --- /dev/null |
| +++ b/internal/hostfiles/sealed_test.go |
| @@ -0,0 +1,472 @@ |
| +package hostfiles |
| + |
| +import ( |
| + "bytes" |
| + "context" |
| + "crypto/ecdh" |
| + "encoding/json" |
| + "errors" |
| + "os" |
| + "slices" |
| + "strings" |
| + "testing" |
| + |
| + "github.com/carlosframework/platform/internal/appconfig" |
| + "github.com/carlosframework/platform/internal/layout/pubclass" |
| + "github.com/carlosframework/platform/internal/release" |
| +) |
| + |
| +const sealHost = "shop.test" |
| + |
| +var shopBinding = appconfig.Binding{Account: "bab", App: "shop"} |
| + |
| +// countingStore counts every request, as countingGets does for reads. |
| +type countingStore struct { |
| + release.Store |
| + gets, puts, deletes int |
| +} |
| + |
| +func (c *countingStore) Get(ctx context.Context, key string) ([]byte, string, error) { |
| + c.gets++ |
| + return c.Store.Get(ctx, key) |
| +} |
| + |
| +func (c *countingStore) Put(ctx context.Context, key string, body []byte, ifMatch string) (string, error) { |
| + c.puts++ |
| + return c.Store.Put(ctx, key, body, ifMatch) |
| +} |
| + |
| +func (c *countingStore) Delete(ctx context.Context, key string) error { |
| + c.deletes++ |
| + return c.Store.Delete(ctx, key) |
| +} |
| + |
| +func (c *countingStore) reset() { c.gets, c.puts, c.deletes = 0, 0, 0 } |
| + |
| +func newKey(t *testing.T) *ecdh.PrivateKey { |
| + t.Helper() |
| + privB64, _, err := appconfig.GenerateKey() |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + priv, err := appconfig.ParsePrivateKey(privB64, "test") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + return priv |
| +} |
| + |
| +func newSealer(t *testing.T, priv *ecdh.PrivateKey, b appconfig.Binding, host string) *ItemSealer { |
| + t.Helper() |
| + s, err := NewItemSealer(priv, b, host) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + return s |
| +} |
| + |
| +// sealedRel is the classifier's verdict for rel under sealHost. |
| +func sealedRel(t *testing.T, rel string) pubclass.SealedRel { |
| + t.Helper() |
| + r, ok := pubclass.SealedPath(pubclass.Nested, sealHost, rel) |
| + if !ok { |
| + t.Fatalf("%s is not a sealed path", rel) |
| + } |
| + return r |
| +} |
| + |
| +func envRel(t *testing.T) pubclass.SealedRel { return sealedRel(t, sealHost+".env") } |
| + |
| +func stageSealed(t *testing.T, p *Publisher, r pubclass.SealedRel, plain string, s *ItemSealer) { |
| + t.Helper() |
| + if err := p.StageSealed(context.Background(), r, []byte(plain), s); err != nil { |
| + t.Fatal(err) |
| + } |
| +} |
| + |
| +func loadM(t *testing.T, st release.Store) Manifest { |
| + t.Helper() |
| + m, found, err := Load(context.Background(), st, pfx) |
| + if err != nil || !found { |
| + t.Fatalf("load: %v (found %v)", err, found) |
| + } |
| + return m |
| +} |
| + |
| +// A sealed item reads back as its plaintext, and no object under the |
| +// prefix (the manifest included) holds the secret: the object is a v2 |
| +// envelope, marked so in the manifest, beside the cutover marker. |
| +func TestStageSealedRoundTripsAndNeverStoresPlaintext(t *testing.T) { |
| + ctx := context.Background() |
| + st := release.NewDirStore(t.TempDir()) |
| + s := newSealer(t, newKey(t), shopBinding, sealHost) |
| + p := open(t, st) |
| + const plain = "CARLOS_ADMIN_TOKEN=tok-5f2e9c\n" |
| + stageSealed(t, p, envRel(t), plain, s) |
| + commit(t, p) |
| + |
| + m := loadM(t, st) |
| + got, err := ReadSealed(ctx, st, pfx, m, SealedEnvItem, nil, s) |
| + if err != nil || string(got) != plain { |
| + t.Fatalf("ReadSealed = %q, %v; want %q", got, err, plain) |
| + } |
| + e := m.Platform[SealedEnvItem] |
| + if e.Sealed != "v2" || e.PlainMAC != s.MAC(SealedEnvItem, []byte(plain)) { |
| + t.Fatalf("entry %+v: want Sealed v2 and the plaintext's MAC", e) |
| + } |
| + keys, err := st.List(ctx, pfx) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if len(keys) < 3 { // the manifest, the envelope, the cutover marker |
| + t.Fatalf("listed %v", keys) |
| + } |
| + for _, k := range keys { |
| + body, _, err := st.Get(ctx, k) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if bytes.Contains(body, []byte("tok-5f2e9c")) { |
| + t.Fatalf("%s holds the plaintext secret", k) |
| + } |
| + } |
| + env, _, err := st.Get(ctx, e.Object) |
| + if err != nil || !appconfig.EnvelopeBound(string(env)) { |
| + t.Fatalf("the sealed object is not a v2 envelope: %v", err) |
| + } |
| + cut, err := ReadPlatform(ctx, st, pfx, m, CutoverItem, nil) |
| + if err != nil || string(cut) != `{"v":1}` { |
| + t.Fatalf("cutover marker %q, %v", cut, err) |
| + } |
| + if m.Platform[CutoverItem].Sealed != "" { |
| + t.Fatalf("the cutover marker is plaintext, not sealed: %+v", m.Platform[CutoverItem]) |
| + } |
| + |
| + // The trio go the same way, under their own names. |
| + stageSealed(t, p, sealedRel(t, sealHost+"/instance.key"), "key-bytes", s) |
| + commit(t, p) |
| + m = loadM(t, st) |
| + if got, err := ReadSealed(ctx, st, pfx, m, "instance.key.sealed", nil, s); err != nil || string(got) != "key-bytes" { |
| + t.Fatalf("instance.key.sealed = %q, %v", got, err) |
| + } |
| +} |
| + |
| +// Sealing is randomized, so only the keyed digest can tell an unchanged |
| +// item: the same plaintext again takes no sequence number and writes |
| +// nothing. Other bytes, or another key, seal afresh. |
| +func TestStageSealedUnchangedWritesNothing(t *testing.T) { |
| + ctx := context.Background() |
| + st := &countingStore{Store: release.NewDirStore(t.TempDir())} |
| + s := newSealer(t, newKey(t), shopBinding, sealHost) |
| + p := open(t, st) |
| + stageSealed(t, p, envRel(t), "A=1\n", s) |
| + commit(t, p) |
| + seq := p.pending() |
| + |
| + st.reset() |
| + stageSealed(t, p, envRel(t), "A=1\n", s) |
| + if st.puts != 0 || st.gets != 0 || p.Dirty() || p.pending() != seq { |
| + t.Fatalf("an unchanged item: %d puts, %d gets, dirty %v, seq %d -> %d", st.puts, st.gets, p.Dirty(), seq, p.pending()) |
| + } |
| + if _, err := p.Commit(ctx); err != nil || st.puts != 0 { |
| + t.Fatalf("commit of nothing: %v, %d puts", err, st.puts) |
| + } |
| + |
| + stageSealed(t, p, envRel(t), "A=2\n", s) |
| + if st.puts != 1 || !p.Dirty() { |
| + t.Fatalf("a changed item: %d puts, dirty %v", st.puts, p.Dirty()) |
| + } |
| + commit(t, p) |
| + |
| + // A box whose key changed reseals, though the plaintext did not. |
| + st.reset() |
| + other := newSealer(t, newKey(t), shopBinding, sealHost) |
| + stageSealed(t, p, envRel(t), "A=2\n", other) |
| + commit(t, p) |
| + if got, err := ReadSealed(ctx, st, pfx, loadM(t, st), SealedEnvItem, nil, other); err != nil || string(got) != "A=2\n" { |
| + t.Fatalf("after a key change: %q, %v", got, err) |
| + } |
| +} |
| + |
| +// An envelope opens only for the binding, the key, the host and the item |
| +// it was sealed for; a v1 envelope or an unmarked entry is refused. |
| +func TestReadSealedRefusesAnotherAppAndAnotherKey(t *testing.T) { |
| + ctx := context.Background() |
| + st := release.NewDirStore(t.TempDir()) |
| + priv := newKey(t) |
| + s := newSealer(t, priv, shopBinding, sealHost) |
| + p := open(t, st) |
| + stageSealed(t, p, envRel(t), "SECRET=1\n", s) |
| + if err := p.StagePlatform(ctx, EnvItem, []byte("SECRET=1\n")); err != nil { |
| + t.Fatal(err) |
| + } |
| + commit(t, p) |
| + m := loadM(t, st) |
| + |
| + for name, other := range map[string]*ItemSealer{ |
| + "another app": newSealer(t, priv, appconfig.Binding{Account: "bab", App: "other"}, sealHost), |
| + "another account": newSealer(t, priv, appconfig.Binding{Account: "cab", App: "shop"}, sealHost), |
| + "another key": newSealer(t, newKey(t), shopBinding, sealHost), |
| + "another host": newSealer(t, priv, shopBinding, "other.test"), |
| + } { |
| + if got, err := ReadSealed(ctx, st, pfx, m, SealedEnvItem, nil, other); err == nil { |
| + t.Errorf("%s opened the escrow: %q", name, got) |
| + } |
| + } |
| + |
| + // The env's envelope moved under the instance key's name opens under |
| + // the key, but its MAC names another item. |
| + moved := m |
| + moved.Platform = map[string]Entry{"instance.key.sealed": m.Platform[SealedEnvItem]} |
| + if _, err := ReadSealed(ctx, st, pfx, moved, "instance.key.sealed", nil, s); err == nil { |
| + t.Error("an envelope under another item's name was accepted") |
| + } |
| + |
| + // A raw item is not a sealed one, whatever its name. |
| + if _, err := ReadSealed(ctx, st, pfx, m, EnvItem, nil, s); err == nil { |
| + t.Error("ReadSealed read the raw env item") |
| + } |
| + if _, err := ReadSealed(ctx, st, pfx, m, "report.token.sealed", nil, s); !errors.Is(err, os.ErrNotExist) { |
| + t.Errorf("a missing item: %v, want os.ErrNotExist", err) |
| + } |
| + |
| + // A v1 envelope opens under any binding, so it is refused even when the |
| + // manifest marks it v2 and carries the right MAC. |
| + pub := priv.PublicKey() |
| + v1, err := appconfig.SealUnbound(pub, []byte("SECRET=1\n")) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := p.StagePlatform(ctx, "v1.sealed", []byte(v1)); err != nil { |
| + t.Fatal(err) |
| + } |
| + commit(t, p) |
| + m = loadM(t, st) |
| + e := m.Platform["v1.sealed"] |
| + e.Sealed, e.PlainMAC = "v2", s.MAC(SealedEnvItem, []byte("SECRET=1\n")) |
| + m.Platform[SealedEnvItem] = e |
| + if _, err := ReadSealed(ctx, st, pfx, m, SealedEnvItem, nil, s); err == nil { |
| + t.Error("a v1 envelope was accepted as a sealed item") |
| + } |
| + if _, err := ReadSealed(ctx, st, pfx, m, SealedEnvItem, nil, nil); err == nil { |
| + t.Error("ReadSealed with no sealer answered") |
| + } |
| + if _, err := ReadSealed(ctx, st, pfx, m, SealedEnvItem, nil, &ItemSealer{}); err == nil { |
| + t.Error("ReadSealed with the zero sealer answered") |
| + } |
| +} |
| + |
| +// An acknowledgement compares the keyed digest, with no read. |
| +func TestSealedAcknowledgedComparesTheMAC(t *testing.T) { |
| + ctx := context.Background() |
| + st := &countingStore{Store: release.NewDirStore(t.TempDir())} |
| + s := newSealer(t, newKey(t), shopBinding, sealHost) |
| + p := open(t, st) |
| + stageSealed(t, p, envRel(t), "A=1\n", s) |
| + if err := p.StagePlatform(ctx, EnvItem, []byte("A=1\n")); err != nil { |
| + t.Fatal(err) |
| + } |
| + commit(t, p) |
| + m := loadM(t, st) |
| + st.reset() |
| + if !SealedAcknowledged(m, SealedEnvItem, []byte("A=1\n"), s) { |
| + t.Error("the staged plaintext is not acknowledged") |
| + } |
| + if SealedAcknowledged(m, SealedEnvItem, []byte("A=2\n"), s) { |
| + t.Error("other bytes are acknowledged") |
| + } |
| + if SealedAcknowledged(m, EnvItem, []byte("A=1\n"), s) { |
| + t.Error("a raw env item is acknowledged as sealed") |
| + } |
| + if SealedAcknowledged(m, "instance.key.sealed", []byte("A=1\n"), s) { |
| + t.Error("a missing item is acknowledged") |
| + } |
| + if SealedAcknowledged(m, SealedEnvItem, []byte("A=1\n"), newSealer(t, newKey(t), shopBinding, sealHost)) { |
| + t.Error("another key's digest matched") |
| + } |
| + if SealedAcknowledged(m, SealedEnvItem, []byte("A=1\n"), nil) || SealedAcknowledged(m, SealedEnvItem, []byte("A=1\n"), &ItemSealer{}) { |
| + t.Error("no sealer, or the zero sealer, acknowledged") |
| + } |
| + if st.gets+st.puts+st.deletes != 0 { |
| + t.Errorf("SealedAcknowledged made %d requests", st.gets+st.puts+st.deletes) |
| + } |
| +} |
| + |
| +// The sealed item names are the classifier's, in both layouts. |
| +func TestItemNamesMatchTheClassifier(t *testing.T) { |
| + want := []string{SealedEnvItem, "instance.key.sealed", "report.token.sealed"} |
| + for _, l := range []pubclass.Layout{pubclass.Nested, pubclass.Flat} { |
| + var got []string |
| + for _, r := range pubclass.SealedRels(l, sealHost) { |
| + got = append(got, r.Item()) |
| + } |
| + if !slices.Equal(got, want) { |
| + t.Errorf("%v: the classifier's items are %v, want %v", l, got, want) |
| + } |
| + } |
| +} |
| + |
| +// EnvItem is the raw env item pubclass names ("host.env"): the predicate |
| +// holds for it alone among this package's platform item names, so the two |
| +// cannot drift apart. |
| +func TestEnvItemIsTheClassifiersRawEnvItem(t *testing.T) { |
| + if !pubclass.IsRawSecretItem(pubclass.PlatformItems(), EnvItem) { |
| + t.Fatalf("pubclass does not take EnvItem %q for its raw env item", EnvItem) |
| + } |
| + for _, name := range []string{SealedEnvItem, "instance.key.sealed", "report.token.sealed", CutoverItem, WakeItem} { |
| + if pubclass.IsRawSecretItem(pubclass.PlatformItems(), name) { |
| + t.Errorf("pubclass takes %q for a raw secret item", name) |
| + } |
| + } |
| +} |
| + |
| +// DropRawSecrets edits the manifest only: the raw env item goes, a named |
| +// live entry is tombstoned, and every old object stays readable for the |
| +// manifest versions that name it. |
| +func TestDropRawSecretsTouchesNoObject(t *testing.T) { |
| + ctx := context.Background() |
| + st := &countingStore{Store: release.NewDirStore(t.TempDir())} |
| + p := open(t, st) |
| + if err := p.StagePlatform(ctx, EnvItem, []byte("A=1\n")); err != nil { |
| + t.Fatal(err) |
| + } |
| + stage(t, p, "instance.key", "raw-key") |
| + stage(t, p, "app.txt", "app") |
| + commit(t, p) |
| + old := loadM(t, st) |
| + |
| + if err := p.DropRawSecrets([]string{"instance.key", "../x"}); err == nil { |
| + t.Fatal("an unclean path was accepted") |
| + } |
| + if p.Dirty() { |
| + t.Fatal("a refused drop changed the manifest") |
| + } |
| + |
| + st.reset() |
| + if err := p.DropRawSecrets([]string{"instance.key", "report.token"}); err != nil { |
| + t.Fatal(err) |
| + } |
| + commit(t, p) |
| + if st.deletes != 0 || st.gets != 0 || st.puts != 1 { |
| + t.Fatalf("drop and commit: %d deletes, %d gets, %d puts; want the manifest PUT alone", st.deletes, st.gets, st.puts) |
| + } |
| + m := loadM(t, st) |
| + if _, ok := m.Platform[EnvItem]; ok { |
| + t.Error("the raw env item is still in the manifest") |
| + } |
| + if e := m.Entries["instance.key"]; !e.Deleted { |
| + t.Errorf("instance.key is %+v, want a tombstone", e) |
| + } |
| + if _, ok := m.Entries["report.token"]; ok { |
| + t.Error("an entry the manifest never held was tombstoned") |
| + } |
| + if e := m.Entries["app.txt"]; e.Deleted || e.Object == "" { |
| + t.Errorf("app.txt is %+v", e) |
| + } |
| + for _, key := range []string{old.Platform[EnvItem].Object, old.Entries["instance.key"].Object} { |
| + if _, _, err := st.Get(ctx, key); err != nil { |
| + t.Errorf("old object %s: %v", key, err) |
| + } |
| + } |
| + |
| + // Nothing left to drop: no change. |
| + if err := p.DropRawSecrets([]string{"instance.key", "report.token"}); err != nil || p.Dirty() { |
| + t.Fatalf("a second drop: %v, dirty %v", err, p.Dirty()) |
| + } |
| +} |
| + |
| +// The two fields are additive: a manifest with sealed items decodes and |
| +// validates as any other, restores, and a manifest without them writes |
| +// neither field. |
| +func TestManifestWithSealedItemsStillValidates(t *testing.T) { |
| + ctx := context.Background() |
| + st := release.NewDirStore(t.TempDir()) |
| + p := open(t, st) |
| + stage(t, p, "a.txt", "1") |
| + commit(t, p) |
| + raw, _, err := st.Get(ctx, ManifestKey(pfx)) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if bytes.Contains(raw, []byte(`"sealed"`)) || bytes.Contains(raw, []byte(`"plain_mac"`)) { |
| + t.Fatalf("a manifest without sealed items carries the new fields: %s", raw) |
| + } |
| + |
| + s := newSealer(t, newKey(t), shopBinding, sealHost) |
| + stageSealed(t, p, envRel(t), "A=1\n", s) |
| + commit(t, p) |
| + raw, _, err = st.Get(ctx, ManifestKey(pfx)) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + m, err := decode(pfx, raw) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := checkManifest(m, []string{pfx}); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := ValidateManifest(m, []string{pfx}); err != nil { |
| + t.Fatal(err) |
| + } |
| + var generic struct { |
| + Platform map[string]map[string]any `json:"platform"` |
| + } |
| + if err := json.Unmarshal(raw, &generic); err != nil { |
| + t.Fatal(err) |
| + } |
| + if generic.Platform[SealedEnvItem]["sealed"] != "v2" || generic.Platform[SealedEnvItem]["plain_mac"] == "" { |
| + t.Fatalf("wire shape %v", generic.Platform[SealedEnvItem]) |
| + } |
| + dir := t.TempDir() |
| + if _, rs, err := Restore(ctx, st, pfx, dir, nil); err != nil || rs.Written != 1 { |
| + t.Fatalf("restore: %v, %+v", err, rs) |
| + } |
| + if _, err := os.Stat(dir + "/" + SealedEnvItem); !errors.Is(err, os.ErrNotExist) { |
| + t.Fatalf("a platform item was restored into the files directory: %v", err) |
| + } |
| +} |
| + |
| +// The sealer refuses what it cannot bind, and StageSealed refuses a |
| +// SealedRel nobody got from the classifier or a missing sealer. |
| +func TestSealedRefusesBadInput(t *testing.T) { |
| + ctx := context.Background() |
| + priv := newKey(t) |
| + for name, c := range map[string]struct { |
| + priv *ecdh.PrivateKey |
| + b appconfig.Binding |
| + host string |
| + }{ |
| + "no key": {nil, shopBinding, sealHost}, |
| + "no account": {priv, appconfig.Binding{App: "shop"}, sealHost}, |
| + "no app": {priv, appconfig.Binding{Account: "bab"}, sealHost}, |
| + "no host": {priv, shopBinding, ""}, |
| + "a slash": {priv, shopBinding, "shop/test"}, |
| + "a traversal": {priv, shopBinding, ".."}, |
| + } { |
| + if _, err := NewItemSealer(c.priv, c.b, c.host); err == nil { |
| + t.Errorf("%s: NewItemSealer accepted it", name) |
| + } |
| + } |
| + st := &countingStore{Store: release.NewDirStore(t.TempDir())} |
| + p := open(t, st) |
| + s := newSealer(t, priv, shopBinding, sealHost) |
| + st.reset() |
| + if err := p.StageSealed(ctx, pubclass.SealedRel{}, []byte("x"), s); err == nil { |
| + t.Error("a zero SealedRel was staged") |
| + } |
| + if err := p.StageSealed(ctx, envRel(t), []byte("x"), nil); err == nil { |
| + t.Error("staged with no sealer") |
| + } |
| + if err := p.StageSealed(ctx, envRel(t), []byte("x"), &ItemSealer{}); err == nil { |
| + t.Error("staged with the zero sealer") |
| + } |
| + // A verdict for another host is not this sealer's to seal. |
| + r, _ := pubclass.SealedPath(pubclass.Nested, "other.test", "other.test.env") |
| + if err := p.StageSealed(ctx, r, []byte("x"), s); err == nil || !strings.Contains(err.Error(), "other.test") { |
| + t.Errorf("another host's path: %v", err) |
| + } |
| + if st.puts != 0 || p.Dirty() { |
| + t.Fatalf("refusals wrote: %d puts, dirty %v", st.puts, p.Dirty()) |
| + } |
| +} |
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv| index db6918f1a..66cc38659 100644 |
| --- a/internal/provision/testdata/plan14-root-reads-chain.tsv |
| +++ b/internal/provision/testdata/plan14-root-reads-chain.tsv |
| @@ -45,4 +45,4 @@ plan14-root-reads-fleet-public-routes.tsv bca6ef741a96b72767b1747789cd01b3111d61 |
| plan14-root-reads-fleet-routes-followups.tsv 1379d066c8dd2335d95d5f6e9c7bce65ff57f00b2b287a308d9b3f47911ae5e7 |
| plan14-root-reads-tunnel-websockets.tsv 949bc734a293366e6b2700244af5110dd6e84b5432023e991c09e806afd62483 |
| plan14-root-reads-console-protection-tab.tsv eaeb153ab7a7a849edc9c6e92f2ac5c709c6e39044a647971cf1fa5ebcb660c8 |
| -plan14-root-reads-durability-3a-escrow.tsv d1cf6e6d51e2b3451a4f3343b6d1ab66374c4dcde6c6f9bb21b52ccb1cf98350 |
| +plan14-root-reads-durability-3a-escrow.tsv 0da3b2b5686a83332323f61821f53b7f3070135f4ca54005946c4c4b1ee70f09 |
diff --git a/internal/provision/testdata/plan14-root-reads-durability-3a-escrow.tsv b/internal/provision/testdata/plan14-root-reads-durability-3a-escrow.tsv| index 0b81f4e37..01706c9be 100644 |
| --- a/internal/provision/testdata/plan14-root-reads-durability-3a-escrow.tsv |
| +++ b/internal/provision/testdata/plan14-root-reads-durability-3a-escrow.tsv |
| @@ -1,10 +1,13 @@ |
| # Census overlay durability-3a-escrow, written by census-propose (#369). census-ruling-durability-3a-escrow, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-durability-3a-escrow.md. |
| -# 0 body, 0 sites, 3 envelope: each changed unit re-frozen at its existing disposition with its claim appended. |
| -# 2 new dispositions: 0 reads re-frozen at their disposition with the claim, 1 new units frozen accepted-legacy, 1 quiet units retired while they read nothing, 0 other. |
| +# 0 body, 0 sites, 4 envelope: each changed unit re-frozen at its existing disposition with its claim appended. |
| +# 3 new dispositions: 0 reads re-frozen at their disposition with the claim, 2 new units frozen accepted-legacy, 1 quiet units retired while they read nothing, 0 other. |
| +@legacy 51297417f7d25f895c3793014740994855e599bf8731cf3295ea836820ae4f13 internal/hostfiles/sealed.go ReadSealed legacy accepted-legacy accepted-legacy;rev3=census-ruling-durability-3a-escrow;basis=durability 3a Task 2: new. Reads one sealed platform item of a files manifest the caller already loaded: the object at exactly the key the entry names, through the existing fetch (checkEntry: origin admitted, key shape, sha256 and size verified), only for an entry marked sealed "v2". The "Open" the scanner sees is appconfig.Open, an in-memory AES-GCM decryption of the fetched bytes, not a file open: no filesystem path is opened, read or followed. It refuses a v1 envelope (appconfig.EnvelopeBound), and after opening under the caller-supplied key and (account, app) binding it checks the HMAC digest over account, app, host and item against the entry. Writes nothing. No production caller in this task; Tasks 3 and 4 call it from the activator. file:Open@898 7c2b887b6e0b45472fd8d1a63a2b78eb565c4e93c89cb329eeeaef429ab0b010 |
| @legacy 7520abf7fe01442d3fcca5cc9c46cd22346ae2ad193162ed8df7ba9371914028 internal/layout/inventory.go Inventory legacy accepted-legacy accepted-legacy;rev3=census-ruling-durability-3a-escrow;basis=durability 3a Task 1: new. One os.ReadDir of the host's inventory root, provision.InstanceDir(dataDir, host) nested or dataDir flat, after refusing a host that fails controlname.ValidHostShape and a layout that is neither flat nor nested; reads only the listing's names and types (DirEntry.IsDir), opens and follows nothing; flat ownership is the extras scan's own (hostEntries over knownHosts); each top-level name is classified by pubclass.Of, a pure function of the name. A missing directory is an empty inventory. No caller in this task; later tasks call it from the publisher. file:ReadDir@449 9662e465abb7f9c60e908952740384479009c9987c8a6ae65d98fb19cb3d4d7e |
| +internal/hostfiles/sealed.go ReadSealed legacy accepted-legacy accepted-legacy;rev3=census-ruling-durability-3a-escrow;basis=durability 3a Task 2: new. Reads one sealed platform item of a files manifest the caller already loaded: the object at exactly the key the entry names, through the existing fetch (checkEntry: origin admitted, key shape, sha256 and size verified), only for an entry marked sealed "v2". The "Open" the scanner sees is appconfig.Open, an in-memory AES-GCM decryption of the fetched bytes, not a file open: no filesystem path is opened, read or followed. It refuses a v1 envelope (appconfig.EnvelopeBound), and after opening under the caller-supplied key and (account, app) binding it checks the HMAC digest over account, app, host and item against the entry. Writes nothing. No production caller in this task; Tasks 3 and 4 call it from the activator. file:Open@898 7c2b887b6e0b45472fd8d1a63a2b78eb565c4e93c89cb329eeeaef429ab0b010 |
| internal/layout/inventory.go Inventory legacy accepted-legacy accepted-legacy;rev3=census-ruling-durability-3a-escrow;basis=durability 3a Task 1: new. One os.ReadDir of the host's inventory root, provision.InstanceDir(dataDir, host) nested or dataDir flat, after refusing a host that fails controlname.ValidHostShape and a layout that is neither flat nor nested; reads only the listing's names and types (DirEntry.IsDir), opens and follows nothing; flat ownership is the extras scan's own (hostEntries over knownHosts); each top-level name is classified by pubclass.Of, a pure function of the name. A missing directory is an empty inventory. No caller in this task; later tasks call it from the publisher. file:ReadDir@449 9662e465abb7f9c60e908952740384479009c9987c8a6ae65d98fb19cb3d4d7e |
| @remove internal/layout/plan.go NestedPlatformNames |
| @removed internal/layout/plan.go NestedPlatformNames H3 census-ruling-durability-3a-escrow;basis=durability 3a Task 1: now a one-line wrapper for pubclass.NestedPlatformNames, which builds the same set (byte-identical, checked before and after) from pubclass.FileBases and the same instancectl/instancekey names, without nestedFiles or rawInstanceDir; it never read anything, and reads nothing now |
| @coverage internal/activator a9f6de4b8b6267b13a954ab27ceaa93ae811da0f88c1ea9d8ed817b64b1f51a8 |
| +@coverage internal/hostfiles 87c6a7acbc7a2b318e564c0426e480477e10912c10deb06181cd740e322734a2 |
| @coverage internal/layout 5d8b1d3bcd0b247e8088e4fb32bc26378ece37f41dc40f1d999e23913eccc9d0 |
| @coverage internal/layout/pubclass bd3938f002a5dca044378b71670e904736653d4914a8b1e06275e2b4dc79ed67 |