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 validate command can now take either namespace or policy-file #15543

Merged
merged 12 commits into from
Oct 30, 2023

Conversation

ashinsabu3
Copy link
Contributor

@ashinsabu3 ashinsabu3 commented Sep 18, 2023

fixes: #6126
This fix now allows the command to take only a namespace flag if required.
image

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).
  • The title of the PR conforms to the Toolchain Guide
  • 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).
  • My new feature complies with the feature status guidelines.
  • I have added a brief description of why this PR is necessary and/or what this PR solves.

@codecov
Copy link

codecov bot commented Sep 18, 2023

Codecov Report

Attention: 17 lines in your changes are missing coverage. Please review.

Comparison is base (ab1cc50) 49.54% compared to head (1659823) 49.68%.
Report is 4 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #15543      +/-   ##
==========================================
+ Coverage   49.54%   49.68%   +0.14%     
==========================================
  Files         269      269              
  Lines       46583    46629      +46     
==========================================
+ Hits        23079    23169      +90     
+ Misses      21232    21186      -46     
- Partials     2272     2274       +2     
Files Coverage Δ
cmd/argocd/commands/admin/settings_rbac.go 51.43% <56.41%> (+24.79%) ⬆️

... and 2 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@crenshaw-dev crenshaw-dev changed the title fix: rbac validate command can now take either namespace or policy-fi… fix: rbac validate command can now take either namespace or policy-file Sep 18, 2023
@crenshaw-dev
Copy link
Member

@ashinsabu3 can you write a test to prevent regressions?

@ashinsabu3
Copy link
Contributor Author

ashinsabu3 commented Sep 18, 2023

@ashinsabu3 can you write a test to prevent regressions?

@crenshaw-dev I don't quite understand what you mean by this. If you mean a unit test, I'm not exactly sure how I would test the Rbac command functions.

@crenshaw-dev
Copy link
Member

Yep, unit testing! Cobra has unit testing utilities. I think there are a couple examples using it in our code base. It'll probably require a bit of mocking to get working.

@ashinsabu3 ashinsabu3 requested a review from a team as a code owner September 19, 2023 20:26
@ashinsabu3
Copy link
Contributor Author

ashinsabu3 commented Sep 19, 2023

I've added a test to check the command being returned, but couldn't get the test for it's execution working. The more I went into trying to get it working, it felt less like a unit test. I've commented it out for now @crenshaw-dev

@ashinsabu3 ashinsabu3 requested a review from a team as a code owner September 28, 2023 09:45
…le as arg

Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>
Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>
Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>
Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>
Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>
@ashinsabu3
Copy link
Contributor Author

ashinsabu3 commented Sep 30, 2023

The previous CI failures seem to be due to some flaky e2e tests, not sure, all passed when run on a weekend night 🙂

cmd/argocd/commands/admin/settings_rbac.go Outdated Show resolved Hide resolved
cmd/argocd/commands/admin/settings_rbac_test.go Outdated Show resolved Hide resolved
var (
policyFile string
)

