Skip to content

feat: bind Secrets Store for Mercury + CF Access tokens#138

Open
chitcommit wants to merge 9 commits intomainfrom
feat/secrets-store-bindings
Open

feat: bind Secrets Store for Mercury + CF Access tokens#138
chitcommit wants to merge 9 commits intomainfrom
feat/secrets-store-bindings

Conversation

@chitcommit
Copy link
Copy Markdown
Contributor

@chitcommit chitcommit commented Mar 28, 2026

Summary

  • Adds 14 secrets_store_secrets bindings at top-level in wrangler.jsonc
  • 7 Mercury API tokens (one per org)
  • 1 Ch1tty MCP bearer token
  • 6 CF Access service token credentials (client_id + client_secret for chittycommand, chittyagent, chittyfinance)

Secrets are provisioned in the Cloudflare Secrets Store (default_secrets_store). Bindings make them available at runtime via await env.BINDING_NAME.get().

Test plan

  • Verify wrangler deploy --env production succeeds with new bindings
  • Confirm env.MERCURY_TOKEN_ARIBIA_LLC.get() returns token at runtime
  • Test credential retrieval via /api/credentials endpoint

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • Standardized and updated secret bindings for external API credentials across deployment config.
    • Moved and declared secrets and OIDC/client credentials per environment for clearer, explicit environment wiring.
    • Activated the disputes service binding in each environment so dispute handling is wired and available at runtime.

…service tokens

Add 14 top-level secrets_store_secrets bindings to ChittyConnect:
- 7 Mercury API tokens (one per org)
- 1 Ch1tty MCP token
- 6 CF Access service token credentials (client_id + secret for chittycommand, chittyagent, chittyfinance)

Secrets are stored in the default_secrets_store (e914522471964c3c8cf1e601770edcc3) and accessible
via async env.BINDING_NAME.get() at runtime. This enables ChittyConnect to serve as the credential
broker for Mercury API tokens and CF Access service-to-service auth across the ecosystem.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 28, 2026 17:02
@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@cloudflare-workers-and-pages
Copy link
Copy Markdown
Contributor

cloudflare-workers-and-pages Bot commented Mar 28, 2026

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
chittyconnect 2400ac8 May 05 2026, 06:11 PM

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 28, 2026

Warning

Rate limit exceeded

@Copilot has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 39 minutes and 47 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a0d03029-d00b-4960-bfe5-efaf672ce164

📥 Commits

Reviewing files that changed from the base of the PR and between 4bd45ef and 2400ac8.

📒 Files selected for processing (2)
  • src/api/routes/thirdparty.js
  • wrangler.jsonc
📝 Walkthrough

Walkthrough

Top-level and per-environment Cloudflare Wrangler configuration updated: secret binding names renamed from MERCURY_TOKEN_*MERCURY_API_KEY_*, CH1TTY_MCP_TOKEN casing standardized, per-env secrets_store_secrets arrays added/expanded, and SVC_DISPUTES service binding enabled in dev/staging/production.

Changes

Wrangler configuration updates

Layer / File(s) Summary
Secret name changes (data shape)
wrangler.jsonc
Renamed secrets from MERCURY_TOKEN_* to MERCURY_API_KEY_*; changed MCP secret secret_name from ch1tty_mcp_tokenCH1TTY_MCP_TOKEN.
Top-level declarations
wrangler.jsonc
Updated top-level secrets_store_secrets to reference MERCURY_API_KEY_* names and capitalized MCP entry; note added that env blocks must declare their own secrets.
Per-environment secret wiring
wrangler.jsonc (env.dev, env.staging, env.production)
Added/expanded secrets_store_secrets arrays per environment with Mercury API keys, CH1TTY_MCP_TOKEN, CF Access client ID/secret pairs, MERCURY_OIDC_*, and Mint/ChittyAuth keys.
Service bindings / integration
wrangler.jsonc (env.dev, env.staging, env.production)
Enabled SVC_DISPUTESchittydispute service binding in dev, staging, and production (replacing previously disabled/commented entries).
Tests / Documentation
(none changed)
No test or docs files modified in this diff.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

security-approved, access-reviewed

Poem

🐰
I hopped through configs, soft and spry,
Renamed the keys, gave secrets a try.
Services awake, bindings set right—
A merry hop into the night. 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is incomplete; it lacks critical sections required by the template including Security & Access checklist items, Docs updates, and Validation steps. Add Security & Access section with security/docs/access review checkboxes, Docs section confirming no doc updates needed, and Validation section with CI/test status.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding Secrets Store bindings for Mercury and CF Access tokens.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/secrets-store-bindings

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 and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@wrangler.jsonc`:
- Around line 52-53: The binding name CH1TTY_MCP_TOKEN and its secret_name
ch1tty_mcp_token use inconsistent casing; update the secret mapping so the two
match (e.g., change secret_name to CH1TTY_MCP_TOKEN) to avoid confusion and
potential case-sensitivity issues when resolving secrets, ensuring you modify
the same object that currently contains "binding": "CH1TTY_MCP_TOKEN" and
"secret_name": "ch1tty_mcp_token".
- Around line 43-51: The secret bindings in wrangler.jsonc use the prefix
MERCURY_TOKEN_* but getMercuryToken() expects MERCURY_API_KEY_{ORG}; update the
bindings so both "binding" and "secret_name" fields are renamed from
MERCURY_TOKEN_{ORG} to MERCURY_API_KEY_{ORG} (e.g., MERCURY_TOKEN_ARIBIA_LLC ->
MERCURY_API_KEY_ARIBIA_LLC) for each entry, or alternatively modify
getMercuryToken() to look up MERCURY_TOKEN_{ORG} instead—pick one approach and
apply it consistently so the env key names used by getMercuryToken() match the
secret binding names.
🪄 Autofix (Beta)

✅ Autofix completed


ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 24cf2616-2c12-498f-8eb4-a0bfc2987632

📥 Commits

Reviewing files that changed from the base of the PR and between 91e0cef and 6addd3e.

📒 Files selected for processing (1)
  • wrangler.jsonc

Comment thread wrangler.jsonc Outdated
Comment thread wrangler.jsonc Outdated
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds Cloudflare Secrets Store secret bindings to the worker’s Wrangler configuration so Mercury tokens and Cloudflare Access service-token credentials can be fetched at runtime via Secrets Store.

Changes:

  • Introduces a top-level secrets_store_secrets block in wrangler.jsonc.
  • Binds 14 secrets (7 Mercury org tokens, 1 MCP token, 6 CF Access client_id/client_secret values) to runtime env.*.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread wrangler.jsonc Outdated
Comment thread wrangler.jsonc Outdated
Comment on lines +59 to +60
{ "binding": "CF_ACCESS_CLIENT_ID_CHITTYFINANCE", "store_id": "e914522471964c3c8cf1e601770edcc3", "secret_name": "CF_ACCESS_CLIENT_ID_CHITTYFINANCE" },
{ "binding": "CF_ACCESS_CLIENT_SECRET_CHITTYFINANCE", "store_id": "e914522471964c3c8cf1e601770edcc3", "secret_name": "CF_ACCESS_CLIENT_SECRET_CHITTYFINANCE" }
Copy link

Copilot AI Mar 28, 2026

Choose a reason for hiding this comment

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

Binding long-lived Mercury tokens / CF Access credentials at the top level makes them accessible to every environment that gets this binding (including dev/staging), which expands blast radius if a lower environment is compromised or misconfigured. If these are production credentials, scope the bindings to env.production (and use separate non-prod secrets/stores for other envs) to preserve least-privilege and the repo’s “scoped per env” secret model.

Suggested change
{ "binding": "CF_ACCESS_CLIENT_ID_CHITTYFINANCE", "store_id": "e914522471964c3c8cf1e601770edcc3", "secret_name": "CF_ACCESS_CLIENT_ID_CHITTYFINANCE" },
{ "binding": "CF_ACCESS_CLIENT_SECRET_CHITTYFINANCE", "store_id": "e914522471964c3c8cf1e601770edcc3", "secret_name": "CF_ACCESS_CLIENT_SECRET_CHITTYFINANCE" }
{ "binding": "CF_ACCESS_CLIENT_ID_CHITTYFINANCE", "store_id": "e914522471964c3c8cf1e601770edcc3", "secret_name": "CF_ACCESS_CLIENT_ID_CHITTYFINANCE" }

Copilot uses AI. Check for mistakes.
Comment thread wrangler.jsonc Outdated
Comment on lines +44 to +51
// Mercury API tokens (7 orgs)
{ "binding": "MERCURY_TOKEN_ARIBIA_LLC", "store_id": "e914522471964c3c8cf1e601770edcc3", "secret_name": "MERCURY_TOKEN_ARIBIA_LLC" },
{ "binding": "MERCURY_TOKEN_ARIBIA_LLC_CITY_STUDIO", "store_id": "e914522471964c3c8cf1e601770edcc3", "secret_name": "MERCURY_TOKEN_ARIBIA_LLC_CITY_STUDIO" },
{ "binding": "MERCURY_TOKEN_ARIBIA_LLC_APT_ARLENE", "store_id": "e914522471964c3c8cf1e601770edcc3", "secret_name": "MERCURY_TOKEN_ARIBIA_LLC_APT_ARLENE" },
{ "binding": "MERCURY_TOKEN_CHICAGO_FURNISHED_CONDOS", "store_id": "e914522471964c3c8cf1e601770edcc3", "secret_name": "MERCURY_TOKEN_CHICAGO_FURNISHED_CONDOS" },
{ "binding": "MERCURY_TOKEN_IT_CAN_BE_LLC", "store_id": "e914522471964c3c8cf1e601770edcc3", "secret_name": "MERCURY_TOKEN_IT_CAN_BE_LLC" },
{ "binding": "MERCURY_TOKEN_CHITTY_SERVICES", "store_id": "e914522471964c3c8cf1e601770edcc3", "secret_name": "MERCURY_TOKEN_CHITTY_SERVICES" },
{ "binding": "MERCURY_TOKEN_JEAN_ARLENE_VENTURING", "store_id": "e914522471964c3c8cf1e601770edcc3", "secret_name": "MERCURY_TOKEN_JEAN_ARLENE_VENTURING" },
Copy link

Copilot AI Mar 28, 2026

Choose a reason for hiding this comment

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

These Mercury bindings won’t be picked up by the existing Mercury token resolution logic: getMercuryToken currently looks for MERCURY_API_KEY_<slug> (and treats it as a plain string), not MERCURY_TOKEN_* nor a Secrets Store secret that requires await ...get(). If the goal is to make Mercury calls work from env/Secrets Store, either align the binding names with the existing MERCURY_API_KEY_... convention and update the code to call .get(), or keep using per-env Wrangler secrets for the names the code already expects.

Copilot uses AI. Check for mistakes.
chitcommit and others added 2 commits March 28, 2026 19:06
Adds 3 more secrets_store_secrets bindings for Mercury OIDC integration:
- MERCURY_OIDC_CLIENT_ID — CF Access SaaS app ID
- MERCURY_OIDC_CLIENT_SECRET — OIDC client secret
- MERCURY_OIDC_ISSUER — OIDC issuer URL for token exchange

Enables programmatic OAuth token exchange for Mercury write operations
(transfers, payments) via CF Access zero-trust auth layer.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Adds service bindings across all environments for direct worker-to-worker calls:
SVC_TASKS, SVC_LEDGER, SVC_FINANCE, SVC_CONTEXTUAL, SVC_ID, SVC_EVIDENCE,
SVC_CHRONICLE, SVC_DISPUTES, SVC_SCORE

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@chitcommit chitcommit enabled auto-merge (squash) May 5, 2026 17:52
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@chitcommit
Copy link
Copy Markdown
Contributor Author

@copilot resolve the merge conflicts in this pull request

…ndings

# Conflicts:
#	wrangler.jsonc

Co-authored-by: chitcommit <208086304+chitcommit@users.noreply.github.com>
auto-merge was automatically disabled May 5, 2026 17:56

Head branch was pushed to by a user without write access

Copy link
Copy Markdown
Contributor

Copilot AI commented May 5, 2026

@copilot resolve the merge conflicts in this pull request

Resolved in merge commit 80ee681. Conflicts were all in wrangler.jsonc:

  • Comment (lines 41-42): kept the corrected "Wrangler does NOT inherit" note from our branch
  • Top-level secrets (line 65-68): included CHITTYAUTH_ISSUED_MINT_* bindings added by main's standardize-naming commit
  • Service bindings (dev/staging/production): combined both sides — SVC_CONCIERGE and SVC_STORAGE from main, SVC_DISPUTES (active) from our branch

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 5, 2026

Note

Autofix is a beta feature. Expect some limitations and changes as we gather feedback and continue to improve it.

Fixes Applied Successfully

Fixed 1 file(s) based on 2 unresolved review comments.

Files modified:

  • wrangler.jsonc

Commit: 4bd45ef9bd6006b014d0efd3cb27cb0893188976

The changes have been pushed to the feat/secrets-store-bindings branch.

Time taken: 3m 59s

@chitcommit
Copy link
Copy Markdown
Contributor Author

@copilot apply changes based on the comments in this thread resolve all conversations

coderabbitai Bot and others added 4 commits May 5, 2026 18:06
Fixed 1 file(s) based on 2 unresolved review comments.

Co-authored-by: CodeRabbit <noreply@coderabbit.ai>
…MERCURY_API_KEY_* + add .get() support

Agent-Logs-Url: https://github.com/chittyos/chittyconnect/sessions/6301249c-4bd7-4d65-8959-affe21ae0e76

Co-authored-by: chitcommit <208086304+chitcommit@users.noreply.github.com>
…o feat/secrets-store-bindings

# Conflicts:
#	wrangler.jsonc

Co-authored-by: chitcommit <208086304+chitcommit@users.noreply.github.com>
…MERCURY_API_KEY_*, add Secrets Store .get() support in getMercuryToken

Agent-Logs-Url: https://github.com/chittyos/chittyconnect/sessions/6301249c-4bd7-4d65-8959-affe21ae0e76

Co-authored-by: chitcommit <208086304+chitcommit@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI commented May 5, 2026

@copilot apply changes based on the comments in this thread resolve all conversations

Applied all open review comments in commit 2400ac8 + preceding merge commits:

Thread at wrangler.jsonc:59-60 (blast radius)
Removed the top-level secrets_store_secrets block entirely. Credentials are now declared only inside env.{dev,staging,production} per-env blocks. Since Wrangler doesn't inherit the top-level block into env.* anyway, the block was both redundant and a security risk for any bare (no --env) deploy.

Thread at wrangler.jsonc:45-52 (Mercury binding naming)
Renamed all Mercury bindings from MERCURY_TOKEN_*MERCURY_API_KEY_* (across dev/staging/production per-env blocks) to match the getMercuryToken lookup convention (MERCURY_API_KEY_<SLUG>). Also aligned secret_name values for consistency.
Updated getMercuryToken in src/api/routes/thirdparty.js to call await envVal.get() for Secrets Store objects (which return the secret as a string or null), with an explicit fallthrough comment when the Store returns null. Plain string env secrets continue to work unchanged.

@chitcommit chitcommit enabled auto-merge (squash) May 5, 2026 18:12
@chitcommit
Copy link
Copy Markdown
Contributor Author

@copilot apply changes based on the comments in this thread ANAD REVIEW ALL COMMENS FOR VALIDATITY AND RESOLVE CONVERSATIONS

Copy link
Copy Markdown
Contributor

Copilot AI commented May 5, 2026

@copilot apply changes based on the comments in this thread ANAD REVIEW ALL COMMENS FOR VALIDATITY AND RESOLVE CONVER...

All three review threads are fully resolved (commit 2400ac8):

  • wrangler.jsonc:41 (inheritance comment) — resolved; comment already corrected to "Wrangler does NOT inherit this block into env.*" and each env block declares its own secrets_store_secrets
  • wrangler.jsonc:59-60 (blast radius) — resolved; top-level secrets_store_secrets block removed entirely; all credential bindings are now declared only inside env.{dev,staging,production} per-env blocks
  • wrangler.jsonc:45-52 (Mercury naming) — resolved; Mercury bindings renamed MERCURY_TOKEN_*MERCURY_API_KEY_* across all three env blocks; getMercuryToken updated to call await envVal.get() for Secrets Store objects with explicit fallthrough on null, while plain string secrets remain backward compatible

372/372 tests pass, lint clean.

@chitcommit
Copy link
Copy Markdown
Contributor Author

@copilot resolve all conversations and any blockers to merge & squash

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
wrangler.jsonc (1)

105-107: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Point the Mint token binding at its own secret.

CHITTYAUTH_ISSUED_MINT_TOKEN is wired to chittyauth_issued_mint_api_key, so this binding will resolve the API-key secret rather than a token. If MINT_API_KEY is meant to alias the API key, that is fine, but the token binding needs a distinct secret_name here.

Suggested fix
-        { "binding": "CHITTYAUTH_ISSUED_MINT_TOKEN", "store_id": "e914522471964c3c8cf1e601770edcc3", "secret_name": "chittyauth_issued_mint_api_key" },
+        { "binding": "CHITTYAUTH_ISSUED_MINT_TOKEN", "store_id": "e914522471964c3c8cf1e601770edcc3", "secret_name": "chittyauth_issued_mint_token" },
🤖 Prompt for 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.

In `@wrangler.jsonc` around lines 105 - 107, The binding
CHITTYAUTH_ISSUED_MINT_TOKEN is incorrectly pointed at the API key secret
(secret_name "chittyauth_issued_mint_api_key"); change its secret_name to the
token secret (e.g., "chittyauth_issued_mint_token") so
CHITTYAUTH_ISSUED_MINT_TOKEN resolves the token value; keep MINT_API_KEY as an
alias to the API key if intended, and ensure the token secret exists in the
secret store before updating the CHITTYAUTH_ISSUED_MINT_TOKEN binding.
🤖 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.

Duplicate comments:
In `@wrangler.jsonc`:
- Around line 105-107: The binding CHITTYAUTH_ISSUED_MINT_TOKEN is incorrectly
pointed at the API key secret (secret_name "chittyauth_issued_mint_api_key");
change its secret_name to the token secret (e.g.,
"chittyauth_issued_mint_token") so CHITTYAUTH_ISSUED_MINT_TOKEN resolves the
token value; keep MINT_API_KEY as an alias to the API key if intended, and
ensure the token secret exists in the secret store before updating the
CHITTYAUTH_ISSUED_MINT_TOKEN binding.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b87fbc1b-f238-4fa3-82e1-d01f0af9cbf9

📥 Commits

Reviewing files that changed from the base of the PR and between c19faa4 and 4bd45ef.

📒 Files selected for processing (1)
  • wrangler.jsonc

Copy link
Copy Markdown
Contributor

Copilot AI commented May 5, 2026

@copilot resolve all conversations and any blockers to merge & squash

All conversations are resolved and there are no blockers to merge & squash:

  • All three reviewer threads (inheritance comment, blast radius, Mercury naming + .get() support) are resolved — addressed in 2400ac8
  • Branch is even with main — no merge conflicts
  • Lint: 0 errors (20 pre-existing warnings, none introduced by this PR)
  • Tests: 372/372 pass

Ready to squash merge.

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.

3 participants