Skip to content

Commit

Permalink
Merge pull request #591 from andyzhangx/secret-name-field
Browse files Browse the repository at this point in the history
feat: add secretName in storage class parameters
  • Loading branch information
andyzhangx authored Dec 23, 2021
2 parents 7aef946 + a0a25f2 commit 7a9303d
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 8 deletions.
15 changes: 12 additions & 3 deletions docs/driver-parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@ skuName | Azure storage account type (alias: `storageAccountType`) | `Standard_L
location | Azure location | `eastus`, `westus`, etc. | No | if empty, driver will use the same location name as current k8s cluster
resourceGroup | Azure resource group name | existing resource group name | No | if empty, driver will use the same resource group name as current k8s cluster
storageAccount | specify Azure storage account name| STORAGE_ACCOUNT_NAME | - No for blobfuse mount </br> - Yes for NFSv3 mount | - For blobfuse mount: if empty, driver will find a suitable storage account that matches `skuName` in the same resource group; if a storage account name is provided, storage account must exist. </br> - For NFSv3 mount, storage account name must be provided
storeAccountKey | whether store account key to k8s secret | `true`,`false` | No | `true`
protocol | specify blobfuse mount or NFSv3 mount | `fuse`, `nfs` | No | `fuse`
containerName | specify the existing container name | existing container name | No | if empty, driver will create a new container name, starting with `pvc-fuse` for blobfuse or `pvc-nfs` for NFSv3
isHnsEnabled | enable `Hierarchical namespace` for Azure DataLake storage account(only for blobfuse) | `true`,`false` | No | `false`
server | specify Azure storage account server address | existing server address, e.g. `accountname.privatelink.blob.core.windows.net` | No | if empty, driver will use default `accountname.blob.core.windows.net` or other sovereign cloud account address
allowBlobPublicAccess | Allow or disallow public access to all blobs or containers for storage account created by driver | `true`,`false` | No | `false`
storageEndpointSuffix | specify Azure storage endpoint suffix | `core.windows.net` | No | if empty, driver will use default storage endpoint suffix according to cloud environment, e.g. `core.windows.net`
tags | [tags](https://docs.microsoft.com/en-us/azure/azure-resource-manager/management/tag-resources) would be created in newly created storage account | tag format: 'foo=aaa,bar=bbb' | No | ""
--- | **Following parameters are only for blobfuse** | --- | --- |
storeAccountKey | whether store account key to k8s secret <br><br> Note: <br> `false` means driver would leverage kubelet identity to get account key | `true`,`false` | No | `true`
secretName | specify secret name to store account key | | No |
secretNamespace | specify the namespace of secret to store account key | `default`,`kube-system`, etc | No | `default`
isHnsEnabled | enable `Hierarchical namespace` for Azure DataLake storage account | `true`,`false` | No | `false`

- `fsGroup` securityContext setting

Expand Down Expand Up @@ -54,8 +57,11 @@ volumeAttributes.resourceGroup | Azure resource group name | existing resource g
volumeAttributes.storageAccount | existing storage account name | existing storage account name | Yes |
volumeAttributes.containerName | existing container name | existing container name | Yes |
volumeAttributes.protocol | specify blobfuse mount or NFSv3 mount | `fuse`, `nfs` | No | `fuse`
--- | **Following parameters are only for blobfuse** | --- | --- |
volumeAttributes.secretName | secret name that stores storage account name and key(only applies for SMB) | | No |
volumeAttributes.secretNamespace | secret namespace | `default`,`kube-system`, etc | No | `default`
nodeStageSecretRef.name | secret name that stores(check below examples):<br>`azurestorageaccountkey`<br>`azurestorageaccountsastoken`<br>`msisecret`<br>`azurestoragespnclientsecret` | existing Kubernetes secret name | No |
nodeStageSecretRef.namespace | namespace where the secret is | k8s namespace | Yes |
nodeStageSecretRef.namespace | secret namespace | k8s namespace | Yes |
--- | **Following parameters are only for feature: blobfuse [Managed Identity and Service Principal Name auth](https://github.com/Azure/azure-storage-fuse#environment-variables)** | --- | --- |
volumeAttributes.AzureStorageAuthType | Authentication Type | `Key`, `SAS`, `MSI`, `SPN` | No | `Key`
volumeAttributes.AzureStorageIdentityClientID | Identity Client ID | | No |
Expand All @@ -70,6 +76,9 @@ volumeAttributes.keyVaultURL | Azure Key Vault DNS name | existing Azure Key Vau
volumeAttributes.keyVaultSecretName | Azure Key Vault secret name | existing Azure Key Vault secret name | No |
volumeAttributes.keyVaultSecretVersion | Azure Key Vault secret version | existing version | No |if empty, driver will use "current version"

- Note
- only mounting blobfuse requires account key, and if secret is not provided in PV config, driver would try to get `azure-storage-account-{accountname}-secret` in the pod namespace, if not found, driver would try using kubelet identity to get account key directly using Azure API.
- mounting blob storage NFSv3 does not need account key, it requires storage account configured with same vnet with agent node.

- create a Kubernetes secret for `nodeStageSecretRef.name`
```console
Expand Down
11 changes: 8 additions & 3 deletions pkg/blob/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -613,14 +613,19 @@ func setAzureCredentials(kubeClient kubernetes.Interface, accountName, accountKe
return secretName, err
}

// GetStorageAccesskey get Azure storage (account name, account key)
func (d *Driver) GetStorageAccesskey(ctx context.Context, accountOptions *azure.AccountOptions, secrets map[string]string, secretNamespace string) (string, string, error) {
// GetStorageAccesskey get Azure storage account key from
// 1. secrets (if not empty)
// 2. use k8s client identity to read from k8s secret
// 3. use cluster identity to get from storage account directly
func (d *Driver) GetStorageAccesskey(ctx context.Context, accountOptions *azure.AccountOptions, secrets map[string]string, secretName, secretNamespace string) (string, string, error) {
if len(secrets) > 0 {
return getStorageAccount(secrets)
}

// read from k8s secret first
secretName := fmt.Sprintf(secretNameTemplate, accountOptions.Name)
if secretName == "" {
secretName = fmt.Sprintf(secretNameTemplate, accountOptions.Name)
}
_, accountKey, err := d.GetStorageAccountFromSecret(secretName, secretNamespace)
if err != nil {
klog.V(2).Infof("could not get account(%s) key from secret(%s) namespace(%s), error: %v, use cluster identity to get account key instead", accountOptions.Name, secretName, secretNamespace, err)
Expand Down
6 changes: 4 additions & 2 deletions pkg/blob/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
if parameters == nil {
parameters = make(map[string]string)
}
var storageAccountType, resourceGroup, location, account, containerName, protocol, customTags, secretNamespace string
var storageAccountType, resourceGroup, location, account, containerName, protocol, customTags, secretName, secretNamespace string
var isHnsEnabled *bool
// set allowBlobPublicAccess as false by default
allowBlobPublicAccess := to.BoolPtr(false)
Expand Down Expand Up @@ -94,6 +94,8 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
protocol = v
case tagsField:
customTags = v
case secretNameField:
secretName = v
case secretNamespaceField:
secretNamespace = v
case isHnsEnabledField:
Expand Down Expand Up @@ -224,7 +226,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
accountOptions.Name = accountName

if accountKey == "" {
if accountName, accountKey, err = d.GetStorageAccesskey(ctx, accountOptions, req.GetSecrets(), secretNamespace); err != nil {
if accountName, accountKey, err = d.GetStorageAccesskey(ctx, accountOptions, req.GetSecrets(), secretName, secretNamespace); err != nil {
return nil, fmt.Errorf("failed to GetStorageAccesskey on account(%s) rg(%s), error: %v", accountOptions.Name, accountOptions.ResourceGroup, err)
}
}
Expand Down
34 changes: 34 additions & 0 deletions test/e2e/dynamic_provisioning_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"os"
"os/exec"
"strings"
"time"

"sigs.k8s.io/blob-csi-driver/test/e2e/driver"
"sigs.k8s.io/blob-csi-driver/test/e2e/testsuites"
Expand Down Expand Up @@ -121,6 +122,39 @@ var _ = ginkgo.Describe("[blob-csi-e2e] Dynamic Provisioning", func() {
test.Run(cs, ns)
})

ginkgo.It("should create a volume on demand with specified secretName", func() {
pods := []testsuites.PodDetails{
{
Cmd: "echo 'hello world' > /mnt/test-1/data && grep 'hello world' /mnt/test-1/data",
Volumes: []testsuites.VolumeDetails{
{
ClaimSize: "10Gi",
MountOptions: []string{
"-o allow_other",
"--file-cache-timeout-in-seconds=120",
"--cancel-list-on-mount-seconds=0",
},
VolumeMount: testsuites.VolumeMountDetails{
NameGenerate: "test-volume-",
MountPathGenerate: "/mnt/test-",
},
},
},
},
}
scParameters := map[string]string{
"skuName": "Standard_LRS",
"secretNamespace": "kube-system",
}
scParameters["secretName"] = fmt.Sprintf("secret-%d", time.Now().Unix())
test := testsuites.DynamicallyProvisionedCmdVolumeTest{
CSIDriver: testDriver,
Pods: pods,
StorageClassParameters: scParameters,
}
test.Run(cs, ns)
})

ginkgo.It("should create a deployment object, write and read to it, delete the pod and write and read to it again", func() {
pod := testsuites.PodDetails{
Cmd: "echo 'hello world' >> /mnt/test-1/data && while true; do sleep 1; done",
Expand Down

0 comments on commit 7a9303d

Please sign in to comment.