This repository has been archived by the owner on Feb 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16.8k
/
deployment.yaml
220 lines (220 loc) · 7.38 KB
/
deployment.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ template "opa.fullname" . }}
labels:
{{ include "opa.labels.standard" . | indent 4 }}
spec:
replicas: {{ .Values.replicas }}
selector:
matchLabels:
app: {{ template "opa.fullname" . }}
{{- with .Values.deploymentStrategy }}
strategy:
{{- toYaml . | nindent 4 }}
{{- end }}
template:
metadata:
{{- if or .Values.generateAdmissionControllerCerts .Values.opa }}
annotations:
{{- if .Values.generateAdmissionControllerCerts }}
checksum/certs: {{ include (print $.Template.BasePath "/webhookconfiguration.yaml") . | sha256sum }}
{{- end }}
{{- if .Values.opa }}
checksum/config: {{ include (print $.Template.BasePath "/secrets.yaml") . | sha256sum }}
{{- end }}
{{- end }}
{{- if .Values.annotations }}
{{ toYaml .Values.annotations | indent 8 }}
{{- end }}
labels:
app: {{ template "opa.fullname" . }}
name: {{ template "opa.fullname" . }}
spec:
{{- if .Values.imagePullSecrets }}
imagePullSecrets:
{{- range .Values.imagePullSecrets }}
- name: {{ . }}
{{- end }}
{{- end }}
{{- if .Values.priorityClassName }}
priorityClassName: {{ .Values.priorityClassName }}
{{- end }}
{{- if or .Values.authz.enabled .Values.bootstrapPolicies}}
initContainers:
- name: initpolicy
image: {{ .Values.mgmt.image }}:{{ .Values.mgmt.imageTag }}
imagePullPolicy: {{ .Values.mgmt.imagePullPolicy }}
resources:
{{ toYaml .Values.mgmt.resources | indent 12 }}
command:
- /bin/sh
- -c
- |
{{- if .Values.authz.enabled }}
tr -dc 'A-F0-9' < /dev/urandom | dd bs=1 count=32 2>/dev/null > /bootstrap/mgmt-token
TOKEN=`cat /bootstrap/mgmt-token`
cat > /bootstrap/authz.rego <<EOF
package system.authz
default allow = false
# Allow anonymous access to the default policy decision.
allow { input.path = [""]; input.method = "POST" }
allow { input.path = [""]; input.method = "GET" }
# This is only used for health check in liveness and readiness probe
allow { input.path = ["health"]; input.method = "GET" }
{{- if .Values.prometheus.enabled }}
# This allows metrics to be scraped by prometheus
allow { input.path = ["metrics"]; input.method = "GET" }
{{- end }}
allow { input.identity == "$TOKEN" }
EOF
{{- end }}
{{- range $policyName, $policy := .Values.bootstrapPolicies }}
cat > /bootstrap/{{ $policyName }}.rego <<EOF
{{ $policy | indent 12 }}
EOF
{{- end }}
volumeMounts:
- name: bootstrap
mountPath: /bootstrap
{{- end }}
{{- if .Values.hostNetwork.enabled }}
hostNetwork: true
{{- end }}
containers:
- name: opa
ports:
- name: https
containerPort: {{ .Values.port }}
{{- if .Values.prometheus.enabled }}
- name: http
containerPort: {{ .Values.mgmt.port }}
{{- end }}
image: {{ .Values.image }}:{{ .Values.imageTag }}
imagePullPolicy: {{ .Values.imagePullPolicy }}
resources:
{{ toYaml .Values.resources | indent 12 }}
args:
- "run"
- "--server"
{{- if .Values.opa }}
- "--config-file=/config/config.yaml"
{{- end }}
- "--tls-cert-file=/certs/tls.crt"
- "--tls-private-key-file=/certs/tls.key"
- "--addr=0.0.0.0:{{ .Values.port }}"
- "--log-level={{ .Values.logLevel }}"
- "--log-format={{ .Values.logFormat }}"
{{- if .Values.authz.enabled }}
- "--authentication=token"
- "--authorization=basic"
- "--ignore=.*"
{{- end }}
{{- if .Values.prometheus.enabled }}
- "--addr=http://0.0.0.0:{{ .Values.mgmt.port }}"
{{- else if .Values.mgmt.enabled }}
- "--addr=http://127.0.0.1:{{ .Values.mgmt.port }}"
{{- end }}
{{- if or .Values.authz.enabled .Values.bootstrapPolicies }}
- "/bootstrap"
{{- end }}
{{- range .Values.extraArgs }}
- {{ . }}
{{- end }}
volumeMounts:
- name: certs
readOnly: true
mountPath: /certs
{{- if .Values.opa }}
- name: config
readOnly: true
mountPath: /config
{{- end }}
{{- if or .Values.authz.enabled .Values.bootstrapPolicies }}
- name: bootstrap
readOnly: true
mountPath: /bootstrap
{{- end }}
readinessProbe:
{{ toYaml .Values.readinessProbe | indent 12 }}
livenessProbe:
{{ toYaml .Values.livenessProbe | indent 12 }}
{{- if .Values.mgmt.enabled }}
- name: mgmt
image: {{ .Values.mgmt.image }}:{{ .Values.mgmt.imageTag }}
imagePullPolicy: {{ .Values.mgmt.imagePullPolicy }}
resources:
{{ toYaml .Values.mgmt.resources | indent 12 }}
args:
{{- if .Values.authz.enabled }}
- --opa-auth-token-file=/bootstrap/mgmt-token
{{- end }}
- --opa-url=http://127.0.0.1:{{ .Values.mgmt.port }}/v1
- --replicate-path={{ .Values.mgmt.replicate.path }}
- --enable-data={{ .Values.mgmt.data.enabled }}
- --enable-policies={{ .Values.mgmt.configmapPolicies.enabled }}
{{- if .Values.mgmt.configmapPolicies.enabled }}
- --policies={{ .Values.mgmt.configmapPolicies.namespaces | join "," }}
- --require-policy-label={{ .Values.mgmt.configmapPolicies.requireLabel }}
{{- end }}
{{- range .Values.mgmt.replicate.namespace }}
- --replicate={{ . }}
{{- end }}
{{- range .Values.mgmt.replicate.cluster }}
- --replicate-cluster={{ . }}
{{- end }}
{{- range .Values.mgmt.extraArgs }}
- {{ . }}
{{- end }}
{{- if or .Values.authz.enabled .Values.bootstrapPolicies }}
volumeMounts:
- name: bootstrap
readOnly: true
mountPath: /bootstrap
{{- end }}
{{- end }}
{{- if .Values.sar.enabled }}
- name: sarproxy
image: {{ .Values.sar.image }}:{{ .Values.sar.imageTag }}
imagePullPolicy: {{ .Values.sar.imagePullPolicy }}
resources:
{{ toYaml .Values.sar.resources | indent 12 }}
command:
- kubectl
- proxy
- --accept-paths=^/apis/authorization.k8s.io/v1/subjectaccessreviews$
{{- end }}
{{- if .Values.extraContainers }}
{{ toYaml .Values.extraContainers | indent 8}}
{{- end }}
{{- if .Values.securityContext.enabled }}
securityContext:
{{- range $key, $val := .Values.securityContext }}
{{- if ne $key "enabled" }}
{{ $key }}: {{ toYaml $val | nindent 10 }}
{{- end }}
{{- end }}
{{- end }}
serviceAccountName: {{ template "opa.serviceAccountName" .}}
volumes:
- name: certs
secret:
secretName: {{ template "opa.fullname" . }}-cert
{{- if .Values.opa }}
- name: config
secret:
secretName: {{ template "opa.fullname" . }}-config
{{- end }}
{{- if or .Values.authz.enabled .Values.bootstrapPolicies}}
- name: bootstrap
emptyDir: {}
{{- if .Values.extraVolumes }}
{{ toYaml .Values.extraVolumes | indent 8}}
{{- end }}
{{- end }}
affinity:
{{ toYaml .Values.affinity | indent 8 }}
nodeSelector:
{{ toYaml .Values.nodeSelector | indent 8 }}
tolerations:
{{ toYaml .Values.tolerations | indent 8 }}