Skip to content

fix(api): keep anon CLI app-list helper grants#1974

Merged
riderx merged 3 commits intomainfrom
codex/temp-cli-anon-app-list-fix
Apr 28, 2026
Merged

fix(api): keep anon CLI app-list helper grants#1974
riderx merged 3 commits intomainfrom
codex/temp-cli-anon-app-list-fix

Conversation

@riderx
Copy link
Copy Markdown
Member

@riderx riderx commented Apr 27, 2026

Summary (AI generated)

  • add a temporary migration that preserves anonymous execute on the helper functions used by the published CLI app list flow
  • document why the legacy CLI still depends on these helper grants
  • extend the SQL privilege regression test to keep the anon grants covered and to exercise an anonymous API-key apps read

Motivation (AI generated)

The currently published CLI still authenticates through legacy anonymous PostgREST helper calls and then issues a direct GET /rest/v1/apps request with the capgkey header. When these helper grants drift or get tightened, CLI users regress from working API-key auth to opaque Apps not found / auth failures.

Business Impact (AI generated)

This restores short-term CLI reliability for existing customers without forcing an immediate CLI upgrade. It reduces support load around broken API-key workflows and buys time to ship the longer-term CLI-side migration to RBAC-aware wrappers.

Test Plan (AI generated)

  • Run bun run typecheck
  • Run bun scripts/supabase-worktree.ts test db
  • Verify bunx @capgo/cli app list succeeds against a local stack after the legacy anon grants are present

Generated with AI

Summary by CodeRabbit

  • Bug Fixes
    • CLI app list now correctly returns apps for anonymous users using legacy API-key header authentication (temporary backend permission adjustment).
  • Tests
    • Expanded test coverage for the header-based identity flow and validated app query behavior with valid vs. invalid API-key headers.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 27, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d7a3a41e-8846-41b8-86cd-8922d88be075

📥 Commits

Reviewing files that changed from the base of the PR and between 1e74928 and 17c623c.

📒 Files selected for processing (2)
  • supabase/migrations/20260427175506_temporary_cli_apps_list_anon_helper_grants.sql
  • supabase/tests/49_test_apikey_oracle_rpc_permissions.sql
🚧 Files skipped from review as they are similar to previous changes (2)
  • supabase/migrations/20260427175506_temporary_cli_apps_list_anon_helper_grants.sql
  • supabase/tests/49_test_apikey_oracle_rpc_permissions.sql

📝 Walkthrough

Walkthrough

Temporarily grants the anon Postgres role EXECUTE on four public helper functions used by header-based API-key auth/RLS and extends a test to assert those grants and that the legacy CLI app list flow (via capgkey header) returns expected public.apps rows.

Changes

Cohort / File(s) Summary
Migration
supabase/migrations/20260427175506_temporary_cli_apps_list_anon_helper_grants.sql
Adds GRANT EXECUTE for role anon on public.get_apikey_header, public.is_apikey_expired, public.get_identity_org_appid, and public.check_min_rights. Includes comments noting cleanup migration to revoke grants later.
Tests
supabase/tests/49_test_apikey_oracle_rpc_permissions.sql
Expands assertions (plan increased) to check anon has EXECUTE on the four helper functions and that GET /rest/v1/apps via capgkey header yields a visible com.demo.app row with a valid header and hides it with an invalid header.

Sequence Diagram

sequenceDiagram
    participant Client as Anonymous Client
    participant PostgREST as PostgREST
    participant RLS as RLS Evaluator
    participant Helpers as Helper Functions
    participant DB as public.apps

    Client->>PostgREST: GET /rest/v1/apps (capgkey header)
    PostgREST->>RLS: Trigger row-level checks
    RLS->>Helpers: get_apikey_header(capgkey)
    Helpers-->>RLS: api_key
    RLS->>Helpers: is_apikey_expired(api_key)
    Helpers-->>RLS: expiry_status
    RLS->>Helpers: get_identity_org_appid(api_key)
    Helpers-->>RLS: identity/org/appid
    RLS->>Helpers: check_min_rights(identity, appid)
    Helpers-->>RLS: permission_ok
    RLS->>DB: allow SELECT for matching rows
    DB-->>PostgREST: rows
    PostgREST-->>Client: 200 OK + apps
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 I hopped through SQL lines tonight,

granted anon a gentle light,
capgkey hums and helpers cheer,
rows appear, the path is clear.
🥕

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix(api): keep anon CLI app-list helper grants' directly and specifically summarizes the main change: preserving anonymous execute privileges on helper functions for the CLI app-list flow.
Description check ✅ Passed The description includes a comprehensive summary explaining the change, motivation, and business impact. It documents the test plan with completed and pending items, though the required checklist items are mostly unchecked and documentation updates are not explicitly addressed.
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 codex/temp-cli-anon-app-list-fix

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 SQLFluff (4.1.0)
supabase/tests/49_test_apikey_oracle_rpc_permissions.sql

User Error: No dialect was specified. You must configure a dialect or specify one on the command line using --dialect after the command. Available dialects:
ansi, athena, bigquery, clickhouse, databricks, db2, doris, duckdb, exasol, flink, greenplum, hive, impala, mariadb, materialize, mysql, oracle, postgres, redshift, snowflake, soql, sparksql, sqlite, starrocks, teradata, trino, tsql, vertica

supabase/migrations/20260427175506_temporary_cli_apps_list_anon_helper_grants.sql

