rancher-charts/charts/rancher-project-monitoring/2.1.0+up0.3.0/templates/rancher-monitoring/hardened.yaml

129 lines
4.1 KiB
YAML
Raw Normal View History

2023-05-26 21:24:11 +00:00
{{- $namespaces := dict "_0" .Release.Namespace -}}
apiVersion: batch/v1
kind: Job
metadata:
name: {{ template "project-prometheus-stack.fullname" . }}-patch-sa
namespace: {{ .Release.Namespace }}
labels:
app: {{ template "project-prometheus-stack.fullname" . }}-patch-sa
annotations:
"helm.sh/hook": post-install, post-upgrade
"helm.sh/hook-delete-policy": hook-succeeded, before-hook-creation
spec:
template:
metadata:
name: {{ template "project-prometheus-stack.fullname" . }}-patch-sa
labels:
app: {{ template "project-prometheus-stack.fullname" . }}-patch-sa
spec:
serviceAccountName: {{ template "project-prometheus-stack.fullname" . }}-patch-sa
{{- if .Values.global.kubectl.securityContext }}
securityContext: {{ toYaml .Values.global.kubectl.securityContext | nindent 8 }}
{{- end }}
restartPolicy: Never
nodeSelector: {{ include "linux-node-selector" . | nindent 8 }}
tolerations: {{ include "linux-node-tolerations" . | nindent 8 }}
containers:
{{- range $_, $ns := $namespaces }}
- name: patch-sa-{{ $ns }}
image: {{ template "system_default_registry" $ }}{{ $.Values.global.kubectl.repository }}:{{ $.Values.global.kubectl.tag }}
imagePullPolicy: {{ $.Values.global.kubectl.pullPolicy }}
command: ["kubectl", "patch", "serviceaccount", "default", "-p", "{\"automountServiceAccountToken\": false}"]
args: ["-n", "{{ $ns }}"]
{{- if $.Values.global.kubectl.resources }}
resources: {{ toYaml $.Values.global.kubectl.resources | nindent 10 }}
{{- end }}
{{- if $.Values.global.kubectl.containerSecurityContext }}
securityContext: {{ toYaml $.Values.global.kubectl.containerSecurityContext | nindent 10 }}
{{- end }}
{{- end }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: {{ template "project-prometheus-stack.fullname" . }}-patch-sa
labels:
app: {{ template "project-prometheus-stack.fullname" . }}-patch-sa
rules:
- apiGroups:
- ""
resources:
- serviceaccounts
verbs: ['get', 'patch']
{{- if .Values.global.cattle.psp.enabled }}
- apiGroups: ['policy']
resources: ['podsecuritypolicies']
verbs: ['use']
resourceNames:
- {{ template "project-prometheus-stack.fullname" . }}-patch-sa
{{- end }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: {{ template "project-prometheus-stack.fullname" . }}-patch-sa
labels:
app: {{ template "project-prometheus-stack.fullname" . }}-patch-sa
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: {{ template "project-prometheus-stack.fullname" . }}-patch-sa
subjects:
- kind: ServiceAccount
name: {{ template "project-prometheus-stack.fullname" . }}-patch-sa
namespace: {{ .Release.Namespace }}
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ template "project-prometheus-stack.fullname" . }}-patch-sa
namespace: {{ .Release.Namespace }}
labels:
app: {{ template "project-prometheus-stack.fullname" . }}-patch-sa
---
{{- if .Values.global.cattle.psp.enabled }}
apiVersion: policy/v1beta1
kind: PodSecurityPolicy
metadata:
name: {{ template "project-prometheus-stack.fullname" . }}-patch-sa
namespace: {{ .Release.Namespace }}
labels:
app: {{ template "project-prometheus-stack.fullname" . }}-patch-sa
spec:
privileged: false
hostNetwork: false
hostIPC: false
hostPID: false
runAsUser:
rule: 'MustRunAsNonRoot'
seLinux:
rule: 'RunAsAny'
supplementalGroups:
rule: 'MustRunAs'
ranges:
- min: 1
max: 65535
fsGroup:
rule: 'MustRunAs'
ranges:
- min: 1
max: 65535
readOnlyRootFilesystem: false
volumes:
- 'secret'
{{- end }}
{{- range $_, $ns := $namespaces }}
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: project-monitoring-policy
namespace: {{ $ns }}
spec:
podSelector: {}
ingress: {{- default (list dict | toYaml) (include "project-prometheus-stack.hardened.networkPolicy.ingress" (list $ $ns)) | nindent 4 }}
egress: {{- $.Values.global.networkPolicy.egress | toYaml | nindent 4 }}
policyTypes:
- Ingress
- Egress
{{- end }}