Skip to content

feat: add RBAC for OpenShift SecurityContextConstraints #272

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

Conversation

ThatsMrTalbot
Copy link

@ThatsMrTalbot ThatsMrTalbot commented Jun 25, 2024

The CSI driver needs higher than normal perms, this falls foul of the default OpenShift SecurityContextConstraints.

This updates the helm chart to include RBAC to bind to the "privileged" SecurityContextConstraints.

This is what I found an official CSI driver doing, so it seemed like the correct behaviour:
https://github.com/search?q=repo%3Aopenshift%2Fsecrets-store-csi-driver-operator%20%20SecurityContextConstraints&type=code

@cert-manager-prow cert-manager-prow bot added dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jun 25, 2024
Copy link
Member

@SgtCoDFish SgtCoDFish left a comment

Choose a reason for hiding this comment

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

I like this idea and I wouldn't have thought of it!

Couple of minor nitpicks left; what do you think?

Comment on lines 167 to 168
# Name if the SecurityContextConstraints to create RBAC for.
name: privileged
Copy link
Member

Choose a reason for hiding this comment

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

nitpick: spelling

Suggested change
# Name if the SecurityContextConstraints to create RBAC for.
name: privileged
# Name of the SecurityContextConstraints to create RBAC for.
name: privileged

Copy link
Author

Choose a reason for hiding this comment

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

Fixed, I have made this exact typo so many times 🤣.

Comment on lines 11 to 13
{{- $securityContextConstraintImplicitlyEnabled := and (kindIs "string" .Values.openshift.securityContextConstraint.enabled) (eq .Values.openshift.securityContextConstraint.enabled "detect") (.Capabilities.APIVersions.Has "security.openshift.io/v1") }}
{{- $securityContextConstraintExplicitlyEnabled := and (kindIs "bool" .Values.openshift.securityContextConstraint.enabled) (.Values.openshift.securityContextConstraint.enabled) }}
{{- $securityContextConstraintEnabled := or $securityContextConstraintImplicitlyEnabled $securityContextConstraintExplicitlyEnabled }}
Copy link
Member

Choose a reason for hiding this comment

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

nitpick: I think this logic makes sense to me but given it's Helm template logic it's quite busy.

Could we add some template comments here in this file explaining what the logic is doing and why? I imagine users will quite often check the roles / clusterroles in a chart to see what permissions are enabled and especially for permissions which have "security" in them it would be helpful to be really clear about what's going on in the template

Copy link
Author

Choose a reason for hiding this comment

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

I have added some comments to make this clear

Copy link
Member

@SgtCoDFish SgtCoDFish 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

Tested locally, this looks correct to me!

$ helm template csi-driver ./deploy/charts/csi-driver  --api-versions security.openshift.io/v1

# contains the securitycontextconstraints

$ helm template csi-driver ./deploy/charts/csi-driver --set openshift.securityContextConstraint.enabled=true

# contains the securitycontextconstraints

$ helm template csi-driver ./deploy/charts/csi-driver --set openshift.securityContextConstraint.enabled=false --api-versions security.openshift.io/v1

# doesn't contain it

@cert-manager-prow cert-manager-prow bot added the lgtm Indicates that a PR is ready to be merged. label Jun 26, 2024
@cert-manager-prow
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: SgtCoDFish

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

@cert-manager-prow cert-manager-prow bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 26, 2024
@cert-manager-prow cert-manager-prow bot merged commit 33ec15c into cert-manager:main Jun 26, 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. dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. lgtm Indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants