Repository navigation
feat: add credential policy broker - #2
Merged
Merged
Conversation
This was referenced Sep 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Intent
Build the first shippable Priority 0 and Priority 1 slice of Firstmate credential management from the authoritative credential-management report. Create docs/credentials.md as the single architecture owner for the same-user soft-boundary trust model, the invariant that secrets never enter argv, pane input, metadata, status, audit, diagnostics, reports, fixtures, or timing, the config/credentials.json schema and validation rules, the provider-adapter contract, captain-only actions, and secondmate filtered-policy, per-host-account, no-primary-secret-forwarding, and env -i rules. Define and validate the gitignored config/credentials.json policy schema containing aliases and non-secret metadata only. Reject unknown keys or adapters, duplicate aliases, missing exact project or environment, free-form shell commands, secret-looking inline values, paths outside effective FM_HOME, unsafe policy symlinks, ownership, hardlinks, or modes, and secondmate projects outside the registered charter. Implement bin/fm-credential.sh with doctor, status , and exec -- [args...], with safe regular-file resolution, exact task project and kind binding, adapter-owned operation and executable allowlists, availability and expiration preflight, secret resolution through the broker's 1Password identity in a subshell, delivery only to the exact child through a supported descriptor or command-scoped environment, bounded redacted output preserving the real exit status, trapped cleanup and variable unsetting, and non-secret audit metadata. Refuse env, printenv, arbitrary sh -c, unrecognized operations or executables, ambient OAuth fallback, and any raw get command. Implement the Cloudflare Wrangler adapter using one scoped Cloudflare API token item per project and environment, CLOUDFLARE_API_TOKEN only in the wrangler subprocess, a token-safe wrangler whoami probe, fixed deploy, deploy-dry-run, and whoami operations, static-token expiry tracking and captain-owned rotation, and distinct missing, revoked or expired, insufficient-scope, and network failures. Add sentinel-only behavioral leak tests proving the synthetic secret never appears in repository files, task records or metadata, process argv, pane capture, logs, report output, or teardown residue, including unsafe mode, symlink, hardlink, unknown alias, wrong project or environment, ungranted operation, missing backend, invalid or expired token, provider outage, and concurrent-use negative paths. Prove a fresh worker without usable Wrangler OAuth state can run an approved dash operation through the alias with a sentinel token. Store no real credentials, do not add config/credentials.json to the secondmate inheritance allowlist, follow the firstmate tracked-material one-owner and repository-style rules, keep bin scripts shellcheck-clean, and test behavior without asserting source bytes.
What Changed
doctor,status, and task-boundexeccommands for fixed Cloudflare Wrangler operations.Risk Assessment
✅ Low: The streaming redactor closes the prior boundary and compression leak paths while preserving bounded output, stream draining, cleanup, and provider exit status.
Testing
Both focused suite runs passed, including policy safety, leak/redaction boundaries, task and operation denial, provider failure classification, fresh-worker command-scoped Wrangler access, concurrency, cleanup, and the added raw
getrefusal. The CLI transcript is the reviewer-visible artifact; no screenshot was appropriate because this change has no graphical surface.Evidence: Credential broker CLI transcript
Shows valid policy, available alias, successful approved dry run, non-secret audit metadata, clean sentinel scan, and no runtime residue.Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
🔧 **Review** - 2 issues found → auto-fixed (5) ✅
bin/fm-credential.sh:598- The intent requires that secrets never enter audit records and that audit metadata remain non-secret, but the denial hunk passes the unrecognized, caller-controlled$operationdirectly toaudit_append. An operation containing tabs/newlines can forge fields or whole audit entries, and sensitive text is persisted verbatim. Record a constant such asoperation=invalidfor rejected values, or validate to a safe atom before auditing.bin/fm-credential.sh:500- The intent requires exact project/environment binding and fixed adapter operations, but this argument denylist still permits Wrangler aliases and target-changing options such as-e staging,-c alternate.toml, and--name other-worker; it also permits boolean negations such as--no-dry-run. Because these arguments are forwarded after the adapter-owned arguments, an approved alias can target a different environment/configuration/resource or potentially turndeploy-dry-runinto a real deployment. Replace the denylist with operation-specific positive argument allowlists, preserving all binding and dry-run flags as adapter-owned values.🔧 Fix: Captain, harden credential audit and Wrangler allowlists
2 errors still open:
bin/fm-credential.sh:308- The intent requires “secret resolution through the broker's 1Password identity in a subshell,” butop readruns with the caller's inherited authentication context and does not require or select the restricted broker identity. When no broker service-account token is present, an ambient personalOP_SESSIONor desktop integration can satisfystatus/exec, bypassing the per-host and vault restrictions. Resolve through an explicitly selected broker identity in an isolated environment and fail closed when that identity is unavailable.bin/fm-credential.sh:365- The argument fix does not close the equivalent Wrangler environment path: this subshell inherits every caller variable except a short denylist. A caller can still set supported controls such asCLOUDFLARE_API_BASE_URLto redirect the authenticated probe/deploy, orWRANGLER_LOG_PATHwith sanitization disabled to create credential-bearing diagnostics. This contradicts the required command-scoped delivery andenv -iboundary. Invoke Wrangler under an explicit minimal environment allowlist at this shared execution boundary.🔧 Fix: Captain, isolate broker identity and Wrangler environment
1 warning still open:
bin/fm-credential.sh:559-status_aliasnever resolves or validates the alias's registered project before probing the token. Consequently, an alias naming a nonexistent$FM_HOME/projects/<project>can reportavailableand makedoctorreport ready, even though everyexecattempt later fails project binding; conversely, task-local Wrangler installations are ignored here. Resolve the registered project and use it for readiness checks, or explicitly narrowstatus/doctorto credential-only semantics.🔧 Fix: Captain, align credential readiness with project binding
1 error still open:
bin/fm-credential.sh:422- The intent requires “secrets never enter … reports” and “bounded redacted output,” buthead -c "$OUTPUT_LIMIT" "$path" > "$bounded"truncates before redaction. If output begins with 65,530 safe bytes followed by the token, capture/truncation retains and prints only a token prefix, so the exact-value matcher never sees the complete secret and the existing full-sentinel assertion still passes. Capture enough overlap for the maximum token length and redact before applying the final output cap, or use an overlap-aware streaming redactor.🔧 Fix: Captain, redact provider output before truncation
1 error still open:
bin/fm-credential.sh:354- The intent requires that secrets never enter reports, but the durable fix still bounds raw output before redaction. If earlier complete token occurrences are replaced with shorter[REDACTED]markers, they can shrink the redacted stream by more thanMAX_SECRET_BYTES; a later token cut by thisheadboundary then shifts inside the final 65,536-byte output cap and its unmatched prefix is printed. Redact while draining with a token-length carry, cap only already-redacted bytes, and continue draining the remaining provider output.🔧 Fix: Captain, stream redaction before bounding provider output
✅ Re-checked - no issues remain.
✅ **Test** - passed
✅ No issues found.
bin/fm-test-run.sh tests/fm-credential.test.shbefore the test additionSynthetic fresh-workerdoctor,status, andexec task-a dash.cloudflare.deploy -- deploy-dry-runwith ambient Wrangler OAuth present; the provider stub enforced isolated auth, token-free argv, and removal of the broker identitySentinel scan across task state and worktree plus credential runtime-residue inspectionAdded the explicit raw-getdenial assertion totests/fm-credential.test.shbin/fm-test-run.sh tests/fm-credential.test.shafter the test addition✅ **Document** - passed
✅ No issues found.
🔧 **Lint** - 1 issue found → auto-fixed ✅
🔧 Fix: Document intentional child-shell expansion for ShellCheck
✅ Re-checked - no issues remain.
✅ **Push** - passed
✅ No issues found.