Skip to content

Commit 5428978

Browse files
committed
Add VolumeID to Mount request
Signed-off-by: Micah Hausler <[email protected]>
1 parent 1080aee commit 5428978

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

docs/book/src/providers.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@ The driver uses gRPC to communicate with the provider. To implement a secrets-st
3535

3636
See [design doc](https://docs.google.com/document/d/10-RHUJGM0oMN88AZNxjOmGz0NsWAvOYrWUEV-FbLWyw/edit?usp=sharing) for more details.
3737

38+
The `MountRequest` message structure includes several additional keys in the `Attributes` field that a provider can use when retrieving a secret. Keys beginning with `csi.storage.k8s.io` are [passed through from the Kubelet](https://kubernetes-csi.github.io/docs/pod-info.html?highlight=pod.name#pod-info-on-mount-with-csi-driver-object) if `podInfoOnMount` is `true` on the CSI driver.
39+
40+
| Attribute Key | Description |
41+
| --- | ---- |
42+
| `csi.storage.k8s.io/pod-name` | Pod name |
43+
| `csi.storage.k8s.io/pod.namespace` | Pod namespace |
44+
| `csi.storage.k8s.io/pod.uid` | Pod UID |
45+
| `csi.storage.k8s.io/serviceAccount.name` | The Pod's ServiceAccount name |
46+
| `csi.storage.k8s.io/serviceAccount.tokens` | A JSON structure serialized to a string containing service account tokens belonging to a pod [when a CSI driver has `tokenRequests` configured](https://kubernetes-csi.github.io/docs/token-requests.html). |
47+
| `secrets-store-csi-driver.sigs.k8s.io/volume.id` | The CSI Volume's ID from the `NodePublishVolumeRequest` call. This may be useful as a cache key if using Service Account tokens to fetch secrets. |
48+
49+
3850
## Features supported by current providers
3951

4052
| Features \ Providers | Azure | GCP | AWS | Vault | Akeyless | Conjur |

pkg/secrets-store/nodeserver.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ const (
6565
// CSIPodServiceAccountTokens is the service account tokens of the pod that the mount is created for
6666
CSIPodServiceAccountTokens = "csi.storage.k8s.io/serviceAccount.tokens" //nolint
6767

68+
SecretStoreVolumeID = "secrets-store-csi-driver.sigs.k8s.io/volume.id"
69+
6870
secretProviderClassField = "secretProviderClass"
6971
)
7072

@@ -181,6 +183,8 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
181183
for k, v := range attrib {
182184
parameters[k] = v
183185
}
186+
// Add the volume ID to the parameters
187+
parameters[SecretStoreVolumeID] = volumeID
184188
// csi.storage.k8s.io/serviceAccount.tokens is empty for Kubernetes version < 1.20.
185189
// For 1.20+, if tokenRequests is set in the CSI driver spec, kubelet will generate
186190
// a token for the pod and send it to the CSI driver.

test/e2eprovider/server/server.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ This is mock key
5050

5151
podUIDAttribute = "csi.storage.k8s.io/pod.uid"
5252
serviceAccountTokensAttribute = "csi.storage.k8s.io/serviceAccount.tokens" //nolint
53-
53+
secretStoreVolumeID = "secrets-store-csi-driver.sigs.k8s.io/volume.id"
5454
// RWMutex is to safely access podCache
5555
m sync.RWMutex
5656
)
@@ -186,6 +186,10 @@ func (s *Server) Mount(ctx context.Context, req *v1alpha1.MountRequest) (*v1alph
186186
}
187187
}
188188

189+
if err := validateVolumeIDAttr(attrib); err != nil {
190+
return nil, fmt.Errorf("failed to validate volume ID, error: %w", err)
191+
}
192+
189193
m.Lock()
190194
podCache[attrib[podUIDAttribute]] = true
191195
m.Unlock()
@@ -266,3 +270,14 @@ func validateTokens(tokenAudiences, saTokens string) error {
266270
}
267271
return nil
268272
}
273+
274+
func validateVolumeIDAttr(attributes map[string]string) error {
275+
volumeID, ok := attributes[secretStoreVolumeID]
276+
if !ok {
277+
return fmt.Errorf("volume ID is not set")
278+
}
279+
if volumeID == "" {
280+
return fmt.Errorf("volume ID is empty")
281+
}
282+
return nil
283+
}

0 commit comments

Comments
 (0)