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

authz: fix regex expression match #5035

Merged
merged 5 commits into from Dec 9, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions authz/rbac_translator.go
Expand Up @@ -94,7 +94,8 @@ func getStringMatcher(value string) *v3matcherpb.StringMatcher {
switch {
case value == "*":
return &v3matcherpb.StringMatcher{
MatchPattern: &v3matcherpb.StringMatcher_SafeRegex{},
MatchPattern: &v3matcherpb.StringMatcher_SafeRegex{
SafeRegex: &v3matcherpb.RegexMatcher{Regex: ".*"}},
ashithasantosh marked this conversation as resolved.
Show resolved Hide resolved
}
case strings.HasSuffix(value, "*"):
prefix := strings.TrimSuffix(value, "*")
Expand All @@ -117,8 +118,9 @@ func getHeaderMatcher(key, value string) *v3routepb.HeaderMatcher {
switch {
case value == "*":
return &v3routepb.HeaderMatcher{
Name: key,
HeaderMatchSpecifier: &v3routepb.HeaderMatcher_SafeRegexMatch{},
Name: key,
HeaderMatchSpecifier: &v3routepb.HeaderMatcher_SafeRegexMatch{
SafeRegexMatch: &v3matcherpb.RegexMatcher{Regex: ".*"}},
}
case strings.HasSuffix(value, "*"):
prefix := strings.TrimSuffix(value, "*")
Expand Down
2 changes: 1 addition & 1 deletion authz/rbac_translator_test.go
Expand Up @@ -127,7 +127,7 @@ func TestTranslatePolicy(t *testing.T) {
Ids: []*v3rbacpb.Principal{
{Identifier: &v3rbacpb.Principal_Authenticated_{
Authenticated: &v3rbacpb.Principal_Authenticated{PrincipalName: &v3matcherpb.StringMatcher{
MatchPattern: &v3matcherpb.StringMatcher_SafeRegex{},
MatchPattern: &v3matcherpb.StringMatcher_SafeRegex{SafeRegex: &v3matcherpb.RegexMatcher{Regex: ".*"}},
}},
}},
},
Expand Down
11 changes: 5 additions & 6 deletions authz/sdk_end2end_test.go
Expand Up @@ -95,8 +95,7 @@ var sdkTests = map[string]struct {
"request": {
"paths":
[
"/grpc.testing.TestService/UnaryCall",
"/grpc.testing.TestService/StreamingInputCall"
"/grpc.testing.TestService/*"
],
"headers":
[
Expand All @@ -122,23 +121,23 @@ var sdkTests = map[string]struct {
"allow_rules":
[
{
"name": "allow_TestServiceCalls",
"name": "allow_all",
"request": {
"paths":
[
"/grpc.testing.TestService/*"
"*"
]
}
}
],
"deny_rules":
[
{
"name": "deny_TestServiceCalls",
"name": "deny_all",
"request": {
"paths":
[
"/grpc.testing.TestService/*"
"*"
]
}
}
Expand Down