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

Set readOnlyRootFilesystem: true for the controller and webhook containers to improve default security posture #2219

Draft
wants to merge 17 commits into
base: master
Choose a base branch
from

Conversation

npgretz
Copy link
Contributor

@npgretz npgretz commented Oct 4, 2024

🛑 Important:

Please open an issue to discuss significant work before you start. We appreciate your contributions and don't want your efforts to go to waste!

For guidelines on how to contribute, please review the CONTRIBUTING.md document.

Purpose of this PR

Provide a clear and concise description of the changes. Explain the motivation behind these changes and link to relevant issues or discussions.

By default, the controller and webhook containers write to their filesystems. DevOpSec at multiple organizations using the spark-operator chart require Kubernetes container security contexts to prohibit writing to the root filesystem ( Slack Conversation, Issue for Improved Security)

This PR will allow the spark-operator chart to be deployed with a read-only root filesystem to improve the default security posture and meet the requirements of users.

Proposed changes:

  • Add an empty directory onto the webhook containers to create certs in
  • Add an empty directory onto the controller containers to write Spark artifacts for Spark apps
  • Set the default container security context for the webhook and controller to readOnlyRootFilesystem

Change Category

Indicate the type of change by marking the applicable boxes:

  • Bugfix (non-breaking change which fixes an issue)
  • Feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that could affect existing functionality)
  • Documentation update

Rationale

Multiple users of the Helm chart require an increased security posture in their Kubernetes deployments.

Checklist

Before submitting your PR, please review the following:

  • I have conducted a self-review of my own code.
  • I have updated documentation accordingly.
  • I have added tests that prove my changes are effective or that my feature works.
  • Existing unit tests pass locally with my changes.

Additional Notes

…its filesystem

Avoid writing to the rootFileSystem of the webhook container by mounting an empty dir where the webhook creates its certs. This improves the security posture of the webhook pod by allowing a securityContext with rootFilesystemReadOnly: true.

Signed-off-by: Nicholas Gretzon <[email protected]>
…ting its filesystem

Avoid writing to the rootFileSystem of the controller container by mounting an empty dir where the controller downloads Spark artifacts for spark apps. This improves the security posture of the controller pod by allowing a securityContext with rootFilesystemReadOnly: true.

Signed-off-by: Nicholas Gretzon <[email protected]>
…true

Improve the default security posture of the Helm chart deployment by preventing writes to container filesystems now that the controller and webhook pods no longer need to write to their filesystems.

Signed-off-by: Nicholas Gretzon <[email protected]>
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign yuchaoran2011 for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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

This is already done in the deployment.yaml for the controller.

Signed-off-by: Nicholas Gretzon <[email protected]>
@google-oss-prow google-oss-prow bot added size/M and removed size/S labels Oct 4, 2024
@cccsss01
Copy link

cccsss01 commented Oct 4, 2024

/lgtm
I can confirm this is working

Copy link
Contributor

@cccsss01: changing LGTM is restricted to collaborators

In response to this:

/lgtm
I can confirm this is working

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.

npgretz added 11 commits October 6, 2024 17:16
…r tmp dir and a webhook certs dir

Create the ability to disable the creation of a tmp directory for the controller pod to write Spark artifacts to when running Spark Applications and the ability to disable the creation of a directory for the webhook pod to write certificates in.

Signed-off-by: Nicholas Gretzon <[email protected]>
Create logic to add a volume and volumeMount to the controller pod if controllerTmpDirectory is enabled in the values.yaml

Signed-off-by: Nicholas Gretzon <[email protected]>
Create logic to add a volume and volumeMount to the webhook pod if webhookCertsDirectory is enabled in the values.yaml

Signed-off-by: Nicholas Gretzon <[email protected]>
…tory

Test the functionality of controllerTmpDirectory in the values.yaml to confirm the volumeMount and volume are created. The volume also should have the appropriate sizeLimit set.

Signed-off-by: Nicholas Gretzon <[email protected]>
Test the functionality of webhookCertsDirectory in the values.yaml to confirm the volumeMount and volume are created. The volume also should have the appropriate sizeLimit set.

Signed-off-by: Nicholas Gretzon <[email protected]>
Copy link

github-actions bot commented Jan 5, 2025

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

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

Successfully merging this pull request may close these issues.

2 participants