-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
feat: Make Casbin matcher configurable on runtime(globMatch(default) or RegexMatch) #7165
Merged
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3a8e88e
fix: Network view is confusing if same ingress is targeting two servi…
cezhang 30d264b
Merge branch 'argoproj:master' into master
cezhang 1b25f26
feat: Make Casbin matcher configurable on runtime(globMatch(default) …
cezhang a949e1f
lint code
cezhang 065a2db
fix lint error
cezhang 4b1ce60
Merge branch 'argoproj:master' into master
cezhang 1a0dc43
add docs; change configmap key name
cezhang 4631b25
change match mode configmap key name
cezhang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -336,3 +336,66 @@ func TestEnforceErrorMessage(t *testing.T) { | |
assert.Equal(t, "rpc error: code = PermissionDenied desc = permission denied: project, sub: proj:default:admin", err.Error()) | ||
|
||
} | ||
|
||
func TestDefaultGlobMatchMode(t *testing.T) { | ||
kubeclientset := fake.NewSimpleClientset() | ||
enf := NewEnforcer(kubeclientset, fakeNamespace, fakeConfigMapName, nil) | ||
err := enf.syncUpdate(fakeConfigMap(), noOpUpdate) | ||
assert.Nil(t, err) | ||
policy := ` | ||
p, alice, clusters, get, "https://github.com/*/*.git", allow | ||
` | ||
_ = enf.SetUserPolicy(policy) | ||
|
||
assert.True(t, enf.Enforce("alice", "clusters", "get", "https://github.com/argoproj/argo-cd.git")) | ||
assert.False(t, enf.Enforce("alice", "repositories", "get", "https://github.com/argoproj/argo-cd.git")) | ||
|
||
} | ||
|
||
func TestGlobMatchMode(t *testing.T) { | ||
cm := fakeConfigMap() | ||
cm.Data[ConfigMapMatchModeKey] = GlobMatchMode | ||
kubeclientset := fake.NewSimpleClientset() | ||
enf := NewEnforcer(kubeclientset, fakeNamespace, fakeConfigMapName, nil) | ||
err := enf.syncUpdate(cm, noOpUpdate) | ||
assert.Nil(t, err) | ||
policy := ` | ||
p, alice, clusters, get, "https://github.com/*/*.git", allow | ||
` | ||
_ = enf.SetUserPolicy(policy) | ||
|
||
assert.True(t, enf.Enforce("alice", "clusters", "get", "https://github.com/argoproj/argo-cd.git")) | ||
assert.False(t, enf.Enforce("alice", "repositories", "get", "https://github.com/argoproj/argo-cd.git")) | ||
|
||
} | ||
|
||
func TestRegexMatchMode(t *testing.T) { | ||
cm := fakeConfigMap() | ||
cm.Data[ConfigMapMatchModeKey] = RegexMatchMode | ||
kubeclientset := fake.NewSimpleClientset() | ||
enf := NewEnforcer(kubeclientset, fakeNamespace, fakeConfigMapName, nil) | ||
err := enf.syncUpdate(cm, noOpUpdate) | ||
assert.Nil(t, err) | ||
policy := ` | ||
p, alice, clusters, get, "https://github.com/argo[a-z]{4}/argo-[a-z]+.git", allow | ||
` | ||
_ = enf.SetUserPolicy(policy) | ||
|
||
assert.True(t, enf.Enforce("alice", "clusters", "get", "https://github.com/argoproj/argo-cd.git")) | ||
assert.False(t, enf.Enforce("alice", "repositories", "get", "https://github.com/argoproj/1argo-cd.git")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have the same question as above. |
||
|
||
} | ||
|
||
func TestGlobMatchFunc(t *testing.T) { | ||
ok, _ := globMatchFunc("arg1") | ||
assert.False(t, ok.(bool)) | ||
|
||
ok, _ = globMatchFunc(time.Now(), "arg2") | ||
assert.False(t, ok.(bool)) | ||
|
||
ok, _ = globMatchFunc("arg1", time.Now()) | ||
assert.False(t, ok.(bool)) | ||
|
||
ok, _ = globMatchFunc("arg/123", "arg/*") | ||
assert.True(t, ok.(bool)) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this test, the
policy
is for cluster,p, alice, clusters, get, "https://github.com/*/*.git", allow
, wonder if you want to verify forrepositories
? Should it be testing for a cluster which does not match with the expression?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My point is to test policy only for clusters, other case should fail on this scenario. So what's your suggestion, only verify test cases for clusters policy?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is to test GlobMatch, I am thinking of focusing the test data on which fails the pattern
https://github.com/*/*.git
. If the test data is usingrepository
, then it failed not due to it failed the GlobMatch.