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(rbac): handle malformed rbac policy #11964

Merged
merged 2 commits into from
May 28, 2023

Conversation

zekth
Copy link
Contributor

@zekth zekth commented Jan 12, 2023

The rbac parser happens to swallow some malformed entries like the one i added in test:

  • p, role:Myrole, applications, *, myapp/* allow

The outcome of this, the whole rbac was broken and then no apps, no clusters were showing up in argo-cd UI. This PR addresses this problem.

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).

@zekth zekth force-pushed the fix/rbac-missing-comma branch from 78a0650 to c029254 Compare January 12, 2023 09:27
@@ -472,6 +472,12 @@ func loadPolicyLine(line string, model model.Model) error {
return fmt.Errorf("invalid RBAC policy: %s", line)
}

for i := 0; i < len(tokens); i++ {
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if a role could contain a space. Like `p, some spacey role, applications, , myapp/, allow

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made the assumption that not indeed.

Copy link
Member

Choose a reason for hiding this comment

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

Want to limit this check to everything besides the role field, so it's an easy-merge?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will push a change

Copy link
Member

Choose a reason for hiding this comment

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

Can't we just assume that there are two types of policies right now:

  • Grants (g), which has two fields (the grantee and the role granted)
  • Policy (p), which has five fields (the role, the resource type, the verb, the resource name pattern and the action)

So wouldn't it make more sense to evaluate the policy type and check whether it has the right amount of fields set?

Copy link
Member

Choose a reason for hiding this comment

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

I think we might already do that. But the fields are split on commas, not spaces.

Copy link
Member

Choose a reason for hiding this comment

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

I ment, instead of checking whether a field contains white space, couldn't we just check for len(tokens) according to the type of policy (g or p) of the currently evaluated record?

Copy link
Member

Choose a reason for hiding this comment

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

Oh, sure, since we wouldn't hit the right number of tokens when there's a comma missing. I do like that better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will push the fix torward that approach then, i wasn't sure if there was special cases that i was not was about.

Copy link
Member

Choose a reason for hiding this comment

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

@alexmt Are you aware of RBAC policy definitions that have a different pattern, e.g. a variable number of fields in a permission definition?

util/rbac/rbac_test.go Outdated Show resolved Hide resolved
@zekth zekth force-pushed the fix/rbac-missing-comma branch 2 times, most recently from 1473415 to 6e96579 Compare January 12, 2023 18:19
@codecov
Copy link

codecov bot commented Jan 12, 2023

Codecov Report

Patch coverage: 82.19% and project coverage change: +0.08 🎉

Comparison is base (5662367) 48.98% compared to head (7730660) 49.06%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #11964      +/-   ##
==========================================
+ Coverage   48.98%   49.06%   +0.08%     
==========================================
  Files         249      249              
  Lines       43066    43127      +61     
==========================================
+ Hits        21094    21160      +66     
+ Misses      19864    19855       -9     
- Partials     2108     2112       +4     
Impacted Files Coverage Δ
util/git/client.go 50.00% <37.50%> (ø)
server/cluster/cluster.go 50.13% <85.71%> (+10.20%) ⬆️
pkg/apis/application/v1alpha1/types.go 59.68% <100.00%> (+0.09%) ⬆️
util/rbac/rbac.go 78.12% <100.00%> (+0.38%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@zekth zekth force-pushed the fix/rbac-missing-comma branch 4 times, most recently from a726b44 to 4fef3a9 Compare January 20, 2023 11:23
@zekth zekth force-pushed the fix/rbac-missing-comma branch from 4fef3a9 to 1462282 Compare January 25, 2023 15:26
@zekth
Copy link
Contributor Author

zekth commented Jan 25, 2023

@crenshaw-dev any update on this?

util/rbac/rbac.go Show resolved Hide resolved
@zekth zekth force-pushed the fix/rbac-missing-comma branch from 1462282 to 0ceec2f Compare February 7, 2023 10:24
@zekth zekth force-pushed the fix/rbac-missing-comma branch from 0ceec2f to 160e57d Compare February 22, 2023 12:17
@zekth zekth force-pushed the fix/rbac-missing-comma branch from a152e4f to 4e2fa06 Compare April 14, 2023 08:03
@zekth zekth requested review from crenshaw-dev and jannfis April 14, 2023 08:04
@zekth zekth force-pushed the fix/rbac-missing-comma branch from 4e2fa06 to ed216a2 Compare May 1, 2023 20:28
@zekth zekth force-pushed the fix/rbac-missing-comma branch from ed216a2 to 2d2c5ca Compare May 21, 2023 08:32
util/rbac/rbac.go Show resolved Hide resolved
@zekth zekth force-pushed the fix/rbac-missing-comma branch from 2d2c5ca to 4065522 Compare May 27, 2023 20:44
Signed-off-by: Vincent Le Goff <vincent.legoff@konghq.com>
@zekth zekth force-pushed the fix/rbac-missing-comma branch from 4065522 to fb4571d Compare May 27, 2023 20:51
@zekth
Copy link
Contributor Author

zekth commented May 27, 2023

@crenshaw-dev fixed

Copy link
Member

@crenshaw-dev crenshaw-dev left a comment

Choose a reason for hiding this comment

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

Thanks, @zekth!

@crenshaw-dev crenshaw-dev merged commit dddee33 into argoproj:master May 28, 2023
@zekth zekth deleted the fix/rbac-missing-comma branch May 28, 2023 05:39
yyzxw pushed a commit to yyzxw/argo-cd that referenced this pull request Aug 9, 2023
Signed-off-by: Vincent Le Goff <vincent.legoff@konghq.com>
tesla59 pushed a commit to tesla59/argo-cd that referenced this pull request Dec 16, 2023
Signed-off-by: Vincent Le Goff <vincent.legoff@konghq.com>
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.

3 participants