feat: account-level api keys - #6991
Open
kaposke wants to merge 2 commits into
Open
Conversation
Decouple credential authentication from resource authorization so account and future multi-environment keys can be checked against explicit targets. Co-authored-by: Cursor <cursoragent@cursor.com>
Exercise an unscoped environment route so account-only key denial depends directly on the ownership middleware. Co-authored-by: Cursor <cursoragent@cursor.com>
kaposke
changed the base branch from
master
to
gui/NAN-6468/refac-make-environment-optional-on-request-locals
August 1, 2026 00:20
Contributor
There was a problem hiding this comment.
1 issue found across 143 files
Confidence score: 3/5
- In
packages/database/lib/migrations/20260731170000_make_customer_key_environment_cleanup_relation_aware.cjs, concurrent deletion of two environments that share a key can race and leave an environment-only API key orphaned with no relations, creating a data-integrity cleanup gap—lock the affectedcustomer_keysrows before relation removal so the second trigger run re-evaluates against current state.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="packages/database/lib/migrations/20260731170000_make_customer_key_environment_cleanup_relation_aware.cjs">
<violation number="1" location="packages/database/lib/migrations/20260731170000_make_customer_key_environment_cleanup_relation_aware.cjs:16">
P2: Concurrent deletion of two environments sharing a key can leave an environment-only API key behind with no relations. Lock affected `customer_keys` rows before removing relations so the second trigger re-evaluates after the first commits.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| DECLARE | ||
| affected_key_ids INTEGER[]; | ||
| BEGIN | ||
| SELECT COALESCE(array_agg(customer_key_id), ARRAY[]::INTEGER[]) |
Contributor
There was a problem hiding this comment.
P2: Concurrent deletion of two environments sharing a key can leave an environment-only API key behind with no relations. Lock affected customer_keys rows before removing relations so the second trigger re-evaluates after the first commits.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/database/lib/migrations/20260731170000_make_customer_key_environment_cleanup_relation_aware.cjs, line 16:
<comment>Concurrent deletion of two environments sharing a key can leave an environment-only API key behind with no relations. Lock affected `customer_keys` rows before removing relations so the second trigger re-evaluates after the first commits.</comment>
<file context>
@@ -0,0 +1,45 @@
+ DECLARE
+ affected_key_ids INTEGER[];
+ BEGIN
+ SELECT COALESCE(array_agg(customer_key_id), ARRAY[]::INTEGER[])
+ INTO affected_key_ids
+ FROM customer_keys_relations
</file context>
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.
Summary
Adds the authentication and authorization foundations for account-level API keys.
Approach
Previously, customer-key authentication joined customer_keys_relations, required an environment relation, and selected one environment during credential lookup. Scope middleware then assumed that environment ownership had already been validated.
Now, authentication resolves the key into a principal containing its account, scopes, and valid environment bindings. Authorization separately checks both the required scope and ownership of the requested target. An environment is inferred only when exactly one valid relation exists; account-only keys require no relation.
This also adds account scopes, a relation-free account-key creation primitive, and relation-aware cleanup when environments are deleted.