Skip to content

Commit 4494a03

Browse files
authored
Merge pull request #2007 from umagnus/release-1.28-aska
[release-1.28] feat: add allowSharedKeyAccess parameter
2 parents d4aae17 + ae0db0d commit 4494a03

File tree

4 files changed

+59
-1
lines changed

4 files changed

+59
-1
lines changed

docs/driver-parameters.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ shareAccessTier | [Access tier for file share](https://docs.microsoft.com/en-us/
2020
server | specify Azure storage account server address | existing server address, e.g. `accountname.privatelink.file.core.windows.net` | No | if empty, driver will use default `accountname.file.core.windows.net` or other sovereign cloud account address
2121
disableDeleteRetentionPolicy | specify whether disable DeleteRetentionPolicy for storage account created by driver | `true`,`false` | No | `false`
2222
allowBlobPublicAccess | Allow or disallow public access to all blobs or containers for storage account created by driver | `true`,`false` | No | `false`
23+
allowSharedKeyAccess | Allow or disallow shared key access for storage account created by driver | `true`,`false` | No | `true`
2324
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`
2425
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, e.g. `core.windows.net`
2526
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 | ""

pkg/azurefile/azurefile.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ const (
112112
getAccountKeyFromSecretField = "getaccountkeyfromsecret"
113113
disableDeleteRetentionPolicyField = "disabledeleteretentionpolicy"
114114
allowBlobPublicAccessField = "allowblobpublicaccess"
115+
allowSharedKeyAccessField = "allowsharedkeyaccess"
115116
storageEndpointSuffixField = "storageendpointsuffix"
116117
fsGroupChangePolicyField = "fsgroupchangepolicy"
117118
ephemeralField = "csi.storage.k8s.io/ephemeral"

pkg/azurefile/controllerserver.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
122122
var secretNamespace, pvcNamespace, protocol, customTags, storageEndpointSuffix, networkEndpointType, shareAccessTier, accountAccessTier, rootSquashType string
123123
var createAccount, useDataPlaneAPI, useSeretCache, matchTags, selectRandomMatchingAccount, getLatestAccountKey bool
124124
var vnetResourceGroup, vnetName, subnetName, shareNamePrefix, fsGroupChangePolicy string
125-
var requireInfraEncryption, disableDeleteRetentionPolicy, enableLFS, isMultichannelEnabled *bool
125+
var requireInfraEncryption, disableDeleteRetentionPolicy, enableLFS, isMultichannelEnabled, allowSharedKeyAccess *bool
126126
// set allowBlobPublicAccess as false by default
127127
allowBlobPublicAccess := pointer.Bool(false)
128128

@@ -212,6 +212,12 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
212212
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("invalid %s: %s in storage class", allowBlobPublicAccessField, v))
213213
}
214214
allowBlobPublicAccess = &value
215+
case allowSharedKeyAccessField:
216+
value, err := strconv.ParseBool(v)
217+
if err != nil {
218+
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("invalid %s: %s in storage class", allowSharedKeyAccessField, v))
219+
}
220+
allowSharedKeyAccess = &value
215221
case pvcNameKey:
216222
fileShareNameReplaceMap[pvcNameMetadata] = v
217223
case pvNameKey:
@@ -358,6 +364,10 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
358364
}
359365
}
360366

367+
if storeAccountKey && !pointer.BoolDeref(allowSharedKeyAccess, true) {
368+
return nil, status.Errorf(codes.InvalidArgument, "storeAccountKey is not supported for account with shared access key disabled")
369+
}
370+
361371
fileShareSize := int(requestGiB)
362372
// account kind should be FileStorage for Premium File
363373
accountKind := string(storage.KindStorageV2)
@@ -418,6 +428,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
418428
EnableLargeFileShare: enableLFS,
419429
DisableFileServiceDeleteRetentionPolicy: disableDeleteRetentionPolicy,
420430
AllowBlobPublicAccess: allowBlobPublicAccess,
431+
AllowSharedKeyAccess: allowSharedKeyAccess,
421432
VNetResourceGroup: vnetResourceGroup,
422433
VNetName: vnetName,
423434
SubnetName: subnetName,

pkg/azurefile/controllerserver_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,51 @@ func TestCreateVolume(t *testing.T) {
624624
}
625625
},
626626
},
627+
{
628+
name: "Failed with storeAccountKey is not supported for account with shared access key disabled",
629+
testFunc: func(t *testing.T) {
630+
allParam := map[string]string{
631+
skuNameField: "premium",
632+
storageAccountTypeField: "stoacctype",
633+
locationField: "loc",
634+
storageAccountField: "stoacc",
635+
resourceGroupField: "rg",
636+
shareNameField: "",
637+
diskNameField: "diskname.vhd",
638+
fsTypeField: "",
639+
storeAccountKeyField: "storeaccountkey",
640+
secretNamespaceField: "default",
641+
mountPermissionsField: "0755",
642+
accountQuotaField: "1000",
643+
allowSharedKeyAccessField: "false",
644+
}
645+
646+
fakeCloud := &azure.Cloud{
647+
Config: azure.Config{
648+
ResourceGroup: "rg",
649+
Location: "loc",
650+
VnetName: "fake-vnet",
651+
SubnetName: "fake-subnet",
652+
},
653+
}
654+
655+
req := &csi.CreateVolumeRequest{
656+
Name: "random-vol-name-vol-cap-invalid",
657+
CapacityRange: stdCapRange,
658+
VolumeCapabilities: stdVolCap,
659+
Parameters: allParam,
660+
}
661+
d := NewFakeDriver()
662+
663+
d.cloud = fakeCloud
664+
665+
expectedErr := status.Errorf(codes.InvalidArgument, "storeAccountKey is not supported for account with shared access key disabled")
666+
_, err := d.CreateVolume(ctx, req)
667+
if !reflect.DeepEqual(err, expectedErr) {
668+
t.Errorf("Unexpected error: %v", err)
669+
}
670+
},
671+
},
627672
{
628673
name: "No valid key with zero request gib",
629674
testFunc: func(t *testing.T) {

0 commit comments

Comments
 (0)