Skip to content

Commit e9791e8

Browse files
Merge pull request #159 from ThatsMrTalbot/feat/openshift-security-context-contstraints
feat: add RBAC for OpenShift SecurityContextConstraints
2 parents 204bd2f + 0cd9f47 commit e9791e8

File tree

4 files changed

+84
-0
lines changed

4 files changed

+84
-0
lines changed

deploy/charts/csi-driver-spiffe/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,5 +501,23 @@ topologySpreadConstraints:
501501
app.kubernetes.io/instance: cert-manager
502502
app.kubernetes.io/component: controller
503503
```
504+
#### **openshift.securityContextConstraint.enabled** ~ `boolean,string,null`
505+
> Default value:
506+
> ```yaml
507+
> detect
508+
> ```
509+
510+
Include RBAC to allow the DaemonSet to "use" the specified
511+
SecurityContextConstraints.
512+
513+
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.
514+
515+
#### **openshift.securityContextConstraint.name** ~ `string`
516+
> Default value:
517+
> ```yaml
518+
> privileged
519+
> ```
520+
521+
Name of the SecurityContextConstraints to create RBAC for.
504522

505523
<!-- /AUTO-GENERATED -->

deploy/charts/csi-driver-spiffe/templates/clusterrole.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,25 @@ rules:
88
- apiGroups: ["cert-manager.io"]
99
resources: ["certificaterequests"]
1010
verbs: ["watch", "create", "delete", "list"]
11+
{{- /* If openshift.securityContextConstraint.enabled is set to "detect" then we
12+
need to check if its an OpenShift cluster. If it is an OpenShift cluster
13+
then it is "implicitly" enabled */}}
14+
{{- $securityContextConstraintImplicitlyEnabled := and (kindIs "string" .Values.openshift.securityContextConstraint.enabled) (eq .Values.openshift.securityContextConstraint.enabled "detect") (.Capabilities.APIVersions.Has "security.openshift.io/v1") }}
15+
16+
{{- /* If openshift.securityContextConstraint.enabled is a bool then we just use
17+
the user provided value. This is referred to here as being "explicitly"
18+
enabled */}}
19+
{{- $securityContextConstraintExplicitlyEnabled := and (kindIs "bool" .Values.openshift.securityContextConstraint.enabled) (.Values.openshift.securityContextConstraint.enabled) }}
20+
21+
{{- /* If the SecurityContextConstraint is either "implicitly" or "explicitly"
22+
enabled, we add the extra RBAC. */}}
23+
{{- $securityContextConstraintEnabled := or $securityContextConstraintImplicitlyEnabled $securityContextConstraintExplicitlyEnabled }}
24+
{{- if $securityContextConstraintEnabled }}
25+
- apiGroups: ["security.openshift.io"]
26+
resources: ["securitycontextconstraints"]
27+
resourceNames: [{{ .Values.openshift.securityContextConstraint.name | quote }}]
28+
verbs: ["use"]
29+
{{- end }}
1130
---
1231
kind: ClusterRole
1332
apiVersion: rbac.authorization.k8s.io/v1

deploy/charts/csi-driver-spiffe/values.schema.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
"nodeSelector": {
2525
"$ref": "#/$defs/helm-values.nodeSelector"
2626
},
27+
"openshift": {
28+
"$ref": "#/$defs/helm-values.openshift"
29+
},
2730
"priorityClassName": {
2831
"$ref": "#/$defs/helm-values.priorityClassName"
2932
},
@@ -558,6 +561,36 @@
558561
"description": "Kubernetes node selector: node labels for pod assignment.",
559562
"type": "object"
560563
},
564+
"helm-values.openshift": {
565+
"additionalProperties": false,
566+
"properties": {
567+
"securityContextConstraint": {
568+
"$ref": "#/$defs/helm-values.openshift.securityContextConstraint"
569+
}
570+
},
571+
"type": "object"
572+
},
573+
"helm-values.openshift.securityContextConstraint": {
574+
"additionalProperties": false,
575+
"properties": {
576+
"enabled": {
577+
"$ref": "#/$defs/helm-values.openshift.securityContextConstraint.enabled"
578+
},
579+
"name": {
580+
"$ref": "#/$defs/helm-values.openshift.securityContextConstraint.name"
581+
}
582+
},
583+
"type": "object"
584+
},
585+
"helm-values.openshift.securityContextConstraint.enabled": {
586+
"default": "detect",
587+
"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."
588+
},
589+
"helm-values.openshift.securityContextConstraint.name": {
590+
"default": "privileged",
591+
"description": "Name of the SecurityContextConstraints to create RBAC for.",
592+
"type": "string"
593+
},
561594
"helm-values.priorityClassName": {
562595
"default": "",
563596
"description": "Optional priority class to be used for the csi-driver pods.",

deploy/charts/csi-driver-spiffe/values.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,3 +269,17 @@ tolerations: []
269269
# app.kubernetes.io/instance: cert-manager
270270
# app.kubernetes.io/component: controller
271271
topologySpreadConstraints: []
272+
273+
openshift:
274+
securityContextConstraint:
275+
# Include RBAC to allow the DaemonSet to "use" the specified
276+
# SecurityContextConstraints.
277+
#
278+
# This value can either be a boolean true or false, or the string "detect".
279+
# If set to "detect" then the securityContextConstraint is automatically
280+
# enabled for openshift installs.
281+
#
282+
# +docs:type=boolean,string,null
283+
enabled: detect
284+
# Name of the SecurityContextConstraints to create RBAC for.
285+
name: privileged

0 commit comments

Comments
 (0)