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

Add configuration to permissions pre-flight check to use SelfSubjectAccessReview or SelfSubjectRulesReview #931

Merged

Conversation

everettraven
Copy link
Contributor

What this PR does / why we need it:

SelfSubjectAccessReviews are great for this pre-flight check's use case, but can a bit intense on the API server (for every resource we are sending at least one request to the API server). For users who are concerned about the load placed on the API server, it would be nice to allow the option to use a SelfSubjectRulesReview instead as it will give the set of permissions a user has for a namespace. Using this API, and caching the results per namespace, results in less requests sent directly to the API server.

This PR:

  • Refactors the permissions package to have a pluggable PermissionValidator interface that has a ValidatePermissions function instead of using a single, inextensible function as existed previously.
  • Adds PermissionValidator implementations that validates permissions using SelfSubjectAccessReview and SelfSubjectRulesReview
  • Refactors validators and preflight check as necessary to make use of the new PermissionValidator interface

Which issue(s) this PR fixes:

Fixes #930

Does this PR introduce a user-facing change?

Add configuration option to the PermissionValidation pre-flight check to specify use of either the `SelfSubjectAccessReview` or `SelfSubjectRulesReview` APIs for performing permission validation. `SelfSubjectAccessReview`s are more accurate but result in higher load on the API server. `SelfSubjectRulesReview`s are less accurate but result in lower load on the API server.

Additional Notes for your reviewer:

Review Checklist:
  • Follows the developer guidelines
  • Relevant tests are added or updated
  • Relevant docs in this repo added or updated
  • Relevant carvel.dev docs added or updated in a separate PR and there's
    a link to that PR
  • Code is at least as readable and maintainable as it was before this
    change

Additional documentation e.g., Proposal, usage docs, etc.:


@praveenrewar
Copy link
Member

@rashmigottipati @tmshort Do y'all want to review this first? In case you already have and it looks good to you, please drop an LGTM 😄

@rashmigottipati
Copy link
Contributor

@praveenrewar that sounds good, I'll make sure to review it today/tomorrow. :)

Copy link
Member

@praveenrewar praveenrewar left a comment

Choose a reason for hiding this comment

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

Changes look good (added some optional nits). Should we also add a test for SelfSubjectRulesReview. I think the existing ones only tests SelfSubjectAccessReview as that is used by default.

pkg/kapp/permissions/preflight.go Outdated Show resolved Hide resolved
// An error is returned if there are any issues creating a SelfSubjectRulesReview (i.e can't determine permissions)
// or if the SelfSubjectRulesReview is evaluated and the caller does not have the permission to perform the actions
// identified in the provided ResourceAttributes.
func (rv *SelfSubjectRulesReviewValidator) ValidatePermissions(ctx context.Context, resourceAttrib *authv1.ResourceAttributes) error {
Copy link
Member

Choose a reason for hiding this comment

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

(optional) nit: resourceAttributes instead of resourceAttrib? (Also applicable to ValidatePermissions on SelfSubjectAccessReviewValidator)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I missed making this change. I can make this change if needed, but functionally it shouldn't make a difference

@everettraven
Copy link
Contributor Author

Should we also add a test for SelfSubjectRulesReview. I think the existing ones only tests SelfSubjectAccessReview as that is used by default.

I think that is reasonable. I think this might be possible via adding a kapp Config resource to the appropriate tests and changing the value there, which I hadn't thought of before. I'll try to have a change made soon-ish for this

@praveenrewar
Copy link
Member

@everettraven Just checking if you are still working on it or your forgot to push your changes. (No rush)

@everettraven
Copy link
Contributor Author

@praveenrewar thanks for following up! I was working on the changes a bit yesterday. I'll finish them up and push today

to allow configuring whether it uses SelfSubjectAccessReview or
SelfSubjectRulesReview to determine if a user has the appropriate
permissions. Defaults to SelfSubjectAccessReview for backwards compatibility

Signed-off-by: everettraven <[email protected]>
@everettraven everettraven force-pushed the enhancement/permissions-ssrr branch from cb68443 to 0505c5f Compare May 8, 2024 17:48
@everettraven
Copy link
Contributor Author

@praveenrewar @100mik rebased and pushed. I can squash the commits if needed

Copy link
Contributor

@rashmigottipati rashmigottipati left a comment

Choose a reason for hiding this comment

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

Looks good to me!

Copy link
Member

@praveenrewar praveenrewar left a comment

Choose a reason for hiding this comment

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

LGTM!

@praveenrewar praveenrewar merged commit 2d0b7ed into carvel-dev:develop May 9, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
3 participants