User Error: No dialect was specified. You must configure a dialect or specify one on the command line using --dialect after the command. Available dialects:
ansi, athena, bigquery, clickhouse, databricks, db2, doris, duckdb, exasol, flink, greenplum, hive, impala, mariadb, materialize, mysql, oracle, postgres, redshift, snowflake, soql, sparksql, sqlite, starrocks, teradata, trino, tsql, vertica


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

@codspeed-hq
Copy link
Copy Markdown
Contributor

codspeed-hq Bot commented Apr 27, 2026

Merging this PR will not alter performance

✅ 28 untouched benchmarks


Comparing codex/temp-cli-anon-app-list-fix (17c623c) with main (730b168)

Open in CodSpeed

@riderx riderx marked this pull request as ready for review April 27, 2026 20:38
@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.

@riderx
Copy link
Copy Markdown
Member Author

riderx commented Apr 27, 2026

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 27, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown
Contributor

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

🧹 Nitpick comments (2)
supabase/migrations/20260427175506_temporary_cli_apps_list_anon_helper_grants.sql (1)

1-8: Add a concrete sunset pointer for this temporary compatibility migration.

The intent is clear, but include a tracking issue/PR reference (or target cleanup migration name) so these grants are reliably removed after CLI migration.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@supabase/migrations/20260427175506_temporary_cli_apps_list_anon_helper_grants.sql`
around lines 1 - 8, Add a concrete sunset pointer to this temporary
compatibility migration by including a tracking reference (e.g., GitHub issue or
PR URL) or the exact name of the follow-up cleanup migration that will remove
these anonymous execute grants for the apps RLS helper functions; update the
migration header/comments in
20260427175506_temporary_cli_apps_list_anon_helper_grants.sql to state that
reference and an expected removal condition (e.g., "remove when PR `#1234` lands"
or "cleanup migration: 20260601_remove_temp_cli_apps_anon_grants"), so reviewers
can reliably find and remove these grants once the CLI migration is complete.
supabase/tests/49_test_apikey_oracle_rpc_permissions.sql (1)

201-210: Add a negative-path public.apps check after setting an invalid capgkey.

You already validate invalid-key behavior for storage.objects; mirroring that for public.apps would harden this regression test.

Proposed test hardening diff
-SELECT plan(19);
+SELECT plan(20);
@@
 DO $$
 BEGIN
     PERFORM set_config('request.headers', '{"capgkey": "invalid-key"}', true);
 END $$;
 
+SELECT
+    is(
+        (
+            SELECT count(*)
+            FROM public.apps
+            WHERE app_id = 'com.demo.app'
+        ),
+        0::bigint,
+        'anon with invalid capgkey cannot read apps through helper identity'
+    );
+
 SELECT
     is(
         (
             SELECT count(*)
             FROM storage.objects
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@supabase/tests/49_test_apikey_oracle_rpc_permissions.sql` around lines 201 -
210, Add a negative-path assertion that mirrors the invalid-key check for
storage.objects: after you set an invalid capgkey, run the same SELECT count(*)
FROM public.apps WHERE app_id = 'com.demo.app' and assert it does NOT return 1
(e.g. expect 0::bigint or a permission-denied outcome). Update the test near the
existing is(..., 1::bigint, 'anon API-key apps query still works through RLS
helper identity') block to include a new is(...) assertion for public.apps when
capgkey is invalid (use the same message pattern like 'anon invalid API-key apps
query blocked by RLS helper identity') so the test verifies both positive and
negative behaviors for public.apps.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@supabase/migrations/20260427175506_temporary_cli_apps_list_anon_helper_grants.sql`:
- Around line 1-8: Add a concrete sunset pointer to this temporary compatibility
migration by including a tracking reference (e.g., GitHub issue or PR URL) or
the exact name of the follow-up cleanup migration that will remove these
anonymous execute grants for the apps RLS helper functions; update the migration
header/comments in 20260427175506_temporary_cli_apps_list_anon_helper_grants.sql
to state that reference and an expected removal condition (e.g., "remove when PR
`#1234` lands" or "cleanup migration: 20260601_remove_temp_cli_apps_anon_grants"),
so reviewers can reliably find and remove these grants once the CLI migration is
complete.

In `@supabase/tests/49_test_apikey_oracle_rpc_permissions.sql`:
- Around line 201-210: Add a negative-path assertion that mirrors the
invalid-key check for storage.objects: after you set an invalid capgkey, run the
same SELECT count(*) FROM public.apps WHERE app_id = 'com.demo.app' and assert
it does NOT return 1 (e.g. expect 0::bigint or a permission-denied outcome).
Update the test near the existing is(..., 1::bigint, 'anon API-key apps query
still works through RLS helper identity') block to include a new is(...)
assertion for public.apps when capgkey is invalid (use the same message pattern
like 'anon invalid API-key apps query blocked by RLS helper identity') so the
test verifies both positive and negative behaviors for public.apps.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 137bea97-58b2-40f2-a5d1-3e51b4200452

📥 Commits

Reviewing files that changed from the base of the PR and between 241ba50 and a6eb0e7.

📒 Files selected for processing (2)
  • supabase/migrations/20260427175506_temporary_cli_apps_list_anon_helper_grants.sql
  • supabase/tests/49_test_apikey_oracle_rpc_permissions.sql

@sonarqubecloud
Copy link
Copy Markdown

@riderx riderx merged commit 5778064 into main Apr 28, 2026
16 checks passed
@riderx riderx deleted the codex/temp-cli-anon-app-list-fix branch April 28, 2026 14:57
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.

1 participant