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

Ephemeral service account tokens for Vault #93

Merged
merged 3 commits into from
Dec 5, 2019

Conversation

lawrencejones
Copy link
Contributor

Kubernetes service account tokens, by default, are not rotated. Our
Vault authentication chain requires that Kubernetes pods send their
tokens to the Vault server, outside of the Kubernetes cluster.

If a token was to be compromised in that exchange, the attacker would be
able to impersonate this Kubernetes service account indefinitely. This
is a significant security risk.

This commit changes our mutating webhook to mount service account
credentials using the kubelet projected volume mounts API. This API uses
the kubelet to inject ephemeral service account tokens that are rotated
periodically into the containers. We can use these tokens to
authenticate against Vault, instead of tokens that are never revoked.

In addition, we can set an audience for the projected token to be
something other than the Kubernetes API server. This would prevent any
leaked tokens being used for anything other than authenticating with
Vault. While we don't use this at present, as our Vault installation
relies on using this token to reflect token review requests back to the
API server, we may switch to this in future if we think the security
benefit is compelling.

@lawrencejones lawrencejones force-pushed the lawrence-use-ephemeral-service-account-tokens branch 4 times, most recently from ab886d2 to 3c73e8b Compare December 5, 2019 12:08
mountPath: /var/run/secrets/kubernetes.io/vault
`

const annotatedPodYAML = `
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lawrencejones lawrencejones force-pushed the lawrence-use-ephemeral-service-account-tokens branch from 3c73e8b to 2284e94 Compare December 5, 2019 15:11
Copy link
Contributor

@jace-ys jace-ys left a comment

Choose a reason for hiding this comment

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

just one nitpick but other than that LGTM

serviceAccountName: secret-reader
restartPolicy: Never
containers:
- name: app
Copy link
Contributor

Choose a reason for hiding this comment

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

think this should be print-env to match the YAML above, but this shouldn't affect the test

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep good point, I'll change them to match (though I'll go with app in both cases, as that's what we like to use)

@lawrencejones lawrencejones force-pushed the lawrence-use-ephemeral-service-account-tokens branch from 2284e94 to 5636407 Compare December 5, 2019 17:08
Kubernetes service account tokens, by default, are not rotated. Our
Vault authentication chain requires that Kubernetes pods send their
tokens to the Vault server, outside of the Kubernetes cluster.

If a token was to be compromised in that exchange, the attacker would be
able to impersonate this Kubernetes service account indefinitely. This
is a significant security risk.

This commit changes our mutating webhook to mount service account
credentials using the kubelet projected volume mounts API. This API uses
the kubelet to inject ephemeral service account tokens that are rotated
periodically into the containers. We can use these tokens to
authenticate against Vault, instead of tokens that are never revoked.

In addition, we can set an audience for the projected token to be
something other than the Kubernetes API server. This would prevent any
leaked tokens being used for anything other than authenticating with
Vault. While we don't use this at present, as our Vault installation
relies on using this token to reflect token review requests back to the
API server, we may switch to this in future if we think the security
benefit is compelling.
@lawrencejones lawrencejones force-pushed the lawrence-use-ephemeral-service-account-tokens branch from 5636407 to babfc14 Compare December 5, 2019 17:09
We now only apply the envconsul-injector webhook to namespaces with this
label, so we must add it if we want our tests to work.
@lawrencejones lawrencejones merged commit d1ed55a into master Dec 5, 2019
@lawrencejones lawrencejones deleted the lawrence-use-ephemeral-service-account-tokens branch December 5, 2019 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants