|
| 1 | +# Service Account Token Volumes |
| 2 | + |
| 3 | +Authors: |
| 4 | + @smarterclayton |
| 5 | + @liggitt |
| 6 | + @mikedanese |
| 7 | + |
| 8 | +## Summary |
| 9 | + |
| 10 | +Kubernetes is able to provide pods with unique identity tokens that can prove |
| 11 | +the caller is a particular pod to a Kubernetes API server. These tokens are |
| 12 | +injected into pods as secrets. This proposal proposes a new mechanism of |
| 13 | +distribution with support for [improved service account tokens][better-tokens] |
| 14 | +and explores how to migrate from the existing mechanism backwards compatibly. |
| 15 | + |
| 16 | +## Motivation |
| 17 | + |
| 18 | +Many workloads running on Kubernetes need to prove to external parties who they |
| 19 | +are in order to participate in a larger application environment. This identity |
| 20 | +must be attested to by the orchestration system in a way that allows a third |
| 21 | +party to trust that an arbitrary container on the cluster is who it says it is. |
| 22 | +In addition, infrastructure running on top of Kubernetes needs a simple |
| 23 | +mechanism to communicate with the Kubernetes APIs and to provide more complex |
| 24 | +tooling. Finally, a significant set of security challenges are associated with |
| 25 | +storing service account tokens as secrets in Kubernetes and limiting the methods |
| 26 | +whereby malicious parties can get access to these tokens will reduce the risk of |
| 27 | +platform compromise. |
| 28 | + |
| 29 | +As a platform, Kubernetes should evolve to allow identity management systems to |
| 30 | +provide more powerful workload identity without breaking existing use cases, and |
| 31 | +provide a simple out of the box workload identity that is sufficient to cover |
| 32 | +the requirements of bootstrapping low-level infrastructure running on |
| 33 | +Kubernetes. We expect that other systems to cover the more advanced scenarios, |
| 34 | +and see this effort as necessary glue to allow more powerful systems to succeed. |
| 35 | + |
| 36 | +With this feature, we hope to provide a backwards compatible replacement for |
| 37 | +service account tokens that strengthens the security and improves the |
| 38 | +scalability of the platform. |
| 39 | + |
| 40 | +## Proposal |
| 41 | + |
| 42 | +Kubernetes should implement a ServiceAccountToken volume projection that |
| 43 | +maintains a service account token requested by the node from the TokenRequest |
| 44 | +API. |
| 45 | + |
| 46 | +### Token Volume Projection |
| 47 | + |
| 48 | +A new volume projection will be implemented with an API that closely matches the |
| 49 | +TokenRequest API. |
| 50 | + |
| 51 | +```go |
| 52 | +type ProjectedVolumeSource struct { |
| 53 | + Sources []VolumeProjection |
| 54 | + DefaultMode *int32 |
| 55 | +} |
| 56 | + |
| 57 | +type VolumeProjection struct { |
| 58 | + Secret *SecretProjection |
| 59 | + DownwardAPI *DownwardAPIProjection |
| 60 | + ConfigMap *ConfigMapProjection |
| 61 | + ServiceAccountToken *ServiceAccountTokenProjection |
| 62 | +} |
| 63 | + |
| 64 | +// ServiceAccountTokenProjection represents a projected service account token |
| 65 | +// volume. This projection can be used to insert a service account token into |
| 66 | +// the pods runtime filesystem for use against APIs (Kubernetes API Server or |
| 67 | +// otherwise). |
| 68 | +type ServiceAccountTokenProjection struct { |
| 69 | + // Audience is the intended audience of the token. A recipient of a token |
| 70 | + // must identify itself with an identifier specified in the audience of the |
| 71 | + // token, and otherwise should reject the token. |
| 72 | + Audience string |
| 73 | + // ExpirationSeconds is the requested duration of validity of the service |
| 74 | + // account token. As the token approaches expiration, the kubelet volume |
| 75 | + // plugin will proactively rotate the service account token. The kubelet will |
| 76 | + // start trying to rotate the token if the token is older than 80 percent of |
| 77 | + // its time to live or if the token is older than 24 hours.Defaults to 1 hour |
| 78 | + // and must be at least 10 minutes. |
| 79 | + ExpirationSeconds int64 |
| 80 | + // Path is the relative path of the file to project the token into. |
| 81 | + Path string |
| 82 | +} |
| 83 | +``` |
| 84 | + |
| 85 | +A volume plugin implemented in the kubelet will project a service account token |
| 86 | +sourced from the TokenRequest API into volumes created from |
| 87 | +ProjectedVolumeSources. As the token approaches expiration, the kubelet volume |
| 88 | +plugin will proactively rotate the service account token. The kubelet will start |
| 89 | +trying to rotate the token if the token is older than 80 percent of its time to |
| 90 | +live or if the token is older than 24 hours. |
| 91 | + |
| 92 | +To replace the current service account token secrets, we also need to inject the |
| 93 | +clusters CA certificate bundle. Initially we will deploy to data in a configmap |
| 94 | +per-namespace and reference it using a ConfigMapProjection. |
| 95 | + |
| 96 | +A projected volume source that is equivalent to the current service account |
| 97 | +secret: |
| 98 | + |
| 99 | +```yaml |
| 100 | +sources: |
| 101 | +- serviceAccountToken: |
| 102 | + expirationSeconds: 3153600000 # 100 years |
| 103 | + path: token |
| 104 | +- configMap: |
| 105 | + name: kube-cacrt |
| 106 | + items: |
| 107 | + - key: ca.crt |
| 108 | + path: ca.crt |
| 109 | +- downwardAPI: |
| 110 | + items: |
| 111 | + - path: namespace |
| 112 | + fieldRef: metadata.namespace |
| 113 | +``` |
| 114 | +
|
| 115 | +
|
| 116 | +This fixes one scalability issue with the current service account token |
| 117 | +deployment model where secret GETs are a large portion of overall apiserver |
| 118 | +traffic. |
| 119 | +
|
| 120 | +A projected volume source that requests a token for vault and Istio CA: |
| 121 | +
|
| 122 | +```yaml |
| 123 | +sources: |
| 124 | +- serviceAccountToken: |
| 125 | + path: vault-token |
| 126 | + audience: vault |
| 127 | +- serviceAccountToken: |
| 128 | + path: istio-token |
| 129 | + audience: ca.istio.io |
| 130 | +``` |
| 131 | +
|
| 132 | +### Alternatives |
| 133 | +
|
| 134 | +1. Instead of implementing a service account token volume projection, we could |
| 135 | + implement all injection as a flex volume or CSI plugin. |
| 136 | + 1. Both flex volume and CSI are alpha and are unlikely to graduate soon. |
| 137 | + 1. Virtual kubelets (like Fargate or ACS) may not be able to run flex |
| 138 | + volumes. |
| 139 | + 1. Service account tokens are a fundamental part of our API. |
| 140 | +1. Remove service accounts and service account tokens completely from core, use |
| 141 | + an alternate mechanism that sits outside the platform. |
| 142 | + 1. Other core features need service account integration, leading to all |
| 143 | + users needing to install this extension. |
| 144 | + 1. Complicates installation for the majority of users. |
| 145 | +
|
| 146 | +
|
| 147 | +[better-tokens]: https://github.com/kubernetes/community/blob/master/contributors/design-proposals/auth/bound-service-account-tokens.md |
0 commit comments