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: add RBAC for OpenShift SecurityContextConstraints #159

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions deploy/charts/csi-driver-spiffe/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -501,5 +501,23 @@ topologySpreadConstraints:
app.kubernetes.io/instance: cert-manager
app.kubernetes.io/component: controller
```
#### **openshift.securityContextConstraint.enabled** ~ `boolean,string,null`
> Default value:
> ```yaml
> detect
> ```

Include RBAC to allow the DaemonSet to "use" the specified
SecurityContextConstraints.

This value can either be a boolean true or false, or the string "detect". If set to "detect" then the securityContextConstraint is automatically enabled for openshift installs.

#### **openshift.securityContextConstraint.name** ~ `string`
> Default value:
> ```yaml
> privileged
> ```

Name of the SecurityContextConstraints to create RBAC for.

<!-- /AUTO-GENERATED -->
19 changes: 19 additions & 0 deletions deploy/charts/csi-driver-spiffe/templates/clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,25 @@ rules:
- apiGroups: ["cert-manager.io"]
resources: ["certificaterequests"]
verbs: ["watch", "create", "delete", "list"]
{{- /* If openshift.securityContextConstraint.enabled is set to "detect" then we
need to check if its an OpenShift cluster. If it is an OpenShift cluster
then it is "implicitly" enabled */}}
{{- $securityContextConstraintImplicitlyEnabled := and (kindIs "string" .Values.openshift.securityContextConstraint.enabled) (eq .Values.openshift.securityContextConstraint.enabled "detect") (.Capabilities.APIVersions.Has "security.openshift.io/v1") }}

{{- /* If openshift.securityContextConstraint.enabled is a bool then we just use
the user provided value. This is referred to here as being "explicitly"
enabled */}}
{{- $securityContextConstraintExplicitlyEnabled := and (kindIs "bool" .Values.openshift.securityContextConstraint.enabled) (.Values.openshift.securityContextConstraint.enabled) }}

{{- /* If the SecurityContextConstraint is either "implicitly" or "explicitly"
enabled, we add the extra RBAC. */}}
{{- $securityContextConstraintEnabled := or $securityContextConstraintImplicitlyEnabled $securityContextConstraintExplicitlyEnabled }}
{{- if $securityContextConstraintEnabled }}
- apiGroups: ["security.openshift.io"]
resources: ["securitycontextconstraints"]
resourceNames: [{{ .Values.openshift.securityContextConstraint.name | quote }}]
verbs: ["use"]
{{- end }}
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
Expand Down
33 changes: 33 additions & 0 deletions deploy/charts/csi-driver-spiffe/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
"nodeSelector": {
"$ref": "#/$defs/helm-values.nodeSelector"
},
"openshift": {
"$ref": "#/$defs/helm-values.openshift"
},
"priorityClassName": {
"$ref": "#/$defs/helm-values.priorityClassName"
},
Expand Down Expand Up @@ -558,6 +561,36 @@
"description": "Kubernetes node selector: node labels for pod assignment.",
"type": "object"
},
"helm-values.openshift": {
"additionalProperties": false,
"properties": {
"securityContextConstraint": {
"$ref": "#/$defs/helm-values.openshift.securityContextConstraint"
}
},
"type": "object"
},
"helm-values.openshift.securityContextConstraint": {
"additionalProperties": false,
"properties": {
"enabled": {
"$ref": "#/$defs/helm-values.openshift.securityContextConstraint.enabled"
},
"name": {
"$ref": "#/$defs/helm-values.openshift.securityContextConstraint.name"
}
},
"type": "object"
},
"helm-values.openshift.securityContextConstraint.enabled": {
"default": "detect",
"description": "Include RBAC to allow the DaemonSet to \"use\" the specified\nSecurityContextConstraints.\n\nThis value can either be a boolean true or false, or the string \"detect\". If set to \"detect\" then the securityContextConstraint is automatically enabled for openshift installs."
},
"helm-values.openshift.securityContextConstraint.name": {
"default": "privileged",
"description": "Name of the SecurityContextConstraints to create RBAC for.",
"type": "string"
},
"helm-values.priorityClassName": {
"default": "",
"description": "Optional priority class to be used for the csi-driver pods.",
Expand Down
14 changes: 14 additions & 0 deletions deploy/charts/csi-driver-spiffe/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -269,3 +269,17 @@ tolerations: []
# app.kubernetes.io/instance: cert-manager
# app.kubernetes.io/component: controller
topologySpreadConstraints: []

openshift:
securityContextConstraint:
# Include RBAC to allow the DaemonSet to "use" the specified
# SecurityContextConstraints.
#
# This value can either be a boolean true or false, or the string "detect".
# If set to "detect" then the securityContextConstraint is automatically
# enabled for openshift installs.
#
# +docs:type=boolean,string,null
enabled: detect
# Name of the SecurityContextConstraints to create RBAC for.
name: privileged