Skip to content

fix(storage,crypto,oci): zeroize keys, guard oci ssrf, clean local tmp files, unify gcp auth - #1852

Closed
nikhilunni wants to merge 6 commits into
mainfrom
audit/p1-crypto-oci-storage
Closed

nikhilunni wants to merge 6 commits into
mainfrom
audit/p1-crypto-oci-storage

Conversation

@nikhilunni

@nikhilunni nikhilunni commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Hardens cryptography, OCI registry access, local blob staging, and cloud client resilience:

  • engram-crypto: Zeroizes raw DEKs, EnvVarKeyProvider key material, and (with the aes-gcm zeroize feature) the expanded AES and GHASH keys on drop. The persisted envelope format does not change: old rows open on the new build, and rows the new build seals open on the old build. No AAD API is added: a sealed row does not record whether it used AAD, so AAD needs a format marker and its callers in one change.
  • engram-oci: Gates plaintext loopback HTTP behind ENGRAM_OCI_ALLOW_INSECURE_LOOPBACK=1 (the Tiltfile sets it) and rejects private, loopback, link-local, and metadata registry addresses unless ENGRAM_OCI_ALLOW_PRIVATE_REGISTRIES=1. A registry passes the check once per client, so a ranged pull does not do one DNS lookup per part. The blob HEAD probe follows redirects only to HTTPS hosts that are not loopback names or private address literals. oci-client owns its own DNS, redirects, and token requests, so DNS rebinding and those redirects stay a network egress policy concern.
  • engram-storage-local: Removes <stem>.tmp.<pid>.<nanos> staging files on a failed put_streaming and filters that shape out of list_prefix.
  • Cloud auth & retries: One cached GCP metadata token source (crates/engram-cloud-gcp/src/auth.rs) with single-flight refresh and conditional 401 invalidation, used by engram-cloud-gcp and engram-secrets-gcp; bounded transient retries in engram-kms-aws, engram-secrets-aws, engram-secrets-gcp, and engram-cloud-gcp. GKE deleteInstances carries a requestId, so a retry does not repeat the delete.

Upgrade note

A deployment that pulls from an in-cluster registry, or from a cloud registry behind a private endpoint (for example an ECR VPC endpoint with private DNS), must set ENGRAM_OCI_ALLOW_PRIVATE_REGISTRIES=1 on the coordinator and the host agents (extraEnv in both charts) before it rolls this build. Without it, image enables and pulls from that registry fail.

Validation

  • cargo fmt --check, cargo clippy --all-targets -- -D warnings, cargo hakari generate --diff.
  • cargo nextest run for engram-crypto, engram-oci, engram-storage-local, engram-cloud-gcp, engram-secrets-gcp, engram-kms-aws, engram-secrets-aws.

🤖 Generated with Claude Code

@nikhilunni nikhilunni changed the title fix(storage,crypto,oci): zeroize keys, add AAD, guard OCI SSRF, clean local tmp files, unify GCP auth fix(storage,crypto,oci): zeroize keys, guard oci ssrf, clean local tmp files, unify gcp auth Dec 2, 2026
@nikhilunni
nikhilunni marked this pull request as ready for review December 2, 2026 21:53
nikhilunni and others added 6 commits December 2, 2026 13:55
… 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>
@nikhilunni

Copy link
Copy Markdown
Contributor Author

Combined into #1860 with the other audit PRs, so they merge and deploy together.

@nikhilunni nikhilunni closed this Dec 3, 2026
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