Skip to content

feat: add allowSharedKeyAccess parameter #1470

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/driver-parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ containerNamePrefix | specify Azure storage directory prefix created by driver |
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
accessTier | [Access tier for storage account](https://learn.microsoft.com/en-us/azure/storage/blobs/access-tiers-overview) | Standard account can choose `Hot` or `Cool`, and Premium account can only choose `Premium` | No | empty(use default setting for different storage account types)
allowBlobPublicAccess | Allow or disallow public access to all blobs or containers for storage account created by driver | `true`,`false` | No | `false`
allowSharedKeyAccess | Allow or disallow shared key access for storage account created by driver | `true`,`false` | No | `true`
requireInfraEncryption | specify whether or not the service applies a secondary layer of encryption with platform managed keys for data at rest for storage account created by driver | `true`,`false` | No | `false`
storageEndpointSuffix | specify Azure storage endpoint suffix | `core.windows.net`, `core.chinacloudapi.cn`, etc | No | if empty, driver will use default storage endpoint suffix according to cloud environment
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 | ""
Expand Down
1 change: 1 addition & 0 deletions pkg/blob/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ const (
keyVaultSecretVersionField = "keyvaultsecretversion"
storageAccountNameField = "storageaccountname"
allowBlobPublicAccessField = "allowblobpublicaccess"
allowSharedKeyAccessField = "allowsharedkeyaccess"
requireInfraEncryptionField = "requireinfraencryption"
ephemeralField = "csi.storage.k8s.io/ephemeral"
podNamespaceField = "csi.storage.k8s.io/pod.namespace"
Expand Down
11 changes: 11 additions & 0 deletions pkg/blob/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
var err error
// set allowBlobPublicAccess as false by default
allowBlobPublicAccess := pointer.Bool(false)
// set allowBlobPublicAccess as true by default
allowSharedKeyAccess := pointer.Bool(true)

containerNameReplaceMap := map[string]string{}

Expand Down Expand Up @@ -171,6 +173,10 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
if strings.EqualFold(v, trueValue) {
allowBlobPublicAccess = pointer.Bool(true)
}
case allowSharedKeyAccessField:
if strings.EqualFold(v, falseValue) {
allowSharedKeyAccess = pointer.Bool(false)
}
case requireInfraEncryptionField:
if strings.EqualFold(v, trueValue) {
requireInfraEncryption = pointer.Bool(true)
Expand Down Expand Up @@ -310,6 +316,10 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
storageEndpointSuffix = d.getStorageEndPointSuffix()
}

if storeAccountKey && !pointer.BoolDeref(allowSharedKeyAccess, false) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think here should be !pointer.BoolDeref(allowSharedKeyAccess, true) since if we didn't give allowSharedKeyAccess the default is true

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, the default value is true

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically allowSharedKeyAccess is never nil here but let me refactor the code a little to make it more straightforward.

return nil, status.Errorf(codes.InvalidArgument, "storeAccountKey is not supported for account with shared access key disabled")
}

accountOptions := &azure.AccountOptions{
Name: account,
Type: storageAccountType,
Expand All @@ -324,6 +334,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
IsHnsEnabled: isHnsEnabled,
EnableNfsV3: enableNfsV3,
AllowBlobPublicAccess: allowBlobPublicAccess,
AllowSharedKeyAccess: allowSharedKeyAccess,
RequireInfrastructureEncryption: requireInfraEncryption,
VNetResourceGroup: vnetResourceGroup,
VNetName: vnetName,
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 @@ -92,6 +92,40 @@ var _ = ginkgo.Describe("[blob-csi-e2e] Dynamic Provisioning", func() {
test.Run(ctx, cs, ns)
})

ginkgo.It("should create a volume on demand with storage account having shared access key disabled", func(ctx ginkgo.SpecContext) {
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-",
},
},
},
},
}
test := testsuites.DynamicallyProvisionedCmdVolumeTest{
CSIDriver: testDriver,
Pods: pods,
StorageClassParameters: map[string]string{
"skuName": "Standard_GRS",
"storeAccountKey": "false",
"allowSharedKeyAccess": "false",
"AzureStorageAuthType": "msi",
"AzureStorageIdentityClientID": "dummy",
},
}
test.Run(ctx, cs, ns)
})

ginkgo.It("should create a volume on demand with mount options", func(ctx ginkgo.SpecContext) {
pods := []testsuites.PodDetails{
{
Expand Down
Loading