Skip to content

feat: add credential policy broker - #2

Merged
Hozzy02 merged 9 commits into
mainfrom
fm/fm-cred-broker
Aug 18, 2026
Merged

Hozzy02 merged 9 commits into
mainfrom
fm/fm-cred-broker

Conversation

@Hozzy02

@Hozzy02 Hozzy02 commented Aug 18, 2026

Copy link
Copy Markdown
Owner

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

  • Add a policy-backed credential broker with doctor, status, and task-bound exec commands for fixed Cloudflare Wrangler operations.
  • Isolate 1Password and Wrangler execution, deliver credentials only through a command-scoped environment, redact bounded provider output, preserve exit statuses, and record non-secret audits.
  • Document the credential architecture and policy schema, and add sentinel-based behavioral coverage for policy validation, leak prevention, denied operations, provider failures, and concurrent use.

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 get refusal. 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.

$ bin/fm-credential.sh doctor
policy: valid aliases=1
credential dash.cloudflare.deploy: available
doctor: ready

$ bin/fm-credential.sh status dash.cloudflare.deploy
credential dash.cloudflare.deploy: available

$ bin/fm-credential.sh exec task-a dash.cloudflare.deploy -- deploy-dry-run
dry-run accepted project=dash.lifelinevending.com environment=production

$ audit fields (non-secret metadata only)
task=task-a alias=dash.cloudflare.deploy adapter=cloudflare-wrangler operation=deploy-dry-run start=2026-08-17T03:14:07Z end=2026-08-17T03:14:07Z exit_class=success exit_code=0
sentinel-scan=clean
runtime-residue=none

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 $operation directly to audit_append. An operation containing tabs/newlines can forge fields or whole audit entries, and sensitive text is persisted verbatim. Record a constant such as operation=invalid for 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 turn deploy-dry-run into 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,” but op read runs 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 personal OP_SESSION or desktop integration can satisfy status/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 as CLOUDFLARE_API_BASE_URL to redirect the authenticated probe/deploy, or WRANGLER_LOG_PATH with sanitization disabled to create credential-bearing diagnostics. This contradicts the required command-scoped delivery and env -i boundary. 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_alias never resolves or validates the alias's registered project before probing the token. Consequently, an alias naming a nonexistent $FM_HOME/projects/<project> can report available and make doctor report ready, even though every exec attempt later fails project binding; conversely, task-local Wrangler installations are ignored here. Resolve the registered project and use it for readiness checks, or explicitly narrow status/doctor to 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,” but head -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 than MAX_SECRET_BYTES; a later token cut by this head boundary 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.sh before the test addition
  • Synthetic fresh-worker doctor, status, and exec task-a dash.cloudflare.deploy -- deploy-dry-run with ambient Wrangler OAuth present; the provider stub enforced isolated auth, token-free argv, and removal of the broker identity
  • Sentinel scan across task state and worktree plus credential runtime-residue inspection
  • Added the explicit raw-get denial assertion to tests/fm-credential.test.sh
  • bin/fm-test-run.sh tests/fm-credential.test.sh after the test addition
✅ **Document** - passed

✅ No issues found.

🔧 **Lint** - 1 issue found → auto-fixed ✅
  • ⚠️ linter found issues (exit code 1)

🔧 Fix: Document intentional child-shell expansion for ShellCheck
✅ Re-checked - no issues remain.

✅ **Push** - passed

✅ No issues found.

@Hozzy02
Hozzy02 merged commit eb627ec into main Aug 18, 2026
13 checks passed
@Hozzy02
Hozzy02 deleted the fm/fm-cred-broker branch September 26, 2026 00:41
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