Skip to content

fix(security): combine the storage, oci, cli, rbac, admin grpc and broker secret audit fixes - #1860

Merged
nikhilunni merged 22 commits into
mainfrom
audit/combined-security-batch
Dec 3, 2026
Merged

nikhilunni merged 22 commits into
mainfrom
audit/combined-security-batch

Conversation

@nikhilunni

Copy link
Copy Markdown
Contributor

Summary

This PR combines four reviewed PRs from the security audit into one change, so that they merge and deploy together: #1852, #1853, #1857 and #1859. Each source branch is merged in with a merge commit, so git log keeps each original commit. The only hand-resolved conflicts are:

One new commit fixes a test. After #1850 the coordinator HTTP router fails closed. The HTTP leg of #1857's admin_pause_resume_preserves_state_and_error_mapping sent no bearer, so it got 401. Now the test fixture gives the REST auth tokens the same list as the app-gRPC tokens, and the HTTP request sends the bearer.

The original PRs carry the full description and review history of each part.

Storage, crypto and OCI (from #1852)

  • engram-crypto zeroizes raw DEKs, the key material from env vars, and the expanded AES and GHASH keys. The envelope format does not change.
  • engram-oci refuses registries at loopback, private, link-local and metadata addresses unless ENGRAM_OCI_ALLOW_PRIVATE_REGISTRIES=1 is set. It sends plain HTTP to a loopback registry only when ENGRAM_OCI_ALLOW_INSECURE_LOOPBACK=1 is set. The HEAD probe follows redirects only to public HTTPS hosts.
  • engram-storage-local removes its staging files when a put fails, and leaves them out of listings.
  • All GCP clients share one cached metadata token source. AWS and GCP clients retry transient failures a bounded number of times. The GKE deleteInstances call carries a requestId.

CLI, operator RBAC and tooling (from #1853)

  • hosts.json is written atomically with mode 0o600. A corrupt file now gives an error; before, it silently wiped stored logins.
  • The host-fleet operator's access to DaemonSets and pods moves from its ClusterRole to a namespaced Role and RoleBinding.
  • Tiltfile secrets move to env=. The justfile sets errexit and pipefail. seed-buckets.sh uses mktemp. The stray .codex-review-*.md files are removed.

Admin pause/resume over app-gRPC (from #1857)

  • SessionService.PauseSession and ResumeSession call the same core functions as the HTTP routes, with the same admin-only authorization.
  • The orchestrator does not call them yet. The cutover (branch audit/p1-admin-pause-resume-orch) merges only after this PR is deployed. The HTTP routes stay until then.
  • HandoffMarker has one definition, in engram-protocol. Its bytes on the wire and on disk do not change, and a crash-state test pins them.

Dedicated connection-broker secret (from #1859)

  • The new value orchestrator.connectionBrokerSecret (existingSecret, key) gives the coordinator and the orchestrator the same broker bearer. When the value is unset, nothing changes. This is the expand step. A later release makes the dedicated secret mandatory.

Before you deploy

  • Host-fleet chart deployer permissions (fix(cli,deploy): harden hosts.json writes, scope operator RBAC, fix Tiltfile and tooling hygiene #1853). The deployer must be allowed to create the operator Role and RoleBinding in the release namespace, and must itself hold the Role's rules: daemonsets: get, list, watch, patch and pods: get, list, watch, delete. A cluster-admin deployer needs nothing. Grant these to a non-admin deploy identity before the upgrade.
  • Private image registries (fix(storage,crypto,oci): zeroize keys, guard oci ssrf, clean local tmp files, unify gcp auth #1852). A deployment that pulls from an in-cluster registry, or from a registry behind a private endpoint, must set ENGRAM_OCI_ALLOW_PRIVATE_REGISTRIES=1 on the coordinator and the host agents (extraEnv) before it rolls this build.
  • Rollout. Every part is safe in either roll order and on rollback. The gRPC methods are new and nothing calls them yet. The broker value is opt-in. The RBAC move causes a short window of Forbidden errors that the operator recovers from by requeueing.

CHANGELOG.md has the upgrade notes under [Unreleased].

Validation

  • Each source PR passed CI Gate on its own after a rebase onto current main.
  • On the combined branch: cargo fmt --all --check; cargo nextest run -p engram-coordinator --test grpc_app (21 pass); cargo clippy -D warnings on coordinator, protocol, host-core, oci and crypto; cargo hakari generate --diff; orchestrator: bun run typecheck, pause-resume-policy.test.ts and authz.matrix.test.ts (28 pass).
  • The CI Gate on this PR's head is the full gate.

Supersedes #1852, #1853, #1857, #1859.

🤖 Generated with Claude Code

nikhilunni and others added 22 commits December 1, 2026 16:38
The chart rolls the coordinator and the orchestrator at the same time.
An orchestrator that calls PauseSession or ResumeSession on a
coordinator without those methods gets Unimplemented. This PR now
ships only the coordinator methods, the generated clients, and the
admin-only policy entries. The orchestrator route cutover moves to a
follow-up that merges after this change is deployed.

Restore admin.ts and config.ts to the REST proxy, keep the direct-RPC
policy gate test, and make the coordinator comments state the current
callers of the HTTP routes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The handoff marker type moved to engram-protocol. The successor reads
the file that the previous build wrote, so pin the pretty JSON bytes
the writer produces. Also cover every post-crash state of the
tmp-then-rename write: a torn marker at each byte offset is removed
and reads as a fresh start, and a leftover tmp sibling is ignored.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… schedule

`seal_with_aad` and `open_with_aad` had no caller. A sealed row does not
record whether it was sealed with AAD, so a reader cannot select the
right open without a schema change, and an open that falls back to empty
AAD gives no binding. The API stays out until a change adds the format
marker and the callers together.

Turn on the aes-gcm `zeroize` feature so the expanded AES and GHASH keys
are cleared on drop, as the raw DEK and KEK already are. The persisted
envelope format does not change; the aes-gcm 0.10.3 vector still opens.

Restore the two facts the earlier cleanup dropped: why `SysRng` is used
(a `!Send` RNG makes the seal future `!Send`), and that a failure of the
fixed-vector test is a data problem, not a value to update.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… redirects

The address check ran a DNS lookup before every pull part, so a ranged
layer pull did one lookup per part on the resume path. A registry that
passes the check is now kept in a per-client set. A policy change
(`with_insecure_loopback`, `with_private_registries`) clears the set, so
a clone with a stricter policy does not reuse a looser result.

The HEAD probe client refused all redirects. A registry with a
redirecting storage driver answers a blob HEAD with a redirect, so a
bake against it failed. Redirects now follow to HTTPS hosts that are not
loopback names or private address literals, or to any HTTPS host when
private registries are allowed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…pback opt-in

`ENGRAM_OCI_ALLOW_PRIVATE_REGISTRIES` is a new setting that a deployment
with an in-cluster registry or a private registry endpoint must set, so
the configuration reference lists it for the coordinator and the host
agents. The compose file comment now names the loopback opt-in. The
Tiltfile entries move next to the other local-service settings, away
from the first line of `coord_env`, which another open change also edits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`list_prefix` hid every name that started with `.tmp.`, but no staging
file has that shape: `put_streaming` names its staging file
`<stem>.tmp.<pid>.<nanos>`. The rule hid valid keys such as `.tmp.key`.
Only the real staging shape is now filtered.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The coordinator sends ENGRAM_CONNECTION_BROKER_BEARER to the
orchestrator's connection credential broker. The chart took it from the
CONTROL_PLANE_BEARER key and could not set the orchestrator's
CONNECTION_BROKER_BEARER, so every chart deployment used the
control-plane bearer for the broker.

`orchestrator.connectionBrokerSecret` (`existingSecret`, `key`) now
feeds both variables from one Secret key, so they always match. When
`existingSecret` is empty, the render is the same as before: the
coordinator reads the CONTROL_PLANE_BEARER key, and the orchestrator
env omits CONNECTION_BROKER_BEARER and falls back. This is the expand
step; a later release makes the dedicated secret required.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…request

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
write_hosts now closes the temp file before the rename, keeps the write or
rename error when the cleanup also fails, and fsyncs the directory so the
rename is durable. The test directory guard no longer panics in drop.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…o audit/combined-security-batch

# Conflicts:
#	CHANGELOG.md
…audit/combined-security-batch

# Conflicts:
#	CHANGELOG.md
… audit/combined-security-batch

# Conflicts:
#	CHANGELOG.md
…' into audit/combined-security-batch

# Conflicts:
#	crates/engram-coordinator/src/api/mod.rs
The coordinator HTTP router now fails closed when it has no auth
tokens. The grpc_app fixture set only the app-gRPC tokens, so the HTTP
leg of admin_pause_resume_preserves_state_and_error_mapping got 401.
The fixture now gives the REST auth tokens the same list, and the HTTP
request sends the bearer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Dec 3, 2026

Copy link
Copy Markdown

The latest Buf updates on your PR. Results from workflow CI / buf (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed⏩ skipped⏩ skipped✅ passedDec 3, 2026, 5:15 PM

@nikhilunni
nikhilunni merged commit 3fbb253 into main Dec 3, 2026
25 checks passed
@nikhilunni
nikhilunni deleted the audit/combined-security-batch branch December 3, 2026 17:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant