feat(byok): add organization-wide key inheritance - #6834
feat(byok): add organization-wide key inheritance#6834BillLeoutsakosvl346 wants to merge 5 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
PR SummaryHigh Risk Overview Runtime resolution in The BYOK settings UI adds a workspace vs organization scope ( Organization mutations require session principals, org admin/owner membership on the target org, and entitlement rules aligned with list/save/delete operations; audits and PostHog events cover org scope. Reviewed by Cursor Bugbot for commit 9f8ff6e. Bugbot is set up for automated code reviews on this repo. Configure here. |
|
| GitGuardian id | GitGuardian status | Secret | Commit | Filename | |
|---|---|---|---|---|---|
| 36334842 | Triggered | Generic High Entropy Secret | 24859cb | apps/sim/lib/api-key/byok.test.ts | View secret |
| 36334841 | Triggered | Generic High Entropy Secret | 24859cb | apps/sim/lib/api-key/byok.test.ts | View secret |
| 36334842 | Triggered | Generic High Entropy Secret | 24859cb | apps/sim/lib/api-key/byok.test.ts | View secret |
| 36334842 | Triggered | Generic High Entropy Secret | 24859cb | apps/sim/lib/api-key/byok.test.ts | View secret |
| 36334842 | Triggered | Generic High Entropy Secret | 24859cb | apps/sim/lib/api-key/byok.test.ts | View secret |
🛠 Guidelines to remediate hardcoded secrets
- Understand the implications of revoking this secret by investigating where it is used in your code.
- Replace and store your secrets safely. Learn here the best practices.
- Revoke and rotate these secrets.
- If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.
To avoid such incidents in the future consider
- following these best practices for managing and storing secrets including API keys and other credentials
- install secret detection on pre-commit to catch secret before it leaves your machine and ease remediation.
🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.
Greptile SummaryThe PR adds encrypted organization-owned BYOK pools, workspace-first credential inheritance, Enterprise entitlement enforcement, and organization-admin management controls.
Confidence Score: 5/5The PR appears safe to merge, with no concrete blocking or independently actionable non-blocking defects identified. Workspace-first credential selection, organization authorization, Enterprise gating, downgrade cleanup, metadata isolation, and persistence changes form a consistent implementation with matching contracts and tests.
|
| Filename | Overview |
|---|---|
| apps/sim/lib/api-key/byok.ts | Implements workspace-first resolution, organization inheritance, entitlement gating, rotation, and decrypt-failure handling without an accepted correctness issue. |
| apps/sim/lib/api-key/application/organization-byok-keys.ts | Adds admin-authorized organization key listing, creation, update, deletion, auditing, capacity enforcement, and inherited-status projection. |
| apps/sim/app/workspace/[workspaceId]/settings/components/byok/byok.tsx | Adds workspace/organization scope selection, inherited badges, entitlement-aware capabilities, and scope-specific mutations. |
| apps/sim/lib/api-key/byok-entitlement.ts | Centralizes hosted Enterprise entitlement checks for organization key writes and runtime inheritance. |
| apps/sim/lib/api/contracts/byok-keys.ts | Adds validated organization-key and inherited-status route contracts while preserving existing workspace contracts. |
| packages/db/schema.ts | Defines encrypted organization BYOK storage with organization and creator foreign keys plus provider lookup indexing. |
| packages/db/migrations/0292_free_multiple_man.sql | Adds the organization_byok_keys table and matching foreign keys and index consistently with the schema. |
| apps/sim/hooks/queries/byok-keys.ts | Adds organization and inherited-status queries with targeted cache invalidation after mutations. |
Sequence Diagram
sequenceDiagram
participant Exec as Workspace execution
participant Resolver as BYOK resolver
participant DB as PostgreSQL
participant Billing as Enterprise entitlement
participant Provider as Provider request
Exec->>Resolver: Resolve provider key(workspaceId, providerId)
Resolver->>DB: Read workspace provider pool
alt Workspace pool exists
DB-->>Resolver: Workspace ciphertexts
Resolver->>Resolver: Rotate and decrypt workspace pool
else No workspace pool
Resolver->>DB: Read workspace organization and org pool
DB-->>Resolver: Organization ciphertexts
Resolver->>Billing: Check current Enterprise entitlement
alt Entitled
Resolver->>Resolver: Rotate and decrypt organization pool
else Not entitled
Resolver-->>Exec: No BYOK key
end
end
Resolver-->>Exec: Effective key or null
Exec->>Provider: Request using BYOK or existing fallback
Reviews (1): Last reviewed commit: "feat(byok): add organization scope to BY..." | Re-trigger Greptile
d3c82b7 to
fbee11d
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit fbee11d. Configure here.
349fa0b to
9f8ff6e
Compare



Summary
Organization keys intentionally apply to executions in all current and future organization workspaces unless a workspace defines its own key for that provider. Existing provider fallback behavior remains unchanged when neither BYOK scope supplies a key.
Type of Change
Testing
Reviewers should focus on the workspace-first resolver boundary, organization authorization and downgrade behavior, and the intentionally organization-wide credential blast radius.
Checklist
Screenshots/Videos
Manual UI validation completed locally for both BYOK scopes, inherited badges, downgrade controls, and inherited-status failure handling.