Skip to content

Commit 5381bf5

Browse files
authored
Merge pull request kubernetes#79553 from ahmedtd/binauthz
GCP config: gke-exec-auth-plugin for ValidatingAdmissionWebhook
2 parents f101466 + 9702c6e commit 5381bf5

File tree

2 files changed

+93
-32
lines changed

2 files changed

+93
-32
lines changed

cluster/gce/gci/configure-helper.sh

Lines changed: 91 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -758,9 +758,55 @@ contexts:
758758
EOF
759759
fi
760760

761-
if [[ -n "${GCP_IMAGE_VERIFICATION_URL:-}" ]]; then
762-
# This is the config file for the image review webhook.
763-
cat <<EOF >/etc/gcp_image_review.config
761+
if [[ -n "${WEBHOOK_GKE_EXEC_AUTH:-}" ]]; then
762+
if [[ -z "${EXEC_AUTH_PLUGIN_URL:-}" ]]; then
763+
1>&2 echo "You requested GKE exec auth support for webhooks, but EXEC_AUTH_PLUGIN_URL was not specified. This configuration depends on gke-exec-auth-plugin for authenticating to the webhook endpoint."
764+
exit 1
765+
fi
766+
767+
if [[ -z "${TOKEN_URL:-}" || -z "${TOKEN_BODY:-}" || -z "${TOKEN_BODY_UNQUOTED:-}" ]]; then
768+
1>&2 echo "You requested GKE exec auth support for webhooks, but TOKEN_URL, TOKEN_BODY, and TOKEN_BODY_UNQUOTED were not provided. gke-exec-auth-plugin requires these values for its configuration."
769+
exit 1
770+
fi
771+
772+
# kubeconfig to be used by webhooks with GKE exec auth support. Note that
773+
# the path to gke-exec-auth-plugin is the path when mounted inside the
774+
# kube-apiserver pod.
775+
cat <<EOF >/etc/srv/kubernetes/webhook.kubeconfig
776+
apiVersion: v1
777+
kind: Config
778+
users:
779+
- name: '*.googleapis.com'
780+
user:
781+
exec:
782+
apiVersion: "client.authentication.k8s.io/v1alpha1"
783+
command: /usr/bin/gke-exec-auth-plugin
784+
args:
785+
- --mode=alt-token
786+
- --alt-token-url=${TOKEN_URL}
787+
- --alt-token-body=${TOKEN_BODY_UNQUOTED}
788+
EOF
789+
fi
790+
791+
if [[ -n "${ADMISSION_CONTROL:-}" ]]; then
792+
# Emit a basic admission control configuration file, with no plugins specified.
793+
cat <<EOF >/etc/srv/kubernetes/admission_controller_config.yaml
794+
apiVersion: apiserver.k8s.io/v1alpha1
795+
kind: AdmissionConfiguration
796+
plugins:
797+
EOF
798+
799+
if [[ "${ADMISSION_CONTROL:-}" == *"ImagePolicyWebhook"* ]]; then
800+
if [[ -z "${GCP_IMAGE_VERIFICATION_URL:-}" ]]; then
801+
1>&2 echo "The ImagePolicyWebhook admission control plugin was requested, but GCP_IMAGE_VERIFICATION_URL was not provided."
802+
exit 1
803+
fi
804+
805+
1>&2 echo "ImagePolicyWebhook admission control plugin requested. Configuring it to point at ${GCP_IMAGE_VERIFICATION_URL}"
806+
807+
# ImagePolicyWebhook does not use gke-exec-auth-plugin for authenticating
808+
# to the webhook endpoint. Emit its special kubeconfig.
809+
cat <<EOF >/etc/srv/kubernetes/gcp_image_review.kubeconfig
764810
clusters:
765811
- name: gcp-image-review-server
766812
cluster:
@@ -777,15 +823,37 @@ contexts:
777823
user: kube-apiserver
778824
name: webhook
779825
EOF
780-
# This is the config for the image review admission controller.
781-
cat <<EOF >/etc/admission_controller.config
782-
imagePolicy:
783-
kubeConfigFile: /etc/gcp_image_review.config
784-
allowTTL: 30
785-
denyTTL: 30
786-
retryBackoff: 500
787-
defaultAllow: true
826+
827+
# Append config for ImagePolicyWebhook to the shared admission controller
828+
# configuration file.
829+
cat <<EOF >>/etc/srv/kubernetes/admission_controller_config.yaml
830+
- name: ImagePolicyWebhook
831+
configuration:
832+
imagePolicy:
833+
kubeConfigFile: /etc/srv/kubernetes/gcp_image_review.kubeconfig
834+
allowTTL: 30
835+
denyTTL: 30
836+
retryBackoff: 500
837+
defaultAllow: true
838+
EOF
839+
fi
840+
841+
# If GKE exec auth for webhooks has been requested, then
842+
# ValidatingAdmissionWebhook should use it. Otherwise, run with the default
843+
# config.
844+
if [[ "${ADMISSION_CONTROL:-}" == *"ValidatingAdmissionWebhook"* && -n "${WEBHOOK_GKE_EXEC_AUTH:-}" ]]; then
845+
1>&2 echo "ValidatingAdmissionWebhook requested, and WEBHOOK_GKE_EXEC_AUTH specified. Configuring ValidatingAdmissionWebhook to use gke-exec-auth-plugin."
846+
847+
# Append config for ValidatingAdmissionWebhook to the shared admission
848+
# controller configuration file.
849+
cat <<EOF >>/etc/srv/kubernetes/admission_controller_config.yaml
850+
- name: ValidatingAdmissionWebhook
851+
configuration:
852+
apiVersion: apiserver.config.k8s.io/v1alpha1
853+
kind: WebhookAdmission
854+
kubeConfigFile: /etc/srv/kubernetes/webhook.kubeconfig
788855
EOF
856+
fi
789857
fi
790858
}
791859

@@ -1731,21 +1799,18 @@ function start-kube-apiserver {
17311799
params+=" --kubelet-certificate-authority=${CA_CERT_BUNDLE_PATH}"
17321800
fi
17331801

1734-
local admission_controller_config_mount=""
1735-
local admission_controller_config_volume=""
1736-
local image_policy_webhook_config_mount=""
1737-
local image_policy_webhook_config_volume=""
17381802
if [[ -n "${ADMISSION_CONTROL:-}" ]]; then
17391803
params+=" --admission-control=${ADMISSION_CONTROL}"
1740-
if [[ ${ADMISSION_CONTROL} == *"ImagePolicyWebhook"* ]]; then
1741-
params+=" --admission-control-config-file=/etc/admission_controller.config"
1742-
# Mount the file to configure admission controllers if ImagePolicyWebhook is set.
1743-
admission_controller_config_mount="{\"name\": \"admissioncontrollerconfigmount\",\"mountPath\": \"/etc/admission_controller.config\", \"readOnly\": false},"
1744-
admission_controller_config_volume="{\"name\": \"admissioncontrollerconfigmount\",\"hostPath\": {\"path\": \"/etc/admission_controller.config\", \"type\": \"FileOrCreate\"}},"
1745-
# Mount the file to configure the ImagePolicyWebhook's webhook.
1746-
image_policy_webhook_config_mount="{\"name\": \"imagepolicywebhookconfigmount\",\"mountPath\": \"/etc/gcp_image_review.config\", \"readOnly\": false},"
1747-
image_policy_webhook_config_volume="{\"name\": \"imagepolicywebhookconfigmount\",\"hostPath\": {\"path\": \"/etc/gcp_image_review.config\", \"type\": \"FileOrCreate\"}},"
1748-
fi
1804+
params+=" --admission-control-config-file=/etc/srv/kubernetes/admission_controller_config.yaml"
1805+
fi
1806+
1807+
# If GKE exec auth support is requested for webhooks, then
1808+
# gke-exec-auth-plugin needs to be mounted into the kube-apiserver container.
1809+
local webhook_exec_auth_plugin_mount=""
1810+
local webhook_exec_auth_plugin_volume=""
1811+
if [[ -n "${WEBHOOK_GKE_EXEC_AUTH:-}" ]]; then
1812+
webhook_exec_auth_plugin_mount='{"name": "gkeauth", "mountPath": "/usr/bin/gke-exec-auth-plugin", "readOnly": true},'
1813+
webhook_exec_auth_plugin_volume='{"name": "gkeauth", "hostPath": {"path": "/home/kubernetes/bin/gke-exec-auth-plugin", "type": "File"}},'
17491814
fi
17501815

17511816
if [[ -n "${KUBE_APISERVER_REQUEST_TIMEOUT:-}" ]]; then
@@ -1867,10 +1932,8 @@ function start-kube-apiserver {
18671932
sed -i -e "s@{{audit_policy_config_volume}}@${audit_policy_config_volume}@g" "${src_file}"
18681933
sed -i -e "s@{{audit_webhook_config_mount}}@${audit_webhook_config_mount}@g" "${src_file}"
18691934
sed -i -e "s@{{audit_webhook_config_volume}}@${audit_webhook_config_volume}@g" "${src_file}"
1870-
sed -i -e "s@{{admission_controller_config_mount}}@${admission_controller_config_mount}@g" "${src_file}"
1871-
sed -i -e "s@{{admission_controller_config_volume}}@${admission_controller_config_volume}@g" "${src_file}"
1872-
sed -i -e "s@{{image_policy_webhook_config_mount}}@${image_policy_webhook_config_mount}@g" "${src_file}"
1873-
sed -i -e "s@{{image_policy_webhook_config_volume}}@${image_policy_webhook_config_volume}@g" "${src_file}"
1935+
sed -i -e "s@{{webhook_exec_auth_plugin_mount}}@${webhook_exec_auth_plugin_mount}@g" "${src_file}"
1936+
sed -i -e "s@{{webhook_exec_auth_plugin_volume}}@${webhook_exec_auth_plugin_volume}@g" "${src_file}"
18741937

18751938
cp "${src_file}" "${ETC_MANIFESTS:-/etc/kubernetes/manifests}"
18761939
}

cluster/gce/manifests/kube-apiserver.manifest

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@
6565
{{webhook_authn_config_mount}}
6666
{{audit_policy_config_mount}}
6767
{{audit_webhook_config_mount}}
68-
{{admission_controller_config_mount}}
69-
{{image_policy_webhook_config_mount}}
68+
{{webhook_exec_auth_plugin_mount}}
7069
{ "name": "srvkube",
7170
"mountPath": "/etc/srv/kubernetes",
7271
"readOnly": true},
@@ -106,8 +105,7 @@
106105
{{webhook_authn_config_volume}}
107106
{{audit_policy_config_volume}}
108107
{{audit_webhook_config_volume}}
109-
{{admission_controller_config_volume}}
110-
{{image_policy_webhook_config_volume}}
108+
{{webhook_exec_auth_plugin_volume}}
111109
{ "name": "srvkube",
112110
"hostPath": {
113111
"path": "/etc/srv/kubernetes"}

0 commit comments

Comments
 (0)