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

feat: Make Casbin matcher configurable on runtime(globMatch(default) or RegexMatch) #7165

Merged
merged 8 commits into from Oct 9, 2021

Conversation

cezhang
Copy link
Contributor

@cezhang cezhang commented Sep 6, 2021

Related topic: #3717 #3870 #4719
As @jannfis mentioned in #3870, I implement the feature of making the casbin matcher configurable on runtime. Default mode is globMatch, so completely compatible with current code. Anyone who want to use regex mode needs to set "match.mode" in argocd-rbac-cm.

Note on DCO:

If the DCO action in the integration test fails, one or more of your commits are not signed off. Please click on the Details link next to the DCO action for instructions on how to resolve this.

Checklist:

  • Either (a) I've created an enhancement proposal and discussed it with the community, (b) this is a bug fix, or (c) this does not need to be in the release notes.
  • The title of the PR states what changed and the related issues number (used for the release note).
  • I've included "Closes [ISSUE #]" or "Fixes [ISSUE #]" in the description to automatically close the associated issue.
  • I've updated both the CLI and UI to expose my feature, or I plan to submit a second PR with them.
  • Does this PR require documentation updates?
  • I've updated documentation as required by this PR.
  • Optional. My organization is added to USERS.md.
  • I have signed off all my commits as required by DCO
  • I have written unit and/or e2e tests for my change. PRs without these are unlikely to be merged.
  • My build is green (troubleshooting builds).

@codecov
Copy link

codecov bot commented Sep 6, 2021

Codecov Report

Merging #7165 (4631b25) into master (b073621) will increase coverage by 0.09%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #7165      +/-   ##
==========================================
+ Coverage   41.24%   41.34%   +0.09%     
==========================================
  Files         161      161              
  Lines       21525    21581      +56     
==========================================
+ Hits         8878     8922      +44     
- Misses      11384    11399      +15     
+ Partials     1263     1260       -3     
Impacted Files Coverage Δ
util/rbac/rbac.go 76.39% <100.00%> (+5.53%) ⬆️
util/env/env.go 61.53% <0.00%> (-22.68%) ⬇️
server/application/application.go 32.29% <0.00%> (-0.04%) ⬇️
controller/appcontroller.go 53.30% <0.00%> (ø)
util/git/client.go 44.74% <0.00%> (+0.18%) ⬆️
util/settings/settings.go 47.02% <0.00%> (+0.25%) ⬆️
controller/metrics/metrics.go 79.86% <0.00%> (+3.43%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b073621...4631b25. Read the comment docs.

Signed-off-by: cezhang <c1zhang.dev@gmail.com>
Signed-off-by: cezhang <c1zhang.dev@gmail.com>
@cezhang
Copy link
Contributor Author

cezhang commented Sep 21, 2021

Hello @alexmt , any suggestion of moving next?

@mayzhang2000 mayzhang2000 self-assigned this Oct 1, 2021
Copy link
Contributor

@mayzhang2000 mayzhang2000 left a comment

Choose a reason for hiding this comment

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

Could you please update documentation operator-manual?

_ = 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"))
Copy link
Contributor

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 for repositories? Should it be testing for a cluster which does not match with the expression?

Copy link
Contributor Author

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?

Copy link
Contributor

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 using repository, then it failed not due to it failed the GlobMatch.

_ = 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"))
Copy link
Contributor

Choose a reason for hiding this comment

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

I have the same question as above.

@mayzhang2000
Copy link
Contributor

@jessesuen Wonder if you could help provide further review of this PR? Thank you!

Copy link
Collaborator

@alexmt alexmt left a comment

Choose a reason for hiding this comment

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

Thank you for the feature @cezhang !

The only concern is that we had another request to make the whole model configurable. However, after looking at the code, I've realized that the matchMode config and globOrRegexMatch function don't introduce any conflict. The globOrRegexMatch in future can be used in user provide policy model.

Added just one minor comment about renaming matchMode to policy.matchMode. LGTM after we agree about the name.

# matchMode configures the matchers function for casbin.
# There are two options for this, 'glob' for glob matcher or 'regex' for regex matcher. If omitted or mis-configured,
# will be set to 'glob' as default.
matchMode: 'glob'
Copy link
Collaborator

Choose a reason for hiding this comment

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

I feel that matchMode key name is a little ambiguous: Argo CD matches different things and it is good to scope it a little. Can we rename it to policy.matchMode to make it more explicit? WDYT @cezhang ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. Commit again, please check.

Signed-off-by: cezhang <c1zhang.dev@gmail.com>
Copy link
Collaborator

@alexmt alexmt left a comment

Choose a reason for hiding this comment

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

LGTM

@alexmt alexmt merged commit 363e1d2 into argoproj:master Oct 9, 2021
ciiay pushed a commit to ciiay/argo-cd that referenced this pull request Oct 21, 2021
…or RegexMatch) (argoproj#7165)

* feat: Make Casbin matcher configurable on runtime(globMatch(default) or RegexMatch)

Signed-off-by: cezhang <c1zhang.dev@gmail.com>
Signed-off-by: ciiay <yicai@redhat.com>
@wesbrownfavor wesbrownfavor mentioned this pull request May 11, 2022
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants