fix(cli): validate app-scoped plans with app context - #2825
Conversation
📝 WalkthroughWalkthroughThe CLI replaces API-key-based plan checks with organization and app-scoped validation. Bundle and channel callers use revised signatures. New tests verify RPC results and errors through the aggregate test script. ChangesPlan validation
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant CLIOperation
participant PlanValidation
participant Supabase
CLIOperation->>PlanValidation: validate organization/app action
PlanValidation->>Supabase: call is_allowed_action_org_action
Supabase-->>PlanValidation: return approval or error
PlanValidation-->>CLIOperation: return boolean or validation error
Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Comment |
Merging this PR will not alter performance
Comparing Footnotes
|
|
@coderabbitai review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
2 issues found across 6 files
Confidence score: 4/5
- In
cli/src/utils.ts(checkPlanValid/isAllowedActionOrg), the org-scoped path still ignores RPCerrorand returns!!data, which can silently deny valid org-scoped legacy users and create inconsistent behavior versus the new app-aware helper — make the org branch check and surface RPC errors the same way. - In
cli/src/utils.ts, the new helper duplicates theis_allowed_action_org_actioncall pattern already incheckPlanValidUpload(including the cast and error handling), which raises drift risk when one path is updated and the other is not — consolidate to a shared helper or parameterizeactionsto keep behavior aligned.
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="cli/src/utils.ts">
<violation number="1" location="cli/src/utils.ts:855">
P3: This new helper duplicates the `is_allowed_action_org_action` call shape, `as never` cast, and `if (error) throw` handling already present in `checkPlanValidUpload` just below it. The two differ only in the `actions` list. A shared helper parameterized by the action list would keep the RPC contract in one place and make the different action sets (all metered vs storage-only) easier to compare.</violation>
<violation number="2" location="cli/src/utils.ts:856">
P2: The new app-aware helper surfaces RPC errors, but the org-scope branch it sits next to in `checkPlanValid` still swallows them. `isAllowedActionOrg` returns `!!data` without checking `error`, so an org-scoped/legacy key hitting a transient or RBAC error gets told to "upgrade your plan" — the same misleading billing error this change is meant to eliminate. Consider giving the org-scope path the same error propagation so both branches behave consistently, or document why org-scope is intentionally lenient.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@cli/src/utils.ts`:
- Around line 850-858: Update isAllowedPlanActions to fall back to the existing
organization-level validation when the app-aware is_allowed_action_org_action
RPC is unavailable on the server, while preserving app-aware behavior when
supported. Detect only the missing-function/unsupported-RPC case for fallback,
and propagate all other RPC errors unchanged.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: cd8f121b-7154-4183-adb3-e1eec3cd244f
📒 Files selected for processing (2)
cli/src/utils.tscli/test/test-plan-validation.mjs
🔗 Linked repositories identified
CodeRabbit considers these linked repositories for cross-repo context during reviews:
Cap-go/capacitor-updater(manual)
There was a problem hiding this comment.
1 issue found across 6 files
Confidence score: 2/5
- In
cli/src/channel/set.ts, the app-aware plan RPC now requiresapp.read, so channel-scoped keys with onlychannel_admincan no longer update channels; this is a concrete least-privilege regression that can block legitimate admin workflows — adjust the plan gate to accept channel-level permissions (or use a channel-scoped check) for this path.
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="cli/src/channel/set.ts">
<violation number="1" location="cli/src/channel/set.ts:242">
P1: Channel-scoped API keys with `channel_admin` access can no longer update a channel: this app-aware plan RPC requires `app.read`, which that least-privilege role intentionally does not grant. The plan gate needs a permission context that accepts the already-authorized channel scope (or the RPC/helper must be adjusted) without broadening the key to app-wide read access.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
|



Summary (AI generated)
is_allowed_action_org_actionRPC when an app ID is available.Motivation (AI generated)
App-scoped API keys can have sufficient permissions for an app without having organization-level
org.read. The legacyis_allowed_action(apikey, appid)path eventually evaluated the plan through an organization-only permission check, returnedfalse, and caused commands such aschannel setto incorrectly reportYou need to upgrade your planfor healthy paid organizations.Business Impact (AI generated)
This restores channel and bundle operations for customers using least-privilege app-scoped API keys, prevents healthy paid accounts from being blocked by a misleading billing error, and keeps plan enforcement intact for all metered resources.
Test Plan (AI generated)
bun run cli:checkgit diff --checkis clean.