var command = &cobra.Command{
Use: "validate --policy-file=POLICYFILE",
Use: "validate --policy-file POLICYFILE [--namespace NAMESPACE]",
Copy link
Member

Choose a reason for hiding this comment

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

As policy-file is also optional now, put it in square brackets.

Suggested change
Use: "validate --policy-file POLICYFILE [--namespace NAMESPACE]",
Use: "validate [--policy-file POLICYFILE] [--namespace NAMESPACE]",

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Short: "Validate RBAC policy",
Long: `
Validates an RBAC policy for being syntactically correct. The policy must be
a local file, and in either CSV or K8s ConfigMap format.
a local file or a K8s ConfigMap in the provided namespace, and in either CSV or K8s ConfigMap format.
Copy link
Member

Choose a reason for hiding this comment

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

While we are updating the command, can we add an example as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding one, let me know if the wording looks fine

Copy link
Member

Choose a reason for hiding this comment

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

The wording looks good! Thanks!

return command
}

// NewRBACCanRoleCommand is the command for 'rbac can-role'
func NewRBACCanCommand() *cobra.Command {
func NewRBACCanCommand(clientConfig clientcmd.ClientConfig) *cobra.Command {
Copy link
Member

Choose a reason for hiding this comment

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

Any reason to put the clientConfig as a parameter? If we are taking namespace as an input, do we need to fetch the namespace from clientConfig rather than adding namespace as a variable like policyFile?

Copy link
Contributor Author

@ashinsabu3 ashinsabu3 Oct 19, 2023

Choose a reason for hiding this comment

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

I've modified this back, at the time I missed something (most likely the issue you commented below
the flag &policyFile is repeated. This should be &namespace? ) and while testing the command it repeatedly returned some segmentation fault so I thought passing down the clientConfig param would fix it.

I've changed it back now that I know why my command was failing at the time.

cmd/argocd/commands/admin/settings_rbac.go Outdated Show resolved Hide resolved
ashinsabu3 and others added 4 commits October 19, 2023 17:43
Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>
Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>
Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>
@ashinsabu3
Copy link
Contributor Author

@ishitasequeira Addressed comments you had. Do the changes look good?

Copy link
Member

@ishitasequeira ishitasequeira left a comment

Choose a reason for hiding this comment

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

Thanks @ashinsabu3! Changes look good!

Short: "Validate RBAC policy",
Long: `
Validates an RBAC policy for being syntactically correct. The policy must be
a local file, and in either CSV or K8s ConfigMap format.
a local file or a K8s ConfigMap in the provided namespace, and in either CSV or K8s ConfigMap format.
Copy link
Member

Choose a reason for hiding this comment

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

The wording looks good! Thanks!

@ishitasequeira ishitasequeira merged commit 48f175b into argoproj:master Oct 30, 2023
25 checks passed
jmilic1 pushed a commit to jmilic1/argo-cd that referenced this pull request Nov 13, 2023
…le (argoproj#15543)

* fix: rbac validate command can now take either namespace or policy-file as arg

Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>

* remove changes to generated text

Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>

* unit test for rbacvalidatecommand

Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>

* codegen changes

Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>

* retrigger ci pipeline

Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>

* retrigger ci pipeline

Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>

* review comments and test changes

Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>

* codegen changes

Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>

* codegen changes - post rebase

Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>

---------

Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>
Signed-off-by: jmilic1 <70441727+jmilic1@users.noreply.github.com>
vladfr pushed a commit to vladfr/argo-cd that referenced this pull request Dec 13, 2023
…le (argoproj#15543)

* fix: rbac validate command can now take either namespace or policy-file as arg

Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>

* remove changes to generated text

Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>

* unit test for rbacvalidatecommand

Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>

* codegen changes

Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>

* retrigger ci pipeline

Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>

* retrigger ci pipeline

Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>

* review comments and test changes

Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>

* codegen changes

Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>

* codegen changes - post rebase

Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>

---------

Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>
tesla59 pushed a commit to tesla59/argo-cd that referenced this pull request Dec 16, 2023
…le (argoproj#15543)

* fix: rbac validate command can now take either namespace or policy-file as arg

Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>

* remove changes to generated text

Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>

* unit test for rbacvalidatecommand

Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>

* codegen changes

Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>

* retrigger ci pipeline

Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>

* retrigger ci pipeline

Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>

* review comments and test changes

Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>

* codegen changes

Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>

* codegen changes - post rebase

Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>

---------

Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>
@ashinsabu3 ashinsabu3 deleted the rbac-validate-fix branch February 19, 2024 10:02
lyda pushed a commit to lyda/argo-cd that referenced this pull request Mar 28, 2024
…le (argoproj#15543)

* fix: rbac validate command can now take either namespace or policy-file as arg

Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>

* remove changes to generated text

Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>

* unit test for rbacvalidatecommand

Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>

* codegen changes

Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>

* retrigger ci pipeline

Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>

* retrigger ci pipeline

Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>

* review comments and test changes

Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>

* codegen changes

Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>

* codegen changes - post rebase

Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>

---------

Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>
Signed-off-by: Kevin Lyda <kevin@lyda.ie>
Hariharasuthan99 pushed a commit to AmadeusITGroup/argo-cd that referenced this pull request Jun 16, 2024
…le (argoproj#15543)

* fix: rbac validate command can now take either namespace or policy-file as arg

Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>

* remove changes to generated text

Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>

* unit test for rbacvalidatecommand

Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>

* codegen changes

Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>

* retrigger ci pipeline

Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>

* retrigger ci pipeline

Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>

* review comments and test changes

Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>

* codegen changes

Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>

* codegen changes - post rebase

Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>

---------

Signed-off-by: Ashin Sabu <ashin.sabu@harness.io>
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.

argocd-util settings rbac validate --namespace NAME requires a --policy-file argument
3 participants