Skip to content

fix(rbac): restore channel API key permissions#2349

Open
riderx wants to merge 2 commits into
mainfrom
codex/fix-channel-write-permission
Open

fix(rbac): restore channel API key permissions#2349
riderx wants to merge 2 commits into
mainfrom
codex/fix-channel-write-permission

Conversation

@riderx
Copy link
Copy Markdown
Member

@riderx riderx commented May 28, 2026

Summary (AI generated)

  • Restores channel creation for write/developer API keys by granting app.create_channel to app_developer.
  • Replaces channel insert/update/delete RLS with exact RBAC permission checks.
  • Updates CLI channel add/set/delete prechecks to use exact RBAC permissions instead of coarse legacy admin checks.
  • Tightens public channel endpoints so service-role writes are gated by exact channel permissions first.

Motivation (AI generated)

A migrated API key could be reported as write by the legacy CLI permission helper even when it had channel/admin RBAC permissions. That made channel create/delete/self-set flows fail before the request reached the real RBAC/RLS checks.

Business Impact (AI generated)

This restores customer channel management for migrated API keys without making write keys destructive: developer/write keys can create and update allowed channel settings, while channel deletion still requires channel.delete. It also keeps older CLI compatibility through the existing RPC shape.

Test Plan (AI generated)

  • bun run supabase:db:reset
  • SQL sanity check: one channels RLS policy per operation and app_developer has app.create_channel
  • bun run cli:lint
  • bun run lint:backend
  • bun run cli:typecheck
  • bun run typecheck:backend
  • bun run typecheck:frontend
  • bun run lint
  • bun run cli:build
  • bun run supabase:with-env -- bunx vitest run tests/channel-post.unit.test.ts tests/rbac-permissions.test.ts tests/hashed-apikey-rls.test.ts
  • bun run supabase:with-env -- bunx vitest run tests/cli-channel.test.ts tests/cli-hashed-apikey.test.ts tests/channel.test.ts

Generated with AI

@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.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 28, 2026

Warning

Review limit reached

@riderx, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 23 minutes and 37 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, 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 include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 067109dc-dbd8-4df3-9ad2-f98ac96aaf33

📥 Commits

Reviewing files that changed from the base of the PR and between 4fec358 and 703d485.

📒 Files selected for processing (42)
  • RBAC_SYSTEM.md
  • cli/src/types/supabase.types.ts
  • read_replicate/schema_replicate.sql
  • src/types/supabase.types.ts
  • supabase/functions/_backend/public/channel/delete.ts
  • supabase/functions/_backend/public/channel/post.ts
  • supabase/functions/_backend/utils/hono_middleware.ts
  • supabase/functions/_backend/utils/rbac.ts
  • supabase/functions/_backend/utils/supabase.types.ts
  • supabase/migrations/20260528122747_fix_channel_rbac_permissions.sql
  • supabase/seed.sql
  • supabase/tests/26_test_rls_policies.sql
  • supabase/tests/33_test_rbac_phase1.sql
  • supabase/tests/37_test_check_min_rights_2fa_enforcement.sql
  • supabase/tests/39_test_reject_access_due_to_2fa.sql
  • supabase/tests/40_test_password_policy_enforcement.sql
  • supabase/tests/41_test_reject_access_due_to_2fa_for_app.sql
  • supabase/tests/42_test_reject_access_due_to_2fa_for_org.sql
  • supabase/tests/45_test_org_create_app_permission.sql
  • supabase/tests/45_test_shared_public_images.sql
  • supabase/tests/46_test_rbac_legacy_apikey_effective_user.sql
  • supabase/tests/47_test_get_org_apikeys_permissions.sql
  • supabase/tests/48_test_rbac_apikey_user_mismatch.sql
  • supabase/tests/49_test_apikey_oracle_rpc_permissions.sql
  • supabase/tests/54_test_usage_credit_rls_performance.sql
  • supabase/tests/56_test_apikey_v2_scope_and_rls.sql
  • tests/apikey-atomic-bindings.test.ts
  • tests/app.test.ts
  • tests/audit-logs.test.ts
  • tests/bundle.test.ts
  • tests/channel-post.unit.test.ts
  • tests/enforce-encrypted-bundles.test.ts
  • tests/hashed-apikey-rls.test.ts
  • tests/organization-api.test.ts
  • tests/organization-put-stripe-sync.unit.test.ts
  • tests/organization-store-delete.unit.test.ts
  • tests/password-policy.test.ts
  • tests/plan-check-appid-passthrough.test.ts
  • tests/private-error-cases.test.ts
  • tests/private-invite-existing-user-to-org.test.ts
  • tests/private-role-bindings.test.ts
  • tests/rbac-permissions.test.ts

Comment @coderabbitai help to get the list of available commands and usage tips.

@codspeed-hq
Copy link
Copy Markdown
Contributor

codspeed-hq Bot commented May 28, 2026

Merging this PR will not alter performance

✅ 43 untouched benchmarks
⏩ 2 skipped benchmarks1


Comparing codex/fix-channel-write-permission (703d485) with main (4fec358)

Open in CodSpeed

Footnotes

  1. 2 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@riderx riderx force-pushed the codex/fix-channel-write-permission branch from 878bd7e to 5f10e30 Compare May 28, 2026 12:47
@riderx riderx force-pushed the codex/fix-channel-write-permission branch from 5f10e30 to a37b9f9 Compare May 28, 2026 12:56
@riderx riderx force-pushed the codex/fix-channel-write-permission branch from a37b9f9 to 7939157 Compare May 28, 2026 13:04
@riderx riderx force-pushed the codex/fix-channel-write-permission branch from 7939157 to 4ae61b2 Compare May 28, 2026 13:12
@riderx riderx force-pushed the codex/fix-channel-write-permission branch from 4ae61b2 to d1cbfe6 Compare May 28, 2026 13:21
@riderx riderx force-pushed the codex/fix-channel-write-permission branch from 9f4e13d to c96d4e4 Compare May 28, 2026 15:38
@riderx riderx force-pushed the codex/fix-channel-write-permission branch from c96d4e4 to 8c03ee7 Compare May 28, 2026 15:46
@riderx riderx force-pushed the codex/fix-channel-write-permission branch from 8c03ee7 to 5788b5c Compare May 28, 2026 16:00
@riderx riderx force-pushed the codex/fix-channel-write-permission branch from 5788b5c to 703d485 Compare May 28, 2026 16:03
@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown

@42Clownfish 42Clownfish left a comment

Choose a reason for hiding this comment

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

Reviewed the channel RBAC/API-key compatibility path. No blocker from my pass.

What I checked:

  • post.ts now separates create vs update: new channels require app.create_channel, existing channels require channel.update_settings, and version changes require channel.promote_bundle after resolving the target version.
  • The migration mirrors that split in RLS for insert/update/delete, so the old CLI compatibility helpers only get callers to the endpoint/RLS gate; they do not become the final authorization decision.
  • The regression coverage hits the important security cases: app developer channel creation, promote denial on direct channel version changes, hashed API-key scope, and forged app/channel binding rejection.
  • Current checks are green, including backend lint/typecheck, SQL/RLS tests, CLI tests, CodeQL, Sonar, and Socket.

One non-blocking edge to keep an eye on: post.ts uses the caller's API-key client to discover existingChannel. If a channel exists but is not visible to that key, the code can classify the request as a create attempt and then rely on the upsert/RLS conflict to reject it. That still looks protected, but it may produce a noisier database error instead of the cleaner cannot_access_app response. If that matters for CLI UX, a service-role existence lookup followed by the same explicit permission checks would make the error path deterministic.

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.

2 participants