Skip to content

fix(cloud): allow issued_token key in bootstrap audit metadata#663

Open
jacsdev wants to merge 3 commits into
Gentleman-Programming:mainfrom
jacsdev:fix/cloud-bootstrap-issued-token-audit-metadata
Open

fix(cloud): allow issued_token key in bootstrap audit metadata#663
jacsdev wants to merge 3 commits into
Gentleman-Programming:mainfrom
jacsdev:fix/cloud-bootstrap-issued-token-audit-metadata

Conversation

@jacsdev

@jacsdev jacsdev commented Jul 24, 2026

Copy link
Copy Markdown

Problem

engram cloud bootstrap admin --issue-token always fails with:

cloudstore: auth audit insert failed: cloudstore: sensitive auth audit metadata is not allowed: issued_token

The admin principal is created and committed, but token issuance rolls back (the token and its audit are written atomically), so a fresh deployment is left with a token-less admin and no supported recovery path — every token-issuing route requires an existing managed-admin token. Reported in #597 and #603.

Root cause

cloudBootstrapCompletionMetadata (cmd/engram/cloud_bootstrap.go) records a boolean issued_token flag. sensitiveAuthAuditKey (internal/cloud/cloudstore/identity.go) classifies any key containing the substring token as sensitive, except the whitelisted token_prefix. issued_token contains token, so it is rejected and the atomic token+audit write fails.

The same completion metadata is also written when bootstrapping with --grant-project (even without --issue-token), so that path fails at the completion audit as well.

Fix

Whitelist issued_token alongside the existing token_prefix exception in sensitiveAuthAuditKey. It is a non-secret boolean flag, not credential material — the secret-bearing keys (raw_token, token_hash, authorization, password, …) remain rejected, including nested values.

Test

Regression assertions added to TestCloudstoreIdentityPureHelpers:

  • sensitiveAuthAuditKey("issued_token") must be false
  • rejectSensitiveAuthAuditMetadata({"issued_token": true, ...}) must return nil
go test ./internal/cloud/cloudstore/
ok  github.com/Gentleman-Programming/engram/internal/cloud/cloudstore

Fixes #597
Fixes #603

Summary by CodeRabbit

  • Bug Fixes
    • Improved audit metadata validation to treat issued_token as safe only when its value is a boolean.
    • Ensures bootstrap completion audit events accept issued_token with boolean values, while still rejecting issued_token when the value is not a boolean, including within nested metadata.
  • Tests
    • Added regression coverage for issued_token validation at both top-level and nested metadata to prevent future validation regressions.

`engram cloud bootstrap admin --issue-token` always failed with
"sensitive auth audit metadata is not allowed: issued_token". The
bootstrap completion audit records a boolean `issued_token` flag, but
sensitiveAuthAuditKey rejected every key containing "token". Because the
token and its audit are persisted atomically, the token was never
minted, and since bootstrap refuses to run twice this left a token-less
admin with no supported recovery path (all token-issuing routes require
an existing managed-admin token).

Whitelist `issued_token` next to the existing `token_prefix` exception:
it is a non-secret boolean flag, not credential material. Add a
regression test asserting the key is accepted.

Fixes Gentleman-Programming#597
Fixes Gentleman-Programming#603
@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: c71d8c5f-334b-4c45-8d51-7ca73003cdad

📥 Commits

Reviewing files that changed from the base of the PR and between 3bb4fb0 and 53a9b5a.

📒 Files selected for processing (1)
  • internal/cloud/cloudstore/identity_storage_test.go

📝 Walkthrough

Walkthrough

The sensitive audit metadata filter now exempts issued_token only when its value is boolean, including nested metadata. Tests cover accepted boolean values and rejected non-boolean values while preserving token_prefix handling.

Changes

Audit metadata validation

Layer / File(s) Summary
Value-aware issued-token exemption
internal/cloud/cloudstore/identity.go, internal/cloud/cloudstore/identity_storage_test.go
The filter applies a (key, value) exemption for boolean issued_token entries, including nested maps, while non-boolean values remain rejected. Regression tests cover top-level and nested cases and retain direct token_prefix handling.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested reviewers: gentleman-programming

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: allowing issued_token in bootstrap audit metadata.
Linked Issues check ✅ Passed The PR fixes the reported bootstrap failure by exempting boolean issued_token metadata and adds regression coverage.
Out of Scope Changes check ✅ Passed The changes stay focused on the sensitive audit metadata filter and its tests, with no obvious unrelated scope creep.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/cloud/cloudstore/identity.go`:
- Around line 958-964: The issued_token whitelist in
internal/cloud/cloudstore/identity.go:958-964 must only bypass
sensitive-metadata filtering when its value is boolean, both at the top level
and recursively; update the relevant filtering logic around the visible key
switch while preserving token_prefix behavior. Add rejection tests in
internal/cloud/cloudstore/identity_storage_test.go:542-549 covering
string/token-like issued_token values and nested non-boolean values.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 60a511db-15c4-444d-8acc-444dc9df2a73

📥 Commits

Reviewing files that changed from the base of the PR and between 763a6ba and 0bc2edb.

📒 Files selected for processing (2)
  • internal/cloud/cloudstore/identity.go
  • internal/cloud/cloudstore/identity_storage_test.go

Comment thread internal/cloud/cloudstore/identity.go Outdated
Address review feedback: the issued_token whitelist bypassed the
sensitive-metadata filter by key name alone, so a non-boolean value could
smuggle secret material under a trusted key. Exempt issued_token only when
its value is actually a bool, at the top level and recursively; otherwise
the key falls through to the normal sensitive-fragment heuristic.

Adds rejection tests for string and nested non-boolean issued_token values.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/cloud/cloudstore/identity_storage_test.go`:
- Around line 547-558: Extend the rejectSensitiveAuthAuditMetadata tests to
cover issued_token set to false, including the nested metadata case if following
the existing true assertion pattern. Assert no error is returned, preserving the
exemption for both boolean values while retaining rejection of non-boolean
issued_token values.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: ed409729-5169-428a-8d4e-aeaae0308c53

📥 Commits

Reviewing files that changed from the base of the PR and between 0bc2edb and 3bb4fb0.

📒 Files selected for processing (2)
  • internal/cloud/cloudstore/identity.go
  • internal/cloud/cloudstore/identity_storage_test.go

Comment thread internal/cloud/cloudstore/identity_storage_test.go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant