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

🌱 Implement privileged namespace security policy update for tilt-prepare #10178

Conversation

maxrantil
Copy link
Contributor

@maxrantil maxrantil commented Feb 20, 2024

What this PR does / why we need it:
This PR creates a updateNamespacePodSecurityStandard function to ensure that the pod-security.kubernetes.io/enforce label is set to "privileged" for Namespace objects. This change is essential for compatibility with CAPIs tilt-prepare and Tiltfile when using CAPM3 (and other providers?), where accessing securityContext is required. Without this update, the existing pod-security policy restricts the usage of securityContext, hindering necessary operations. This aligns the behavior with CAPD, where the privileged policy is already set for Namespace objects.

/area provider/infrastructure-in-memory

@k8s-ci-robot
Copy link
Contributor

@maxrantil: The label(s) area/ cannot be applied, because the repository doesn't have them.

In response to this:

What this PR does / why we need it:
This PR creates a updateNamespaceSecurityPolicy function to ensure that the pod-security.kubernetes.io/enforce label is set to "privileged" for Namespace objects. This change is essential for compatibility with CAPIs tilt-prepare and Tiltfile when using CAPM3 (and other providers?), where accessing securityContext is required. Without this update, the existing pod-security policy restricts the usage of securityContext, hindering necessary operations. This aligns the behavior with CAPD, where the privileged policy is already set for Namespace objects.

/area provider/infrastructure-in-memory

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added area/provider/infrastructure-in-memory Issues or PRs related to the in-memory infrastructure provider cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Feb 20, 2024
@k8s-ci-robot
Copy link
Contributor

Hi @maxrantil. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Feb 20, 2024
@maxrantil maxrantil force-pushed the tilt-prepare-update-namespace-security-policy/max branch 2 times, most recently from 345a10d to 6d65534 Compare February 20, 2024 10:43
@chrischdi
Copy link
Member

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Feb 20, 2024
@chrischdi
Copy link
Member

/remove-area provider/infrastructure-in-memory

@k8s-ci-robot k8s-ci-robot added do-not-merge/needs-area PR is missing an area label and removed area/provider/infrastructure-in-memory Issues or PRs related to the in-memory infrastructure provider labels Feb 20, 2024
@chrischdi
Copy link
Member

/area devtools

@k8s-ci-robot k8s-ci-robot added area/devtools Issues or PRs related to devtools and removed do-not-merge/needs-area PR is missing an area label labels Feb 20, 2024
@maxrantil maxrantil force-pushed the tilt-prepare-update-namespace-security-policy/max branch from 6d65534 to aa7fc10 Compare February 20, 2024 11:02
@lentzi90
Copy link
Contributor

This change is essential for compatibility with CAPIs tilt-prepare and Tiltfile when using CAPM3 (and other providers?), where accessing securityContext is required. Without this update, the existing pod-security policy restricts the usage of securityContext, hindering necessary operations. This aligns the behavior with CAPD, where the privileged policy is already set for Namespace objects.

I just wanted to clarify this a bit. Tilt-prepare already removes the security context from the deployments, but this is not enough if the namespace has enforced pod security standards. The issue is not visible for CAPI/CAPD since CAPD anyway uses the privileged policy in order to mount the docker socket. Other providers will likely be able to run with a restricted policy for the namespace, except when using Tilt. This is why we want to make tilt-prepare change the label on the namespace.

@chrischdi
Copy link
Member

chrischdi commented Feb 20, 2024

This change is essential for compatibility with CAPIs tilt-prepare and Tiltfile when using CAPM3 (and other providers?), where accessing securityContext is required. Without this update, the existing pod-security policy restricts the usage of securityContext, hindering necessary operations. This aligns the behavior with CAPD, where the privileged policy is already set for Namespace objects.

I just wanted to clarify this a bit. Tilt-prepare already removes the security context from the deployments, but this is not enough if the namespace has enforced pod security standards. The issue is not visible for CAPI/CAPD since CAPD anyway uses the privileged policy in order to mount the docker socket. Other providers will likely be able to run with a restricted policy for the namespace, except when using Tilt. This is why we want to make tilt-prepare change the label on the namespace.

100% agree, this gets helpful when PSA is enforced in a clusters and we want to run a provider or the core CAPI providers using tilt.
Core CAPI controllers should be affected to, only CAPD not because it requires privileged anyway.

Edit: it comes down to that the reason for wanting this in tilt-prepare is this line in tilt-prepare:

container.SecurityContext = nil

@maxrantil maxrantil force-pushed the tilt-prepare-update-namespace-security-policy/max branch from aa7fc10 to a8e4f53 Compare February 20, 2024 11:13
@lentzi90
Copy link
Contributor

Good point! So the reason it is currently working for CAPI is that there are no restrictions on the namespace. Probably the same for many other providers.

@maxrantil maxrantil force-pushed the tilt-prepare-update-namespace-security-policy/max branch from a8e4f53 to cdbdeb2 Compare February 20, 2024 12:04
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Feb 20, 2024
Copy link
Contributor

@tuminoid tuminoid left a comment

Choose a reason for hiding this comment

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

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 8, 2024
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 7cd7cabbf76b59c96494ba7f5bad36da33982cb3

Copy link
Member

@chrischdi chrischdi left a comment

Choose a reason for hiding this comment

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

One last nit, let's add a comment on why we have to do this to provide future context.

@maxrantil maxrantil force-pushed the tilt-prepare-update-namespace-security-policy/max branch from c17656c to 03335e9 Compare March 8, 2024 17:20
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 8, 2024
@chrischdi
Copy link
Member

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 11, 2024
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 92cf5b3fa87d43dd1aec4c273f8892485401cc79

@k8s-ci-robot k8s-ci-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Mar 12, 2024
@maxrantil maxrantil force-pushed the tilt-prepare-update-namespace-security-policy/max branch from 28d9938 to abf180d Compare March 12, 2024 12:25
This commit updates the updateNamespaceSecurityStandard function to set the
pod-security.kubernetes.io/enforce label to 'privileged' for Namespace objects.

Signed-off-by: Max Rantil <max.rantil@est.tech>
Co-authored-by: Christian Schlotter <chrischdi@users.noreply.github.com>
@maxrantil maxrantil force-pushed the tilt-prepare-update-namespace-security-policy/max branch from abf180d to 8be5d93 Compare March 12, 2024 13:09
@maxrantil
Copy link
Contributor Author

/cc @killianmuldoon @JoelSpeed would any of you please be willing to do a review?

Copy link
Contributor

@tuminoid tuminoid left a comment

Choose a reason for hiding this comment

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

Readding LGTM after all comments so far have been resolved.

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 20, 2024
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: dc11a973b8c001a38361c1b5656ab20d9dbd884b

Copy link
Contributor

@killianmuldoon killianmuldoon left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

Thanks for this!

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: killianmuldoon

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 21, 2024
@k8s-ci-robot k8s-ci-robot merged commit 84aa52a into kubernetes-sigs:main Mar 21, 2024
25 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v1.7 milestone Mar 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/devtools Issues or PRs related to devtools cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants