Skip to content

Commit 4adcc79

Browse files
authored
Merge pull request #8551 from zalando-incubator/postgres-exec-2
Add an admitter that validates that unprivileged users cannot exec into postgres pods
2 parents 1ba8207 + 2bb083b commit 4adcc79

File tree

3 files changed

+47
-9
lines changed

3 files changed

+47
-9
lines changed

cluster/config-defaults.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -677,9 +677,9 @@ teapot_admission_controller_configmap_deletion_protection_factories_enabled: "tr
677677
# enable the rolebinding admission-controller webhook which validates rolebindings and clusterrolebindings
678678
teapot_admission_controller_enable_rolebinding_webhook: "true"
679679

680-
# enable the generic admission-controller webhook which catches all resources
681-
teapot_admission_controller_enable_generic_webhook: "false"
682-
# prevent write operations for non-admin users in protected namespaces
680+
# enable the generic deny-all admission webhook which rejects all requests it receives
681+
teapot_admission_controller_enable_write_protection_webhook: "false"
682+
# configure the behaviour of the deny-all admission webhook, `true` blocks everything, `false` allows everything
683683
teapot_admission_controller_prevent_write_operations: "false"
684684

685685
# Enable and configure Pod Security Policy rules implemented in admission-controller.

cluster/manifests/01-admission-control/teapot.yaml

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,34 @@ webhooks:
267267
apiVersions: ["v1"]
268268
resources: ["rolebindings", "clusterrolebindings"]
269269
{{- end }}
270-
{{- if eq .Cluster.ConfigItems.teapot_admission_controller_enable_generic_webhook "true" }}
271-
- name: generic-namespaced-admitter.teapot.zalan.do
270+
{{- if eq .Cluster.ConfigItems.teapot_admission_controller_enable_write_protection_webhook "true" }}
271+
- name: pod-exec-admitter.teapot.zalan.do
272272
clientConfig:
273-
url: "https://localhost:8085/generic"
273+
url: "https://localhost:8085/pod/exec"
274+
caBundle: "{{ .Cluster.ConfigItems.ca_cert_decompressed }}"
275+
admissionReviewVersions: ["v1beta1"]
276+
failurePolicy: Fail
277+
sideEffects: "NoneOnDryRun"
278+
matchPolicy: Equivalent
279+
namespaceSelector:
280+
matchExpressions:
281+
- key: kubernetes.io/metadata.name
282+
operator: NotIn
283+
values: [ "kube-system", "visibility", "kubenurse" ]
284+
rules:
285+
- operations: [ "CONNECT" ]
286+
apiGroups: [""]
287+
apiVersions: ["v1"]
288+
resources: ["pods/exec"]
289+
scope: "Namespaced"
290+
matchConditions:
291+
- name: 'exclude-privileged-groups'
292+
expression: 'request.userInfo.groups.all(g, !(g in ["okta:common/administrator", "zalando:administrator"]))'
293+
- name: 'exclude-postgres-admins'
294+
expression: 'request.userInfo.groups.all(g, !(g in ["okta:common/postgres-admin"]))'
295+
- name: namespaced-deny-admitter.teapot.zalan.do
296+
clientConfig:
297+
url: "https://localhost:8085/deny"
274298
caBundle: "{{ .Cluster.ConfigItems.ca_cert_decompressed }}"
275299
admissionReviewVersions: ["v1beta1"]
276300
failurePolicy: Fail
@@ -287,9 +311,16 @@ webhooks:
287311
apiVersions: ["*"]
288312
resources: ["*/*"]
289313
scope: "Namespaced"
290-
- name: generic-cluster-admitter.teapot.zalan.do
314+
matchConditions:
315+
- name: 'exclude-privileged-groups'
316+
expression: 'request.userInfo.groups.all(g, !(g in ["system:masters", "system:nodes", "system:serviceaccounts:kube-system", "okta:common/administrator", "zalando:administrator"]))'
317+
- name: 'exclude-privileged-usernames'
318+
expression: '!(request.userInfo.username in ["system:kube-controller-manager", "system:kube-scheduler", "zalando-iam:zalando:service:k8sapi_credentials-provider"])'
319+
- name: 'exclude-eks-components'
320+
expression: '!request.userInfo.username.startsWith("eks:")'
321+
- name: global-deny-admitter.teapot.zalan.do
291322
clientConfig:
292-
url: "https://localhost:8085/generic"
323+
url: "https://localhost:8085/deny"
293324
caBundle: "{{ .Cluster.ConfigItems.ca_cert_decompressed }}"
294325
admissionReviewVersions: ["v1beta1"]
295326
failurePolicy: Fail
@@ -304,4 +335,11 @@ webhooks:
304335
apiVersions: ["*"]
305336
resources: ["*/*"]
306337
scope: "Cluster"
338+
matchConditions:
339+
- name: 'exclude-privileged-groups'
340+
expression: 'request.userInfo.groups.all(g, !(g in ["system:masters", "system:nodes", "system:serviceaccounts:kube-system", "okta:common/administrator", "zalando:administrator"]))'
341+
- name: 'exclude-privileged-usernames'
342+
expression: '!(request.userInfo.username in ["system:kube-controller-manager", "system:kube-scheduler", "zalando-iam:zalando:service:k8sapi_credentials-provider"])'
343+
- name: 'exclude-eks-components'
344+
expression: '!request.userInfo.username.startsWith("eks:")'
307345
{{- end }}

cluster/node-pools/master-default/userdata.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ write_files:
206206
limits:
207207
memory: {{ .Values.InstanceInfo.MemoryFraction (parseInt64 .Cluster.ConfigItems.apiserver_memory_limit_percent)}}
208208
{{- end }}
209-
- image: 926694233939.dkr.ecr.eu-central-1.amazonaws.com/production_namespace/teapot/admission-controller:master-224
209+
- image: 926694233939.dkr.ecr.eu-central-1.amazonaws.com/production_namespace/teapot/admission-controller:master-227
210210
name: admission-controller
211211
lifecycle:
212212
preStop:

0 commit comments

Comments
 (0)