Skip to content
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

feat: add allowSharedKeyAccess parameter #1972

Merged
merged 1 commit into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -41,6 +41,7 @@ shareAccessTier | [Access tier for file share](https://docs.microsoft.com/en-us/
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
disableDeleteRetentionPolicy | specify whether disable DeleteRetentionPolicy for storage account created by driver | `true`,`false` | No | `false`
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, 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 | ""
Expand Down
1 change: 1 addition & 0 deletions pkg/azurefile/azurefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ const (
getAccountKeyFromSecretField = "getaccountkeyfromsecret"
disableDeleteRetentionPolicyField = "disabledeleteretentionpolicy"
allowBlobPublicAccessField = "allowblobpublicaccess"
allowSharedKeyAccessField = "allowsharedkeyaccess"
storageEndpointSuffixField = "storageendpointsuffix"
fsGroupChangePolicyField = "fsgroupchangepolicy"
ephemeralField = "csi.storage.k8s.io/ephemeral"
Expand Down
13 changes: 12 additions & 1 deletion pkg/azurefile/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
var secretNamespace, pvcNamespace, protocol, customTags, storageEndpointSuffix, networkEndpointType, shareAccessTier, accountAccessTier, rootSquashType, tagValueDelimiter string
var createAccount, useDataPlaneAPI, useSeretCache, matchTags, selectRandomMatchingAccount, getLatestAccountKey bool
var vnetResourceGroup, vnetName, subnetName, shareNamePrefix, fsGroupChangePolicy string
var requireInfraEncryption, disableDeleteRetentionPolicy, enableLFS, isMultichannelEnabled *bool
var requireInfraEncryption, disableDeleteRetentionPolicy, enableLFS, isMultichannelEnabled, allowSharedKeyAccess *bool
// set allowBlobPublicAccess as false by default
allowBlobPublicAccess := pointer.Bool(false)

Expand Down Expand Up @@ -224,6 +224,12 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("invalid %s: %s in storage class", allowBlobPublicAccessField, v))
}
allowBlobPublicAccess = &value
case allowSharedKeyAccessField:
value, err := strconv.ParseBool(v)
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("invalid %s: %s in storage class", allowSharedKeyAccessField, v))
}
allowSharedKeyAccess = &value
case pvcNameKey:
fileShareNameReplaceMap[pvcNameMetadata] = v
case pvNameKey:
Expand Down Expand Up @@ -382,6 +388,10 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
}
}

if storeAccountKey && !pointer.BoolDeref(allowSharedKeyAccess, true) {
return nil, status.Errorf(codes.InvalidArgument, "storeAccountKey is not supported for account with shared access key disabled")
}

if resourceGroup == "" {
resourceGroup = d.cloud.ResourceGroup
}
Expand Down Expand Up @@ -450,6 +460,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
EnableLargeFileShare: enableLFS,
DisableFileServiceDeleteRetentionPolicy: disableDeleteRetentionPolicy,
AllowBlobPublicAccess: allowBlobPublicAccess,
AllowSharedKeyAccess: allowSharedKeyAccess,
VNetResourceGroup: vnetResourceGroup,
VNetName: vnetName,
SubnetName: subnetName,
Expand Down
45 changes: 45 additions & 0 deletions pkg/azurefile/controllerserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,51 @@ func TestCreateVolume(t *testing.T) {
}
},
},
{
name: "Failed with storeAccountKey is not supported for account with shared access key disabled",
testFunc: func(t *testing.T) {
allParam := map[string]string{
skuNameField: "premium",
storageAccountTypeField: "stoacctype",
locationField: "loc",
storageAccountField: "stoacc",
resourceGroupField: "rg",
shareNameField: "",
diskNameField: "diskname.vhd",
fsTypeField: "",
storeAccountKeyField: "storeaccountkey",
secretNamespaceField: "default",
mountPermissionsField: "0755",
accountQuotaField: "1000",
allowSharedKeyAccessField: "false",
}

fakeCloud := &azure.Cloud{
Config: azure.Config{
ResourceGroup: "rg",
Location: "loc",
VnetName: "fake-vnet",
SubnetName: "fake-subnet",
},
}

req := &csi.CreateVolumeRequest{
Name: "random-vol-name-vol-cap-invalid",
CapacityRange: stdCapRange,
VolumeCapabilities: stdVolCap,
Parameters: allParam,
}
d := NewFakeDriver()

d.cloud = fakeCloud

expectedErr := status.Errorf(codes.InvalidArgument, "storeAccountKey is not supported for account with shared access key disabled")
_, err := d.CreateVolume(ctx, req)
if !reflect.DeepEqual(err, expectedErr) {
t.Errorf("Unexpected error: %v", err)
}
},
},
{
name: "No valid key with zero request gib",
testFunc: func(t *testing.T) {
Expand Down
Loading