Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GCP config: gke-exec-auth-plugin for ValidatingAdmissionWebhook #79553

Merged
merged 1 commit into from Jul 23, 2019

Conversation

ahmedtd
Copy link
Contributor

@ahmedtd ahmedtd commented Jun 29, 2019

This commit adds support for using gke-exec-auth-plugin for webhooks when calling endpoints matching *.googleapis.com, and integrates this support with ValidatingAdmissionWebhook.

To enable it, request ValidatingAdmissionWebhook with ADMISSION_CONTROL=...,ValidatingAdmissionWebhook,... (default) and opt in to gke-exec-auth-plugin using WEBHOOK_GKE_EXEC_AUTH=true during the configuration process.

If you don't opt-in, ValidatingAdmissionWebhook will be deployed as before.

Requesting WEBHOOK_GKE_EXEC_AUTH=true will fail if you have not provided other configuration variables:

  • EXEC_AUTH_PLUGIN_URL: controls whether gke-exec-auth-plugin is downloaded during the installation step. A prerequisite for actually using the plugin.

  • TOKEN_URL, TOKEN_BODY, and TOKEN_BODY_UNQUOTED: configuration values used when calling the plugin. TOKEN_URL and TOKEN_BODY have existing usage.
    TOKEN_BODY_UNQUOTED is a new variable that is meant to sidestep the problem of inverting strconv.Quote in Bash.

The existing configuration process for ImagePolicyWebhook has been reworked to make it play nicely with ValidatingAdmissionWebhook under WEBHOOK_GKE_EXEC_AUTH=true:

  • It originally placed the ImagePolicyWebhook configuration object at the top-level of the file specified by --admission-control-config-file. I can't see why this worked; it must have been hitting some sort of lucky path through the various config file loading mechanisms. Now, it places its configuration in a sub-field of that file, which is shared among all admission control plugins.

  • It mounted its various config files read-write. I reviewed the code and couldn't see why it was necessary, so I moved the config files into the existing read-only mount at /etc/srv/kubernetes.

  • It now checks that all the configuration values it requires have been provided, rather than silently writing out a broken config.

/kind feature

NONE

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. kind/feature Categorizes issue or PR as related to a new feature. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Jun 29, 2019
@k8s-ci-robot
Copy link
Contributor

Hi @ahmedtd. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jun 29, 2019
@k8s-ci-robot k8s-ci-robot added sig/cluster-lifecycle Categorizes an issue or PR as relevant to SIG Cluster Lifecycle. sig/gcp and removed needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Jun 29, 2019
@ahmedtd ahmedtd force-pushed the binauthz branch 8 times, most recently from 3977fab to 7587265 Compare June 30, 2019 08:34
@ahmedtd ahmedtd changed the title GCP config: Support AdmissionWebhook plugin GCP config: gke-exec-auth-plugin for ValidatingAdmissionWebhook Jun 30, 2019
@ahmedtd ahmedtd force-pushed the binauthz branch 4 times, most recently from da55df9 to f6e47b5 Compare July 2, 2019 01:48
@ahmedtd
Copy link
Contributor Author

ahmedtd commented Jul 2, 2019

/assign @MrHohn @yguo0905

@ahmedtd
Copy link
Contributor Author

ahmedtd commented Jul 2, 2019

/retest

cluster/gce/gci/configure-helper.sh Show resolved Hide resolved
plugins:
EOF

if [[ ${ADMISSION_CONTROL:-} == *"ImagePolicyWebhook"* ]]; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe worth to log when a admission control config is enabled?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added some log messages, but these blocks aren't enabling the admission control plugins. The admission control plugins are enabled by inclusion in ADMISSION_CONTROL, which get included in the apiserver command line around line 1801 of configure-helper.sh.

These blocks are just "noticing" that the caller requested admission control plugins that might require special setup.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, what you describe is more accurate. Thanks for the logs.

# kubeconfig to be used by webhooks with GKE exec auth support. Note that
# the path to gke-exec-auth-plugin is the path when mounted inside the
# kube-apiserver pod.
cat <<EOF >/etc/srv/kubernetes/webhook_kubeconfig.yaml
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: make this end with .kubeconfig to be consistent?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

if [[ -n "${GCP_IMAGE_VERIFICATION_URL:-}" ]]; then
# This is the config file for the image review webhook.
cat <<EOF >/etc/gcp_image_review.config
if [[ ${WEBHOOK_GKE_EXEC_AUTH:-} ]]; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indent mismatch?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

# kubeconfig to be used by webhooks with GKE exec auth support. Note that
# the path to gke-exec-auth-plugin is the path when mounted inside the
# kube-apiserver pod.
cat <<EOF >/etc/srv/kubernetes/webhook_kubeconfig.yaml
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this kubeconfig be ever needed by something other than the exec auth admission plugin? If not, should it fall under the same if [[ ${ADMISSION_CONTROL:-} == *"ImagePolicyWebhook"* ]] bucket?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

webhook.kubeconfig should be usable for any webhook that needs to call to *.googleapis.com. For example, MutatingAdmissionWebhook.

I didn't want to go through and add the kubeconfig to a bunch of other webhooks that we're not planning on exercising regularly --- ValidatingAdmissionWebhook will be using this kubeconfig as part of our binary authorization feature.

# gke-exec-auth-plugin needs to be mounted into the kube-apiserver container.
local webhook_exec_auth_plugin_mount=""
local webhook_exec_auth_plugin_volume=""
if [[ ${WEBHOOK_GKE_EXEC_AUTH:-} ]]; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a bit concerning that the logic for exec webhook are scattered among a couple places. Is there a specific reason the mount/volume setup has to be placed here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I was mostly following the existing organization of the file.

