diff --git a/docs/pages/reference/helm-reference/teleport-cluster.mdx b/docs/pages/reference/helm-reference/teleport-cluster.mdx index 2470d0798369c..4a3bd6cf140ee 100644 --- a/docs/pages/reference/helm-reference/teleport-cluster.mdx +++ b/docs/pages/reference/helm-reference/teleport-cluster.mdx @@ -2082,6 +2082,23 @@ See [the GitHub PR](https://github.com/gravitational/teleport/pull/36251) for te memory: 2Gi ``` +## `podSecurityContext` + +| Type | Default value | +|----------|---------------| +| `object` | `{}` | + +[Kubernetes reference](https://kubernetes.io/docs/concepts/security/pod-security-standards/) + +The `podSecurityContext` applies to the main Teleport pods. + +`values.yaml` example: + + ```yaml + podSecurityContext: + fsGroup: 65532 + ``` + ## `securityContext` | Type | Default value | diff --git a/examples/chart/teleport-cluster/.lint/pod-security-context-empty.yaml b/examples/chart/teleport-cluster/.lint/pod-security-context-empty.yaml new file mode 100644 index 0000000000000..14ff54654e53b --- /dev/null +++ b/examples/chart/teleport-cluster/.lint/pod-security-context-empty.yaml @@ -0,0 +1 @@ +clusterName: helm-lint diff --git a/examples/chart/teleport-cluster/.lint/pod-security-context.yaml b/examples/chart/teleport-cluster/.lint/pod-security-context.yaml new file mode 100644 index 0000000000000..50710c44fa3ac --- /dev/null +++ b/examples/chart/teleport-cluster/.lint/pod-security-context.yaml @@ -0,0 +1,7 @@ +clusterName: helm-lint +podSecurityContext: + fsGroup: 99 + fsGroupChangePolicy: OnRootMismatch + runAsGroup: 99 + runAsNonRoot: true + runAsUser: 99 diff --git a/examples/chart/teleport-cluster/templates/auth/deployment.yaml b/examples/chart/teleport-cluster/templates/auth/deployment.yaml index 85c8ed999ea70..7dc0901694fdc 100644 --- a/examples/chart/teleport-cluster/templates/auth/deployment.yaml +++ b/examples/chart/teleport-cluster/templates/auth/deployment.yaml @@ -293,6 +293,9 @@ spec: {{- end }} {{- if $auth.priorityClassName }} priorityClassName: {{ $auth.priorityClassName }} +{{- end }} +{{- if $auth.podSecurityContext }} + securityContext: {{- toYaml $auth.podSecurityContext | nindent 8 }} {{- end }} serviceAccountName: {{ include "teleport-cluster.auth.serviceAccountName" . }} terminationGracePeriodSeconds: {{ $auth.terminationGracePeriodSeconds }} diff --git a/examples/chart/teleport-cluster/templates/proxy/deployment.yaml b/examples/chart/teleport-cluster/templates/proxy/deployment.yaml index cbdbbe3feccff..fc55fdd58f7b3 100644 --- a/examples/chart/teleport-cluster/templates/proxy/deployment.yaml +++ b/examples/chart/teleport-cluster/templates/proxy/deployment.yaml @@ -324,6 +324,9 @@ spec: {{- end }} {{- if $proxy.priorityClassName }} priorityClassName: {{ $proxy.priorityClassName }} +{{- end }} +{{- if $proxy.podSecurityContext }} + securityContext: {{- toYaml $proxy.podSecurityContext | nindent 8 }} {{- end }} serviceAccountName: {{ include "teleport-cluster.proxy.serviceAccountName" . }} terminationGracePeriodSeconds: {{ $proxy.terminationGracePeriodSeconds }} diff --git a/examples/chart/teleport-cluster/tests/auth_deployment_test.yaml b/examples/chart/teleport-cluster/tests/auth_deployment_test.yaml index a74f5c569f512..6f158540d23a7 100644 --- a/examples/chart/teleport-cluster/tests/auth_deployment_test.yaml +++ b/examples/chart/teleport-cluster/tests/auth_deployment_test.yaml @@ -126,6 +126,35 @@ tests: - matchSnapshot: path: spec.template.spec + - it: should set podSecurityContext when set in values + template: auth/deployment.yaml + values: + - ../.lint/pod-security-context.yaml + asserts: + - equal: + path: spec.template.spec.securityContext.fsGroup + value: 99 + - equal: + path: spec.template.spec.securityContext.fsGroupChangePolicy + value: OnRootMismatch + - equal: + path: spec.template.spec.securityContext.runAsGroup + value: 99 + - equal: + path: spec.template.spec.securityContext.runAsNonRoot + value: true + - equal: + path: spec.template.spec.securityContext.runAsUser + value: 99 + + - it: should not set podSecurityContext when is empty object (default value) + template: auth/deployment.yaml + values: + - ../.lint/pod-security-context-empty.yaml + asserts: + - isNull: + path: spec.template.spec.securityContext + - it: should set securityContext when set in values template: auth/deployment.yaml values: diff --git a/examples/chart/teleport-cluster/tests/proxy_deployment_test.yaml b/examples/chart/teleport-cluster/tests/proxy_deployment_test.yaml index 7d8a12553f3d8..486bc87918488 100644 --- a/examples/chart/teleport-cluster/tests/proxy_deployment_test.yaml +++ b/examples/chart/teleport-cluster/tests/proxy_deployment_test.yaml @@ -164,6 +164,35 @@ tests: - matchSnapshot: path: spec.template.spec + - it: should set podSecurityContext when set in values + template: proxy/deployment.yaml + values: + - ../.lint/pod-security-context.yaml + asserts: + - equal: + path: spec.template.spec.securityContext.fsGroup + value: 99 + - equal: + path: spec.template.spec.securityContext.fsGroupChangePolicy + value: OnRootMismatch + - equal: + path: spec.template.spec.securityContext.runAsGroup + value: 99 + - equal: + path: spec.template.spec.securityContext.runAsNonRoot + value: true + - equal: + path: spec.template.spec.securityContext.runAsUser + value: 99 + + - it: should not set podSecurityContext when is empty object (default value) + template: proxy/deployment.yaml + values: + - ../.lint/pod-security-context-empty.yaml + asserts: + - isNull: + path: spec.template.spec.securityContext + - it: should set securityContext when set in values template: proxy/deployment.yaml values: diff --git a/examples/chart/teleport-cluster/values.schema.json b/examples/chart/teleport-cluster/values.schema.json index 675f9b5750636..657ae941d592b 100644 --- a/examples/chart/teleport-cluster/values.schema.json +++ b/examples/chart/teleport-cluster/values.schema.json @@ -943,6 +943,11 @@ "type": "object", "default": {} }, + "podSecurityContext": { + "$id": "#/properties/podSecurityContext", + "type": "object", + "default": {} + }, "securityContext": { "$id": "#/properties/securityContext", "type": "object", diff --git a/examples/chart/teleport-cluster/values.yaml b/examples/chart/teleport-cluster/values.yaml index c5c64ce491519..977919324e640 100644 --- a/examples/chart/teleport-cluster/values.yaml +++ b/examples/chart/teleport-cluster/values.yaml @@ -760,6 +760,10 @@ resources: {} # limits: # memory: "2Gi" +# Pod security context for any pods created by the chart +podSecurityContext: {} + # fsGroup: 65532 + # Security context to add to the container securityContext: {} # runAsUser: 99