This feature allows CSI drivers to impersonate the pods that they mount the volumes for. This improves the security posture in the mounting process where the volumes are ACL’ed on the pods’ service account without handing out unnecessary permissions to the CSI drivers’ service account. This feature is especially important for secret-handling CSI drivers, such as the secrets-store-csi-driver. Since these tokens can be rotated and short-lived, this feature also provides a knob for CSI drivers to receive NodePublishVolume RPC calls periodically with the new token. This knob is also useful when volumes are short-lived, e.g. certificates.
UsageSee more details at the design document.
This feature adds two fields in CSIDriver
spec:
type CSIDriverSpec struct {
... // existing fields
RequiresRepublish *bool
TokenRequests []TokenRequest
}
type TokenRequest struct {
Audience string
ExpirationSeconds *int64
}
TokenRequest.Audience
:
APIAudiences
of kube-apiserver. one of the audiences specified.TokenRequest.ExpirationSeconds
:
1 << 32
seconds.RequiresRepublish
:
NodePublishVolume
will be periodically called. When used with TokenRequest
, the token will be refreshed if it expired. NodePublishVolume
should only change the contents rather than the mount because container will not be restarted to reflect the mount change. The period between NodePublishVolume
is 0.1s.The token will be bounded to the pod that the CSI driver is mounting volumes for and will be set in VolumeContext
:
"csi.storage.k8s.io/serviceAccount.tokens": {
<audience>: {
'token': <token>,
'expirationTimestamp': <expiration timestamp in RFC3339 format>,
},
...
}
If CSI driver doesn't find token recorded in the volume_context
, it should return error in NodePublishVolume
to inform Kubelet to retry.
Here is an example of a CSIDriver
object:
apiVersion: storage.k8s.io/v1
kind: CSIDriver
metadata:
name: mycsidriver.example.com
spec:
tokenRequests:
- audience: "gcp"
- audience: ""
expirationSeconds: 3600
requiresRepublish: true
Feature gate
Kube apiserver must start with the CSIServiceAccountToken
feature gate enabled:
--feature-gates=CSIServiceAccountToken=true
It is enabled by default in Kubernetes 1.21 and cannot be disabled since 1.22.
Example CSI DriversTokenReview
request to authenticate.RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4