Note that this block isn't doing mounts for use by gke-exec-auth-plugin, rather it's mounting gke-exec-auth-plugin into the kube-apiserver container (so that the various webhooks can execute it). To do so, it needs to modify the kube-apiserver's static pod manifest, which is what this function is all about.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, thanks for the explanation :)

@ahmedtd
Copy link
Contributor Author

ahmedtd commented Jul 3, 2019

/retest

Copy link
Member

@MrHohn MrHohn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

plugins:
EOF

if [[ ${ADMISSION_CONTROL:-} == *"ImagePolicyWebhook"* ]]; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, what you describe is more accurate. Thanks for the logs.

# gke-exec-auth-plugin needs to be mounted into the kube-apiserver container.
local webhook_exec_auth_plugin_mount=""
local webhook_exec_auth_plugin_volume=""
if [[ ${WEBHOOK_GKE_EXEC_AUTH:-} ]]; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, thanks for the explanation :)

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 3, 2019
@ahmedtd
Copy link
Contributor Author

ahmedtd commented Jul 5, 2019

/test pull-kubernetes-kubemark-e2e-gce-big

@ahmedtd
Copy link
Contributor Author

ahmedtd commented Jul 5, 2019

/test pull-kubernetes-node-e2e-containerd

@ahmedtd
Copy link
Contributor Author

ahmedtd commented Jul 8, 2019

/unassign @yguo0905
/assign @mikedanese

@k8s-ci-robot k8s-ci-robot assigned mikedanese and unassigned yguo0905 Jul 8, 2019
fi

if [[ -z ${TOKEN_URL:-} || -z ${TOKEN_BODY:-} || -z ${TOKEN_BODY_UNQUOTED:-} ]]; then
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."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should be 1>&2 echo "....", but this file isn't consistent.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

args:
- --mode=alt-token
- --alt-token-url=${TOKEN_URL?}
- --alt-token-body=${TOKEN_BODY_UNQUOTED?}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Side note: we set -o nounset so the ? is the default behavior for parameter expansion, although no problem with being defensive.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

if [[ -n "${GCP_IMAGE_VERIFICATION_URL:-}" ]]; then
# This is the config file for the image review webhook.
cat <<EOF >/etc/gcp_image_review.config
if [[ ${WEBHOOK_GKE_EXEC_AUTH:-} ]]; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrap parameter expansions in quotes here and below. Be explicit about what the condition is checking a -n.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@mikedanese mikedanese added the priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. label Jul 11, 2019
@k8s-ci-robot k8s-ci-robot removed the needs-priority Indicates a PR lacks a `priority/foo` label and requires one. label Jul 11, 2019
@mikedanese mikedanese added needs-priority Indicates a PR lacks a `priority/foo` label and requires one. and removed lgtm "Looks good to me", indicates that a PR is ready to be merged. labels Jul 11, 2019
@mikedanese
Copy link
Member

Removed lgtm for you to get a chance to look at the comments.
/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ahmedtd, mikedanese

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 11, 2019
This commit adds support for using `gke-exec-auth-plugin` (vTPM-based
certificates for mTLS) for webhooks when calling endpoints matching
`*.googleapis.com`, and integrates this support with
ValidatingAdmissionWebhook.

To enable it, request ValidatingAdmissionWebhook with
`ADMISSION_CONTROL=...,ValidatingAdmissionWebhook,...` (default) and
opt in to `gke-exec-auth-plugin` using `WEBHOOK_GKE_EXEC_AUTH=true`
during the configuration process.

If you don't opt-in, ValidatingAdmissionWebhook will be deployed as
before.

Requesting `WEBHOOK_GKE_EXEC_AUTH=true` will fail if you have not
provided other configuration variables:

  * `EXEC_AUTH_PLUGIN_URL`: controls whether `gke-exec-auth-plugin` is
    downloaded during the installation step.  A prerequisite for
    actually using the plugin.

  * `TOKEN_URL`, `TOKEN_BODY`, and `TOKEN_BODY_UNQUOTED`:
    configuration values used when calling the plugin.  `TOKEN_URL`
    and `TOKEN_BODY` have existing usage. `TOKEN_BODY_UNQUOTED` is a
    new variable that is meant to sidestep the problem of inverting
    `strconv.Quote` in Bash.

The existing configuration process for ImagePolicyWebhook has been
reworked to make it play nicely with ValidatingAdmissionWebhook under
`WEBHOOK_GKE_EXEC_AUTH=true`.

  * It originally placed the ImagePolicyWebhook configuration object
    at the top-level of the file specified by
    `--admission-control-config-file`.  I can't see why this worked;
    it must have been hitting some sort of lucky path through the
    various config file loading mechanisms.  Now, it places its
    configuration in a sub-field of that file, which is shared among
    all admission control plugins.

  * It mounted its various config files read-write.  I reviewed the
    code and couldn't see why it was necessary, so I moved the config
    files into the existing read-only mount at `/etc/srv/kubernetes`.

  * It now checks that all the configuration values it requires have
    been provided.

Co-authored-by: Mike Danese <mikedanese@google.com>
Co-authored-by: Taahir Ahmed <taahm@google.com>
@mikedanese
Copy link
Member

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 23, 2019
@k8s-ci-robot k8s-ci-robot merged commit 5381bf5 into kubernetes:master Jul 23, 2019
@ahmedtd ahmedtd deleted the binauthz branch August 28, 2019 21:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. release-note-none Denotes a PR that doesn't merit a release note. sig/cluster-lifecycle Categorizes an issue or PR as relevant to SIG Cluster Lifecycle. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants