Skip to content

Commit 5c3eaa6

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

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"strings"
3030
"sync"
3131

32+
secretsstore "sigs.k8s.io/secrets-store-csi-driver/pkg/secrets-store"
3233
"sigs.k8s.io/secrets-store-csi-driver/provider/v1alpha1"
3334
"sigs.k8s.io/secrets-store-csi-driver/test/e2eprovider/types"
3435

@@ -186,6 +187,10 @@ func (s *Server) Mount(ctx context.Context, req *v1alpha1.MountRequest) (*v1alph
186187
}
187188
}
188189

190+
if err := validateVolumeIDAttr(attrib); err != nil {
191+
return nil, fmt.Errorf("failed to validate volume ID, error: %w", err)
192+
}
193+
189194
m.Lock()
190195
podCache[attrib[podUIDAttribute]] = true
191196
m.Unlock()
@@ -266,3 +271,14 @@ func validateTokens(tokenAudiences, saTokens string) error {
266271
}
267272
return nil
268273
}
274+
275+
func validateVolumeIDAttr(attributes map[string]string) error {
276+
volumeID, ok := attributes[secretsstore.SecretStoreVolumeID]
277+
if !ok {
278+
return fmt.Errorf("volume ID is not set")
279+
}
280+
if volumeID == "" {
281+
return fmt.Errorf("volume ID is empty")
282+
}
283+
return nil
284+
}

0 commit comments

Comments
 (0)