Skip to content

refactor(api): require permission key in create and update requests - #1885

Open
AmanGIT07 wants to merge 3 commits into
mainfrom
refactor/drop-deprecated-request-fallbacks
Open

refactor(api): require permission key in create and update requests#1885
AmanGIT07 wants to merge 3 commits into
mainfrom
refactor/drop-deprecated-request-fallbacks

Conversation

@AmanGIT07

Copy link
Copy Markdown
Contributor

Summary

CreatePermission and UpdatePermission accept the permission identity only via the key field (service.resource.verb). The deprecated namespace/name request body fields are no longer read; requests sending only those fields now receive InvalidArgument. Part of #1782.

Changes

  • internal/api/v1beta1connect/permission.go: remove the namespace/name fallback; reject a missing or malformed key in both CreatePermission and UpdatePermission
  • cmd/seed/permissions.json + cmd/seed.go: seed data sends key
  • test/e2e/regression/service_registration_test.go: request bodies send key
  • internal/api/v1beta1connect/permission_test.go: request bodies send key; add missing-key and malformed-key cases for both handlers

Test Plan

  • go test ./internal/api/v1beta1connect/ passes
  • make lint passes (0 issues)
  • Full e2e regression suite ran successfully

🤖 Generated with Claude Code

@vercel

vercel Bot commented Aug 14, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
frontier Ready Ready Preview Aug 17, 2026 3:32pm

@coderabbitai

coderabbitai Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

An error occurred during the review process. Please try again later.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 848badab-95b4-4c80-9e15-cd71f0e6fa88

📥 Commits

Reviewing files that changed from the base of the PR and between c28de61 and d3b2cf6.

📒 Files selected for processing (2)
  • internal/bootstrap/schema/schema.go
  • internal/bootstrap/schema/schema_test.go

Included review availability: Your plan includes up to 2 reviews per rolling hour; 1 remains after this review.


📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Permission identifiers now use a single key format for creation, updates, and bootstrap configuration.
  • Bug Fixes

    • Invalid or incomplete permission keys now return clear validation errors instead of being accepted through legacy fields.
    • Permission names and namespaces are validated consistently, including stricter namespace formatting.
    • Permission metadata formatting has been standardized.
  • Tests

    • Added coverage for missing, malformed, and invalid permission keys.
    • Updated regression scenarios to validate the consolidated permission format.

Walkthrough

The permission model now uses a consolidated Key field. Seed data, reporting, API validation, schema rules, unit tests, and regression tests use fully qualified permission keys.

Changes

Permission key migration

Layer / File(s) Summary
Seed data and custom permission reporting
cmd/seed.go, cmd/seed/permissions.json
Seed permissions use combined keys. Custom permission reporting parses namespace and name from each key.
API and schema validation
internal/api/v1beta1connect/errors.go, internal/api/v1beta1connect/permission.go, internal/bootstrap/schema/schema.go
CreatePermission and UpdatePermission validate parsed key components against namespace rules and return InvalidArgument for incomplete or invalid keys.
Request and regression coverage
internal/api/v1beta1connect/permission_test.go, internal/bootstrap/schema/schema_test.go, test/e2e/regression/service_registration_test.go
Tests submit consolidated keys and cover validation, successful operations, and deletion scenarios.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: 🔵 Low · up to d3b2c

The API now requires a valid permission key and rejects deprecated namespace/name-only payloads; UpdatePermission still lacks a direct regression case proving that legacy input is rejected, so the change is mergeable with explicit owner awareness or a follow-up test.

Possibly related issues

Possibly related PRs

  • raystack/frontier#1797: This PR extends the same schema.IsValidPermissionNamespace validation and applies it to permission API validation.
  • raystack/frontier#1886: Both PRs require consolidated, schema-formatted permission identifiers in API inputs.
  • raystack/frontier#1887: Both PRs modify permission key parsing, validation, and migration from deprecated fields.

Suggested reviewers: rohilsurana

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
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.

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.

❤️ Share

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
internal/api/v1beta1connect/permission_test.go (1)

84-102: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Prove that deprecated fields are ignored.

The missing-key cases leave Name and Namespace empty. A future fallback to populated deprecated fields could pass these cases. Add CreatePermission and UpdatePermission cases with Key empty, Name and Namespace populated, and expect CodeInvalidArgument.

This follows the PR objective that deprecated request fields are no longer read.

Also applies to: 268-286


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 9a841b60-53d3-4101-b77a-15ff9171c906

📥 Commits

Reviewing files that changed from the base of the PR and between 7c10c55 and 6b786f6.

📒 Files selected for processing (5)
  • cmd/seed.go
  • cmd/seed/permissions.json
  • internal/api/v1beta1connect/permission.go
  • internal/api/v1beta1connect/permission_test.go
  • test/e2e/regression/service_registration_test.go

Comment thread internal/api/v1beta1connect/permission.go Outdated
@coveralls

coveralls commented Aug 14, 2026

Copy link
Copy Markdown

Coverage Report for CI Build 32038815790

Coverage increased (+0.004%) to 48.739%

Details

  • Coverage increased (+0.004%) from the base build.
  • Patch coverage: 4 uncovered changes across 2 files (9 of 13 lines covered, 69.23%).
  • 1 coverage regression across 1 file.

Uncovered Changes

File Changed Covered %
cmd/seed.go 3 0 0.0%
internal/api/v1beta1connect/permission.go 10 9 90.0%

Coverage Regressions

1 previously-covered line in 1 file lost coverage.

File Lines Losing Coverage Coverage
internal/api/v1beta1connect/permission.go 1 60.4%

Coverage Stats

Coverage Status
Relevant Lines: 40091
Covered Lines: 19540
Line Coverage: 48.74%
Coverage Strength: 15.66 hits per line

💛 - Coveralls

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
internal/api/v1beta1connect/permission_test.go (1)

275-315: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Add an invalid-namespace case for UpdatePermission.

internal/api/v1beta1connect/permission.go Line 120 has a separate namespace-validation branch. TestHandler_UpdatePermission covers missing keys, malformed keys, and invalid permission names, but it does not cover a three-part key with an invalid namespace. Add an app..get case and expect connect.CodeInvalidArgument with ErrPermissionKeyNotation.

Based on the changed handler branch and the supplied test cases, this is the only new validation path without a direct regression case.

Proposed test case
+		{
+			name:  "should return bad request error if key namespace is invalid",
+			setup: func(as *mocks.PermissionService) {},
+			request: connect.NewRequest(&frontierv1beta1.UpdatePermissionRequest{
+				Id: testPermissions[testPermissionIdx].ID,
+				Body: &frontierv1beta1.PermissionRequestBody{
+					Key: "app..get",
+				},
+			}),
+			want:    nil,
+			wantErr: connect.NewError(connect.CodeInvalidArgument, ErrPermissionKeyNotation),
+		},

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: d7469106-ebfb-4b52-94ba-265fdc69e424

📥 Commits

Reviewing files that changed from the base of the PR and between 6b786f6 and c28de61.

📒 Files selected for processing (3)
  • internal/api/v1beta1connect/errors.go
  • internal/api/v1beta1connect/permission.go
  • internal/api/v1beta1connect/permission_test.go

Comment thread cmd/seed/permissions.json
@@ -1,50 +1,42 @@
[
{
"name": "create",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What is the purpose of these seed JSON files? It looks like dummy data. If they are not needed, we can think of removing them.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The six JSON files under cmd/seed/ (permissions, roles, users, organizations, projects, resource) are compiled into the binary with go:embed and used by exactly one thing: the frontier seed CLI command, documented in the CLI reference. Running it against a live server creates a sample world through the public API — the compute/order and database/order permissions, two custom roles, a sample org with users, projects, a resource, and policies. Its purpose is stated in its own help text: making it easier to get started — demo data for someone evaluating Frontier locally.

Removing the command and its fixtures is doable, but that's its own discussion — keeping this PR to the request-field change.

@whoAbhishekSah

Copy link
Copy Markdown
Member

@AmanGIT07, did you test that the reconcile flow is working correctly for permissions?

AmanGIT07 and others added 3 commits August 17, 2026 19:28
CreatePermission and UpdatePermission read the permission identity only
from the key field and return InvalidArgument when it is missing or
malformed. The deprecated namespace/name request fields are no longer
read. The seed command and e2e tests send keys.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Missing or malformed keys now fail with a format-hint error instead of
a generic bad request. Create validates the namespace form and Update
applies the same name and namespace checks as Create.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Create and Update reject a body that sends only namespace/name, an
empty key part, or an invalid key namespace.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@AmanGIT07
AmanGIT07 force-pushed the refactor/drop-deprecated-request-fallbacks branch from d3b2cf6 to ca5b944 Compare August 17, 2026 14:22
@AmanGIT07

Copy link
Copy Markdown
Contributor Author

@whoAbhishekSah Verified live against a server built from this branch: reconcile dry-run plans the adds, apply creates them through the key-only CreatePermission, an immediate re-run converges to "no changes", export reads back the exact namespace/name pair, and delete: true removes them. An invalid namespace in the desired-state file fails the plan client-side before any server call.

Also rebased the branch onto current main (post #1887, so the key-reading reconciler was in the loop for the run above) and dropped the namespace-grammar commit from this PR — fix/reconcile-permission-spicedb-grammar covers that more completely.

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.

3 participants