diff --git a/chart/questions.yml b/chart/questions.yml index f53caa3..ec8a685 100644 --- a/chart/questions.yml +++ b/chart/questions.yml @@ -338,3 +338,9 @@ WARNING: DO NOT CHANGE THIS SETTING WITH ATTACHED VOLUMES.' max: 32767 show_if: "service.ui.type=NodePort||service.ui.type=LoadBalancer" label: UI Service NodePort number +- variable: podSecurityPolicy.enabled + default: "true" + description: "Configure a custom pod security policy for the Longhorn namespace." + label: Pod Security Policy + type: boolean + group: "Other Settings" \ No newline at end of file diff --git a/chart/templates/psp.yaml b/chart/templates/psp.yaml new file mode 100644 index 0000000..7bd0a56 --- /dev/null +++ b/chart/templates/psp.yaml @@ -0,0 +1,66 @@ +{{- if .Values.podSecurityPolicy.enabled }} +apiVersion: policy/v1beta1 +kind: PodSecurityPolicy +metadata: + name: longhorn-psp + labels: {{- include "longhorn.labels" . | nindent 4 }} +spec: + privileged: true + allowPrivilegeEscalation: true + requiredDropCapabilities: + - NET_RAW + allowedCapabilities: + - SYS_ADMIN + hostNetwork: false + hostIPC: false + hostPID: true + runAsUser: + rule: RunAsAny + seLinux: + rule: RunAsAny + fsGroup: + rule: RunAsAny + supplementalGroups: + rule: RunAsAny + volumes: + - configMap + - downwardAPI + - emptyDir + - secret + - projected + - hostPath +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: Role +metadata: + name: longhorn-psp-role + labels: {{- include "longhorn.labels" . | nindent 4 }} + namespace: {{ .Release.Namespace }} +rules: +- apiGroups: + - policy + resources: + - podsecuritypolicies + verbs: + - use + resourceNames: + - longhorn-psp +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: longhorn-psp-binding + labels: {{- include "longhorn.labels" . | nindent 4 }} + namespace: {{ .Release.Namespace }} +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: Role + name: longhorn-psp-role +subjects: +- kind: ServiceAccount + name: longhorn-service-account + namespace: {{ .Release.Namespace }} +- kind: ServiceAccount + name: default + namespace: {{ .Release.Namespace }} +{{- end }} \ No newline at end of file diff --git a/chart/values.yaml b/chart/values.yaml index 1899dc5..3ac9446 100644 --- a/chart/values.yaml +++ b/chart/values.yaml @@ -118,3 +118,7 @@ ingress: # - name: longhorn.local-tls # key: # certificate: + +# Setup pod security policy in the Longhorn namespace to allow privileged pods +podSecurityPolicy: + enabled: true