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

Fix API ABAC for access tokens without attributes #1067

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions internal/api/auth/token_verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (t *OIDCTokenVerifier) parseAttributes(token *oidc.IDToken) ([]string, erro
)
}

var filteredValue []string
filteredValue := []string{}
for i := range val.Len() {
str, ok := val.Index(i).Interface().(string)
if ok {
Expand All @@ -122,7 +122,7 @@ func (t *OIDCTokenVerifier) parseAttributes(token *oidc.IDToken) ([]string, erro
return filteredValue, nil
}

var attributes []string
attributes := []string{}
for _, role := range filteredValue {
if attrs, ok := t.cfg.ABAC.RolesMapping[role]; ok {
attributes = append(attributes, attrs...)
Expand Down
64 changes: 64 additions & 0 deletions internal/api/auth/token_verifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,47 @@ func TestParseAttributes(t *testing.T) {
Attributes: []string{"*"},
},
},
{
name: "Parses attributes based on configuration (disabled)",
config: &auth.OIDCConfig{
ProviderURL: iss,
ClientID: audience,
ABAC: auth.OIDCABACConfig{
Enabled: false,
},
},
token: token(t, signer, iss, customClaims{
Email: "[email protected]",
EmailVerified: true,
Attributes: []string{"*"},
}),
wantClaims: &auth.Claims{
Email: "[email protected]",
EmailVerified: true,
Attributes: nil,
},
},
{
name: "Parses attributes based on configuration (no attributes)",
config: &auth.OIDCConfig{
ProviderURL: iss,
ClientID: audience,
ABAC: auth.OIDCABACConfig{
Enabled: true,
ClaimPath: "attributes",
},
},
token: token(t, signer, iss, customClaims{
Email: "[email protected]",
EmailVerified: true,
Attributes: []string{},
}),
wantClaims: &auth.Claims{
Email: "[email protected]",
EmailVerified: true,
Attributes: []string{},
},
},
{
name: "Parses attributes based on configuration (nested)",
config: &auth.OIDCConfig{
Expand Down Expand Up @@ -254,6 +295,29 @@ func TestParseAttributes(t *testing.T) {
Attributes: []string{"*", "package:list", "package:listActions", "package:move", "package:read", "package:upload"},
},
},
{
name: "Parses attributes based on configuration (mapping roles, no attributes)",
config: &auth.OIDCConfig{
ProviderURL: iss,
ClientID: audience,
ABAC: auth.OIDCABACConfig{
Enabled: true,
ClaimPath: "attributes",
UseRoles: true,
RolesMapping: map[string][]string{"admin": {"*"}},
},
},
token: token(t, signer, iss, customClaims{
Email: "[email protected]",
EmailVerified: true,
Attributes: []string{"other", "random", "role"},
}),
wantClaims: &auth.Claims{
Email: "[email protected]",
EmailVerified: true,
Attributes: []string{},
},
},
{
name: "Fails to parse attributes (missing claim)",
config: &auth.OIDCConfig{
Expand Down
1 change: 0 additions & 1 deletion internal/workflow/processing.go
Original file line number Diff line number Diff line change
Expand Up @@ -1284,7 +1284,6 @@ func (w *ProcessingWorkflow) validatePREMIS(
XMLPath: xmlPath,
XSDPath: w.cfg.ValidatePREMIS.XSDPath,
}).Get(activityOpts, &xmlvalidateResult)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added by make lint, I didn't want to create another commit just for it ;)

if err != nil {
if strings.Contains(err.Error(), fmt.Sprintf("%s: no such file or directory", xmlPath)) {
// Allow PREMIS XML to not exist without failing workflow.
Expand Down
Loading