Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

auth/clientcredentials: add schema-based scope enforcement interceptor #61

Merged
merged 8 commits into from
Sep 3, 2024

Conversation

bobheadxi
Copy link
Member

@bobheadxi bobheadxi commented Sep 2, 2024

Adds an interceptor, clientcredentials.Interceptor, that enforces required SAMS scopes based on a proto schema extension. This will reduce boilerplate in RPC implementations and reduce the chance of mistakes/out-of-sync problems between a schema and the implementation

Usage example:

extend google.protobuf.MethodOptions {
	// The SAMS scopes required to use this RPC.
	//
	// The range 50000-99999 is reserved for internal use within individual organizations
	// so you can use numbers in this range freely for in-house applications.
	repeated string sams_required_scopes = 50001;
}

Allows you to set required scopes as method options:

rpc GetUserRoles(GetUserRolesRequest) returns (GetUserRolesResponse) {
	option (sams_required_scopes) = "sams::user.roles::read";
};

This generates E_SamsRequiredScopes that can be used to point to where we can extract sams_required_scopes.

Test plan

Unit tests

@bobheadxi bobheadxi requested a review from a team as a code owner September 2, 2024 18:29
@bobheadxi bobheadxi force-pushed the clientcredentials-schema-interceptor branch from 27b3fc2 to 9344924 Compare September 2, 2024 18:51
Copy link
Member

@unknwon unknwon left a comment

Choose a reason for hiding this comment

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

Comment on lines 165 to 168
logger.Error("attempt to authenticate using SAMS token without required scope",
log.Error(err))
// Return an opaque error
return info, connect.NewError(connect.CodePermissionDenied, errors.New("insufficient scope"))
Copy link
Member

Choose a reason for hiding this comment

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

I think:

  1. Logging service-side errors here is non-actionable, after all this is client's problem to have insufficient scope.
  2. The error returned to the client does not need to be opaque (no security concerns), and being explicit greatly help the client debug scope issues.

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed the log, and made the error non-opaque 👍

@bobheadxi bobheadxi force-pushed the clientcredentials-schema-interceptor branch from def9a18 to bcfd685 Compare September 2, 2024 20:50
@bobheadxi bobheadxi requested a review from unknwon September 2, 2024 20:50
@bobheadxi bobheadxi merged commit 35e9505 into main Sep 3, 2024
2 checks passed
@bobheadxi bobheadxi deleted the clientcredentials-schema-interceptor branch September 3, 2024 00:28
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