Add reject_access_due_to_2fa_for_org function#1333
Conversation
… checks Adds a new function for checking 2FA enforcement at the organization level, respecting org-limited API keys. Includes 14 comprehensive tests covering JWT auth, API key auth, org-limited API key constraints, and edge cases. 🤖 Generated with Claude Code Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
📝 WalkthroughWalkthroughAdds a SECURITY DEFINER SQL function Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant DB_Function as reject_access_due_to_2fa_for_org()
participant IdentityFn as public.get_identity_org_allowed()
participant Orgs as public.orgs
Client->>DB_Function: call(org_id)
DB_Function->>IdentityFn: get_identity(org_id, key_modes...)
IdentityFn-->>DB_Function: identity or null
alt no identity
DB_Function-->>Client: RETURN true /* reject access */
else identity found
DB_Function->>Orgs: SELECT enforcing_2fa FROM orgs WHERE id=org_id
Orgs-->>DB_Function: enforcing_2fa value or null
alt org not found or enforcing_2fa = false
DB_Function-->>Client: RETURN false /* allow */
else enforcing_2fa = true
alt identity.has_2fa_enabled = true
DB_Function-->>Client: RETURN false /* allow */
else
DB_Function-->>Client: RETURN true /* reject */
end
end
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
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. Comment |
- Clarify why get_identity_org_allowed is used instead of get_identity - Document intentional behavior difference when org doesn't exist - Ensure clean request.headers state before anonymous user test 🤖 Generated with Claude Code Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
🤖 Generated with Claude Code Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
* feat: add reject_access_due_to_2fa_for_org function for org-level 2FA checks Adds a new function for checking 2FA enforcement at the organization level, respecting org-limited API keys. Includes 14 comprehensive tests covering JWT auth, API key auth, org-limited API key constraints, and edge cases. 🤖 Generated with Claude Code Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com> * fix: improve comments and ensure clean test state - Clarify why get_identity_org_allowed is used instead of get_identity - Document intentional behavior difference when org doesn't exist - Ensure clean request.headers state before anonymous user test 🤖 Generated with Claude Code Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: return false for non-existent org (no 2FA enforcement applies) 🤖 Generated with Claude Code Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Haiku 4.5 <noreply@anthropic.com> Co-authored-by: Martin DONADIEU <martindonadieu@gmail.com>



Summary
Adds a new database function
reject_access_due_to_2fa_for_orgfor checking 2FA enforcement at the organization level. This function respects org-limited API keys and properly validates that API keys are allowed to access the specific organization being queried.Test plan
supabase test dbChecklist
Motivation
It turns out that even with the best plan in the world (#1291), 3 PRs that do nothing but add DB code (#1311, #1310, #1300) getting all the functions I need for the CLI to work in advance is not easy. I forgot to do public
reject_access_due_to_2fa_for_org, so here we go. 4th PR for the 2FA enforcementBusiness impact
None - another PR in the PRs required for 2FA enforcement to work
Summary by CodeRabbit
New Features
Tests
✏️ Tip: You can customize this high-level summary in your review settings.
Note
Adds an org-scoped 2FA access check usable by CLI/frontend.
public.reject_access_due_to_2fa_for_org(org_id uuid)(SECURITY DEFINER) returnstrueto reject orfalseto allowpublic.get_identity_org_allowed(...)to enforce org-limited API key scopepublic.has_2fa_enabled(user_id)authenticated,anon, andservice_roleWritten by Cursor Bugbot for commit 6a12b49. This will update automatically on new commits. Configure here.