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: Include oldObject and admission request metadata in expansion #3341

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

multimac
Copy link

What this PR does / why we need it: Update the expansion logic to propagate the oldObject and userInfo fields from the admission request (along with a few other fields)

I've been trying to set up a policy that allows users to edit fields of a specific workload resource (eg. a Deployment) but prevents them from modifying the Pod template within that resource, as that could allow them to alter the workload and lead to security issues (eg. modifying the container image that is executed)

Currently, the expansion logic only expands the object field, meaning it's not possibly to detect if a policy is operating on a CREATE or an UPDATE request, and act accordingly. Additionally, because it doesn't propagate the userInfo field, it's not possible to make policies that depend on which user made the change

Special notes for your reviewer: I've tried to add tests to pkg/expansion, but wasn't sure how to go about setting up a test in pkg/webhook to confirm all fields from the admission request are propagated as expected

This commit updates `pkg/expansion` and `pkg/webhook` to include additional information from the `AdmissionRequest` object when expanding workload resources.

The two main pieces of now-propagated information are `OldObject` and `UserInfo`, which allow for policies that apply to updated resources, and that depend on the user / system that is performing the creation/updating of the resource.

Signed-off-by: David Symons <[email protected]>
@multimac multimac requested a review from a team as a code owner March 28, 2024 06:00
Copy link
Contributor

@maxsmythe maxsmythe left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

Because this change is super specific to the admission webhook, I think we can restrict our changes to only that file (webhook/policy.go). Here are my rough thoughts:

  • rename createReviewForResultant() createResultantReviews(), refactor to accept a review object and return review objects for the expanded resources
  • as part of the above refactoring, call expansion twice: once for object and once for oldObject (where non-nil)
  • As far as testing goes, we will only need to write unit tests for createResultantReviews()

)

// Expandable represents an expandable object and its metadata.
type Expandable struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

Because object, oldObject, etc. only exist for webhook admission (not audit, gator, or any other enforcement point), we probably should not make these part of the interface. We can probably achieve the same result by modifying how the admission webhook invokes expansion.

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

2 participants