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

Zarf overwrites namespace labels required when deploying to env with restricted pod security standard #2932

Closed
Ansible-man opened this issue Aug 27, 2024 · 11 comments · Fixed by #3036

Comments

@Ansible-man
Copy link
Contributor

Environment

Device and OS: RHEL 9
App version: 0.38.3
Kubernetes distro being used: rke2
Other:

Steps to reproduce

  1. Create zarf namespace with labels that allow it to run in an environment that enforces the restricted pod security standard
  2. Deploy Zarf with zarf init command (we use a custom package that only has the zarf agent based on iron bank images)

Expected result

  1. Zarf leaves the existing NS labels alone

Actual Result

Zarf removes the labels and fails to deploy due to non compliance

Visual Proof (screenshots, videos, text, etc)

Severity/Priority

medium

Additional Context

Add any other context or screenshots about the technical debt here.
Instead of requiring users to apply exceptions Zarf should natively comply with the Kubernetes restricted pod security standard. Especially when building it for a government use case.
Please see
https://kubernetes.io/docs/concepts/security/pod-security-standards/#restricted

@github-project-automation github-project-automation bot moved this to Backlog in Zarf Aug 27, 2024
@Ansible-man Ansible-man changed the title Zarf overwrites namespace labels required when deploying to env with restricted pod security profile Zarf overwrites namespace labels required when deploying to env with restricted pod security standard Aug 27, 2024
@AustinAbro321
Copy link
Contributor

AustinAbro321 commented Aug 27, 2024

Hey @Ansible-man just to make sure I understand you are talking specifically about the zarf namespace correct? You are pre-creating the zarf namespace with extra labels on it before running zarf init ?

@Ansible-man
Copy link
Contributor Author

Ansible-man commented Aug 28, 2024

Yes @AustinAbro321 . Please see
https://kubernetes.io/docs/concepts/security/pod-security-standards/
https://kubernetes.io/docs/concepts/security/pod-security-admission/
https://kubernetes.io/docs/concepts/security/pod-security-admission/#exemptions

Because PSA is enforcing the restricted Pod Security Level and Zarf does not apply security context to its deployment like

spec:
securityContext:
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
containers:

  • name: restricted-container
    image: nginx:1.19.8
    securityContext:
    allowPrivilegeEscalation: false
    capabilities:
    drop:
    - ALL
    runAsUser: 1000
    runAsGroup: 3000
    readOnlyRootFilesystem: true

We have to apply labels to the zarf namespace so the PSA will allow it to run

apiVersion: v1
kind: Namespace
metadata:
name: zarf
labels:
pod-security.kubernetes.io/enforce: privileged
pod-security.kubernetes.io/enforce-version: v1.25
pod-security.kubernetes.io/audit: privileged
pod-security.kubernetes.io/audit-version: v1.25
pod-security.kubernetes.io/warn: privileged
pod-security.kubernetes.io/warn-version: v1.25

@Ansible-man
Copy link
Contributor Author

I would be more than happy to do testing and put in a PR to apply the proper security context on the zarf-agent if its something you guys want. The root issue is Zarf not complying with the restricted pod security standard.

@AustinAbro321
Copy link
Contributor

@Ansible-man A PR to apply the proper security context on the Zarf agent would be great. I'm relatively certain we can adhere to the restricted level without breaking any functionality. Tests should catch it if so

@Ansible-man
Copy link
Contributor Author

@AustinAbro321 Sounds good, I will look into doing this in the next few days. Thanks

@Miaoxiang-philips
Copy link
Contributor

Hey @AustinAbro321 @Ansible-man , have any updates in there ? I have same problem too.

@Ansible-man
Copy link
Contributor Author

Ansible-man commented Sep 21, 2024 via email

@Ansible-man
Copy link
Contributor Author

@AustinAbro321 I have the code ready to commit, I can't seem to make a branch or access the slack channel. I read the contributing docs and I see where it says to create a draft PR but I am not able to make the branch for the draft PR.

@AustinAbro321
Copy link
Contributor

@Ansible-man Only members of the org can make a new branch in this repo, you'll have to create a fork

@Ansible-man
Copy link
Contributor Author

Tested the above in my rke2 cluster at home with the restricted PSS and all seemed to go well. We only deploy the zarf agent without any other components so I cannot speak to their compliance.

@Miaoxiang-philips
Copy link
Contributor

Tested the above in my rke2 cluster at home with the restricted PSS and all seemed to go well. We only deploy the zarf agent without any other components so I cannot speak to their compliance.

Hi @Ansible-man ,
Thanks, In fact, in my use case, the other components also need to be PSS compliant, which I've tried to do myself and tested successfully, so I'll create another PR to commit the code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants