Skip to content

refactor(api): require resource in CheckResourcePermission - #1886

Open
AmanGIT07 wants to merge 1 commit into
mainfrom
refactor/require-resource-in-permission-check
Open

refactor(api): require resource in CheckResourcePermission#1886
AmanGIT07 wants to merge 1 commit into
mainfrom
refactor/require-resource-in-permission-check

Conversation

@AmanGIT07

Copy link
Copy Markdown
Contributor

Summary

CheckResourcePermission accepts the object only via the resource field (namespace:id). The deprecated object_id/object_namespace request fields are no longer read; requests sending only those fields now receive InvalidArgument. Namespace aliases keep working inside resource. Part of #1782.

Changes

  • internal/api/v1beta1connect/permission_check.go: remove the split-field fallback; reject a missing or malformed resource
  • test/e2e/regression/onboarding_test.go, serviceusers_test.go, api_test.go: check requests send resource
  • internal/api/v1beta1connect/permission_check_test.go: success cases send resource; add missing-resource case

Test Plan

  • go test ./internal/api/v1beta1connect/ passes
  • make lint passes (0 issues)
  • Onboarding, service-users, and API e2e regression suites pass

🤖 Generated with Claude Code

CheckResourcePermission reads the object only from the resource field
("namespace:id") and returns InvalidArgument when it is missing or
malformed. The deprecated object_id/object_namespace request fields are
no longer read. E2E tests send the resource form.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@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 14, 2026 10:13am

@coderabbitai

coderabbitai Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Permission checks now require a valid, namespace-qualified resource identifier.
    • Requests missing or containing an invalid resource identifier return a clear invalid-argument error.
    • Updated permission checks across onboarding, relation, and service-user workflows to use the unified resource format.

Walkthrough

Changes

Permission resource identifier migration

Layer / File(s) Summary
Resource validation and unit coverage
internal/api/v1beta1connect/permission_check.go, internal/api/v1beta1connect/permission_check_test.go
CheckResourcePermission now requires the combined Resource identifier and returns InvalidArgument when it is missing or invalid. Unit tests cover the updated request format and error cases.
End-to-end permission request migration
test/e2e/regression/api_test.go, test/e2e/regression/onboarding_test.go, test/e2e/regression/serviceusers_test.go
Regression and onboarding permission checks now use namespace-qualified values in Resource instead of separate object fields.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 71057

The change enforces the new resource-based request format, with deprecated-only requests rejected as invalid. No actionable merge-blocking risk remains beyond an optional test hardening follow-up.

Suggested reviewers: whoabhisheksah, 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


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 5a381cba-390a-4d76-b8c0-f350fcbc32c1

📥 Commits

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

📒 Files selected for processing (5)
  • internal/api/v1beta1connect/permission_check.go
  • internal/api/v1beta1connect/permission_check_test.go
  • test/e2e/regression/api_test.go
  • test/e2e/regression/onboarding_test.go
  • test/e2e/regression/serviceusers_test.go

Comment on lines +44 to +50
name: "should return bad request error if resource is missing",
request: connect.NewRequest(&frontierv1beta1.CheckResourcePermissionRequest{
Permission: schema.UpdatePermission,
}),
want: nil,
wantErr: connect.NewError(connect.CodeInvalidArgument, ErrBadRequest),
},

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.

🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

Add a regression case for deprecated fields.

The current missing-resource case sets neither Resource nor ObjectId/ObjectNamespace. It would pass even if the legacy fallback were reintroduced. Add a case that sets only ObjectId and ObjectNamespace and expects CodeInvalidArgument.

Proposed test case
 		{
 			name: "should return bad request error if resource is missing",
 			request: connect.NewRequest(&frontierv1beta1.CheckResourcePermissionRequest{
 				Permission: schema.UpdatePermission,
 			}),
 			want:    nil,
 			wantErr: connect.NewError(connect.CodeInvalidArgument, ErrBadRequest),
 		},
+		{
+			name: "should reject deprecated object fields when resource is missing",
+			request: connect.NewRequest(&frontierv1beta1.CheckResourcePermissionRequest{
+				ObjectId:        testRelationV2.Object.ID,
+				ObjectNamespace: testRelationV2.Object.Namespace,
+				Permission:      schema.UpdatePermission,
+			}),
+			want:    nil,
+			wantErr: connect.NewError(connect.CodeInvalidArgument, ErrBadRequest),
+		},
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
name: "should return bad request error if resource is missing",
request: connect.NewRequest(&frontierv1beta1.CheckResourcePermissionRequest{
Permission: schema.UpdatePermission,
}),
want: nil,
wantErr: connect.NewError(connect.CodeInvalidArgument, ErrBadRequest),
},
name: "should return bad request error if resource is missing",
request: connect.NewRequest(&frontierv1beta1.CheckResourcePermissionRequest{
Permission: schema.UpdatePermission,
}),
want: nil,
wantErr: connect.NewError(connect.CodeInvalidArgument, ErrBadRequest),
},
{
name: "should reject deprecated object fields when resource is missing",
request: connect.NewRequest(&frontierv1beta1.CheckResourcePermissionRequest{
ObjectId: testRelationV2.Object.ID,
ObjectNamespace: testRelationV2.Object.Namespace,
Permission: schema.UpdatePermission,
}),
want: nil,
wantErr: connect.NewError(connect.CodeInvalidArgument, ErrBadRequest),
},

@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 31791295387

Coverage decreased (-0.007%) to 48.691%

Details

  • Coverage decreased (-0.007%) from the base build.
  • Patch coverage: 1 of 1 lines across 1 file are fully covered (100%).
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 40075
Covered Lines: 19513
Line Coverage: 48.69%
Coverage Strength: 15.66 hits per line

💛 - Coveralls

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