forked from mesosphere/traefik-forward-auth
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
optional case-insensitive username and groupname comparisons for RBAC…
… + tests (cherry picked from commit 13427e8)
- Loading branch information
Showing
4 changed files
with
79 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -156,3 +156,61 @@ func TestRBACAuthorizer_Authorize2(t *testing.T) { | |
assert.NilError(t, err) | ||
assert.Equal(t, result, test.should) | ||
} | ||
|
||
func TestCaseInsensitiveSubjects(t *testing.T) { | ||
type testCase struct { | ||
authorizer authorization.Authorizer | ||
user authorization.User | ||
url string | ||
should bool | ||
} | ||
|
||
// declare roles and bindings all lower-case | ||
role := makeRole("grafana-admin", []string{"*"}, []string{"/ops/portal/grafana", "/ops/portal/grafana/*"}) | ||
rolebindings := makeClusterRoleBindingList( | ||
makeBinding("User", "grafana-admin-boyle", "[email protected]", "grafana-admin"), | ||
makeBinding("Group", "grafana-admin-oidc-admins", "oidc:admins", "grafana-admin"), | ||
) | ||
|
||
// default authorizer | ||
defaultAuthorizer := getRBACAuthorizer(&role, rolebindings) | ||
|
||
// case-insensitive authorizer | ||
caseInsensitiveAuthorizer := getRBACAuthorizer(&role, rolebindings) | ||
caseInsensitiveAuthorizer.CaseInsensitiveSubjects = true | ||
|
||
tests := []testCase{ | ||
// users | ||
{ | ||
authorizer: defaultAuthorizer, | ||
user: authorization.User{Name: "[email protected]", Groups: []string{"oidc:chemists"}}, | ||
url: "/ops/portal/grafana/rnJhmVJw.woff2", | ||
should: false, // default case-sensitive user comparison shouldn't allow Boyle | ||
}, | ||
{ | ||
authorizer: caseInsensitiveAuthorizer, | ||
user: authorization.User{Name: "[email protected]", Groups: []string{"oidc:chemists"}}, | ||
url: "/ops/portal/grafana/rnJhmVJw.woff2", | ||
should: true, // case-insensitive user comparison should allow Boyle | ||
}, | ||
// groups | ||
{ | ||
authorizer: defaultAuthorizer, | ||
user: authorization.User{Name: "[email protected]", Groups: []string{"oidc:Admins"}}, | ||
url: "/ops/portal/grafana/rnJhmVJw.woff2", | ||
should: false, // default case-sensitive group comparison shouldn't allow Admins group | ||
}, | ||
{ | ||
authorizer: caseInsensitiveAuthorizer, | ||
user: authorization.User{Name: "[email protected]", Groups: []string{"oidc:Admins"}}, | ||
url: "/ops/portal/grafana/rnJhmVJw.woff2", | ||
should: true, // case-insensitive group comparison should allow Admins group | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
result, err := test.authorizer.Authorize(test.user, "GET", test.url) | ||
assert.NilError(t, err) | ||
assert.Equal(t, result, test.should) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters