Skip to content

Commit

Permalink
Backport of auth/kubernetes: support for dynamically reloading short-…
Browse files Browse the repository at this point in the history
…lived tokens into release/1.9.x (#13698)

* auth/kubernetes: support for dynamically reloading short-lived tokens (#13595)

* auth/kubernetes: support for short-lived tokens

* Uplift new version of Kubernetes auth plugin that does not store the
  service account token persistently to Vault storage.

* Update the documentation to recommend local token again when running
  Vault inside cluster.

Signed-off-by: Tero Saarni <tero.saarni@est.tech>

* Added changelog entry

Signed-off-by: Tero Saarni <tero.saarni@est.tech>

* clarification to changelog entry, executed go mod tidy

* clarifications and added targeted release version

* update available version to 1.9.3+ and changelog

renamed changelog file to the backport pr number.

* update go.mod to k8s-auth@v0.11.4

Co-authored-by: Tero Saarni <tero.saarni@est.tech>
Co-authored-by: Theron Voran <tvoran@users.noreply.github.com>
  • Loading branch information
3 people committed Jan 22, 2022
1 parent b118c8a commit 38c074a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 6 deletions.
3 changes: 3 additions & 0 deletions changelog/13698.txt
@@ -0,0 +1,3 @@
```release-note:improvement
auth/kubernetes: Added support for dynamically reloading short-lived tokens for better Kubernetes 1.21+ compatibility
```
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -96,7 +96,7 @@ require (
github.com/hashicorp/vault-plugin-auth-gcp v0.11.3
github.com/hashicorp/vault-plugin-auth-jwt v0.11.4
github.com/hashicorp/vault-plugin-auth-kerberos v0.5.0
github.com/hashicorp/vault-plugin-auth-kubernetes v0.11.3
github.com/hashicorp/vault-plugin-auth-kubernetes v0.11.4
github.com/hashicorp/vault-plugin-auth-oci v0.9.0
github.com/hashicorp/vault-plugin-database-couchbase v0.5.1
github.com/hashicorp/vault-plugin-database-elasticsearch v0.9.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Expand Up @@ -942,8 +942,8 @@ github.com/hashicorp/vault-plugin-auth-jwt v0.11.4 h1:rL/hvd7uGB8CGpw1FKxxUD/dBJ
github.com/hashicorp/vault-plugin-auth-jwt v0.11.4/go.mod h1:jzjDdssus8sw8G6NOP7kNFMEeIvrjXvPHUR3pEn5+r0=
github.com/hashicorp/vault-plugin-auth-kerberos v0.5.0 h1:oORxeqOraVVLQrb+z3fj5JayPmH/JBxJWGywZ8ZRJt0=
github.com/hashicorp/vault-plugin-auth-kerberos v0.5.0/go.mod h1:eqjae8tMBpAWgJNk1NjV/vtJYXQRZnYudUkBFowz3bY=
github.com/hashicorp/vault-plugin-auth-kubernetes v0.11.3 h1:VTl62rRNhcALzsLw8romBZfTRpVna2IeLTN0kAQyXvY=
github.com/hashicorp/vault-plugin-auth-kubernetes v0.11.3/go.mod h1:HNcW9fnQIKw9g5qnxRQn6pHfGnSuVwBJAGb/v2/2dvw=
github.com/hashicorp/vault-plugin-auth-kubernetes v0.11.4 h1:qtmDVB9A9iloGg1URpDU9NxRaPi4gCLE7CComDlLQP8=
github.com/hashicorp/vault-plugin-auth-kubernetes v0.11.4/go.mod h1:HNcW9fnQIKw9g5qnxRQn6pHfGnSuVwBJAGb/v2/2dvw=
github.com/hashicorp/vault-plugin-auth-oci v0.9.0 h1:5wuHuPsW/MM5x0yvbr5ZwFLviNdF7q2t+z9saL7zjcI=
github.com/hashicorp/vault-plugin-auth-oci v0.9.0/go.mod h1:Cn5cjR279Y+snw8LTaiLTko3KGrbigRbsQPOd2D5xDw=
github.com/hashicorp/vault-plugin-database-couchbase v0.5.1 h1:WsXcOHHVwphwsrNGxpxRHcFzVgApN17ZNiE5RVD+q78=
Expand Down
2 changes: 2 additions & 0 deletions website/content/api-docs/auth/kubernetes.mdx
Expand Up @@ -29,8 +29,10 @@ access the Kubernetes API.

- `kubernetes_host` `(string: <required>)` - Host must be a host string, a host:port pair, or a URL to the base of the Kubernetes API server.
- `kubernetes_ca_cert` `(string: "")` - PEM encoded CA cert for use by the TLS client used to talk with the Kubernetes API. NOTE: Every line must end with a newline: `\n`
If not set, the local CA cert will be used if running in a Kubernetes pod.
- `token_reviewer_jwt` `(string: "")` - A service account JWT used to access the TokenReview
API to validate other JWTs during login. If not set,
the local service account token is used if running in a Kubernetes pod, otherwise
the JWT submitted in the login payload will be used to access the Kubernetes TokenReview API.
- `pem_keys` `(array: [])` - Optional list of PEM-formatted public keys or certificates
used to verify the signatures of Kubernetes service account
Expand Down
25 changes: 22 additions & 3 deletions website/content/docs/auth/kubernetes.mdx
Expand Up @@ -125,9 +125,8 @@ Kubernetes auth:
* The value of the JWT's `"iss"` claim depends on the cluster's configuration.

The changes to token lifetime are important when configuring the
[`token_reviewer_jwt`](/api-docs/auth/kubernetes#token_reviewer_jwt) option. You
must avoid using a short-lived token because Vault stores that token in Vault
storage and does not automatically refresh it. If a short-lived token is used,
[`token_reviewer_jwt`](/api-docs/auth/kubernetes#token_reviewer_jwt) option.
If a short-lived token is used,
Kubernetes will revoke it as soon as the pod or service account are deleted, or
if the expiry time passes, and Vault will no longer be able to use the
`TokenReview` API. See [How to work with short-lived Kubernetes tokens][short-lived-tokens]
Expand Down Expand Up @@ -155,6 +154,7 @@ table summarizes the options, each of which is explained in more detail below.

| Option | All tokens are short-lived | Can revoke tokens early | Other considerations |
| ------------------------------------ | -------------------------- | ----------------------- | -------------------- |
| Use local token as reviewer JWT | Yes | Yes | Requires Vault (1.9.3+) to be deployed on the Kubernetes cluster |
| Use client JWT as reviewer JWT | Yes | Yes | Operational overhead |
| Use long-lived token as reviewer JWT | No | Yes | |
| Use JWT auth instead | Yes | No | |
Expand All @@ -168,6 +168,25 @@ short-lived tokens. If you would like to disable this, set

[k8s-extended-tokens]: https://kubernetes.io/docs/reference/command-line-tools-reference/kube-apiserver/#options

#### Use local service account token as the reviewer JWT

When running Vault in a Kubernetes pod the recommended option is to use the pod's local
service account token. Vault will periodically re-read the file to support
short-lived tokens. To use the local token and CA certificate, omit
`token_reviewer_jwt` and `kubernetes_ca_cert` when configuring the auth method.
Vault will attempt to load them from `token` and `ca.crt` respectively inside
the default mount folder `/var/run/secrets/kubernetes.io/serviceaccount/`.

```bash
vault write auth/kubernetes/config \
kubernetes_host=https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_PORT
```

!> **Note:** Requires Vault 1.9.3+. In earlier versions the service account
token and CA certificate is read once and stored in Vault storage.
When the service account token expires or is revoked, Vault will no longer be
able to use the `TokenReview` API and client authentication will fail.

#### Use the Vault client's JWT as the reviewer JWT

When configuring Kubernetes auth, you can omit the `token_reviewer_jwt`, and Vault
Expand Down

0 comments on commit 38c074a

Please sign in to comment.