Add OAuth2 API scope registration and enforcement
Register v1 API scopes in coredata, advertise them in OIDC discovery and protected-resource metadata, show them on the consent screen, and enforce scope-to-action mapping in the IAM Authorizer before policy evaluation. Signed-off-by: Ludovic Vielle <ludovic@probo.com>
This commit is contained in:
@@ -28,9 +28,9 @@ import (
|
||||
|
||||
type (
|
||||
AuthorizeFuncOption func(*iam.AuthorizeParams)
|
||||
AuthorizeFunc func(context.Context, gid.GID, string, ...AuthorizeFuncOption) (*coredata.Scope, error)
|
||||
AuthorizeFunc func(context.Context, gid.GID, iam.Action, ...AuthorizeFuncOption) (*coredata.Scope, error)
|
||||
BatchAuthorizeFuncOption func(*iam.AuthorizeBatchParams)
|
||||
BatchAuthorizeFunc func(context.Context, string, []gid.GID, ...BatchAuthorizeFuncOption) (*coredata.Scope, error)
|
||||
BatchAuthorizeFunc func(context.Context, iam.Action, []gid.GID, ...BatchAuthorizeFuncOption) (*coredata.Scope, error)
|
||||
)
|
||||
|
||||
func WithAttr(key, value string) AuthorizeFuncOption {
|
||||
@@ -78,7 +78,7 @@ func NewAuthorizeFunc(
|
||||
return func(
|
||||
ctx context.Context,
|
||||
objectID gid.GID,
|
||||
action string,
|
||||
action iam.Action,
|
||||
options ...AuthorizeFuncOption,
|
||||
) (*coredata.Scope, error) {
|
||||
identity := authn.IdentityFromContext(ctx)
|
||||
@@ -108,6 +108,10 @@ func NewAuthorizeFunc(
|
||||
return nil, gqlutils.Forbidden(ctx, err)
|
||||
}
|
||||
|
||||
if _, ok := errors.AsType[*iam.ErrInsufficientOAuth2Scope](err); ok {
|
||||
return nil, gqlutils.Forbidden(ctx, err)
|
||||
}
|
||||
|
||||
if errors.Is(err, coredata.ErrResourceNotFound) {
|
||||
return nil, gqlutils.NotFoundf(ctx, "resource not found")
|
||||
}
|
||||
@@ -127,7 +131,7 @@ func NewBatchAuthorizeFunc(
|
||||
) BatchAuthorizeFunc {
|
||||
return func(
|
||||
ctx context.Context,
|
||||
action string,
|
||||
action iam.Action,
|
||||
objectIDs []gid.GID,
|
||||
options ...BatchAuthorizeFuncOption,
|
||||
) (*coredata.Scope, error) {
|
||||
@@ -158,6 +162,10 @@ func NewBatchAuthorizeFunc(
|
||||
return nil, gqlutils.Forbidden(ctx, err)
|
||||
}
|
||||
|
||||
if _, ok := errors.AsType[*iam.ErrInsufficientOAuth2Scope](err); ok {
|
||||
return nil, gqlutils.Forbidden(ctx, err)
|
||||
}
|
||||
|
||||
if _, ok := errors.AsType[*iam.ErrMixedOrganizationBatch](err); ok {
|
||||
return nil, gqlutils.Invalid(ctx, err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user