Skip to content

Commit 6d90b0f

Browse files
committed
feat: add VNetLinkName and PublicNetworkAccess in account creation
1 parent 53954b8 commit 6d90b0f

File tree

6 files changed

+77
-1
lines changed

6 files changed

+77
-1
lines changed

docs/driver-parameters.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ vnetResourceGroup | specify vnet resource group where virtual network is | exist
6767
vnetName | virtual network name | existing virtual network name | No | if empty, driver will use the `vnetName` value in azure cloud config file
6868
subnetName | subnet name | existing subnet name(s) of virtual network, if you want to update service endpoints on multiple subnets, separate them using a comma (`,`) | No | if empty, driver will use the `subnetName` value in azure cloud config file
6969
fsGroupChangePolicy | indicates how volume's ownership will be changed by the driver, pod `securityContext.fsGroupChangePolicy` is ignored | `OnRootMismatch`(by default), `Always`, `None` | No | `OnRootMismatch`
70+
vnetLinkName | virtual network link name associated with private dns zone | | No | if empty, driver will use the `vnetName + "-vnetlink"` by default
71+
publicNetworkAccess | `PublicNetworkAccess` property of created storage account by the driver | `Enabled`, `Disabled`, `SecuredByPerimeter` | No |
7072

7173
- account tags format created by dynamic provisioning
7274
```

pkg/azurefile/azurefile.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ const (
120120
getAccountKeyFromSecretField = "getaccountkeyfromsecret"
121121
disableDeleteRetentionPolicyField = "disabledeleteretentionpolicy"
122122
allowBlobPublicAccessField = "allowblobpublicaccess"
123+
publicNetworkAccessField = "publicnetworkaccess"
123124
allowSharedKeyAccessField = "allowsharedkeyaccess"
124125
storageEndpointSuffixField = "storageendpointsuffix"
125126
fsGroupChangePolicyField = "fsgroupchangepolicy"
@@ -148,6 +149,7 @@ const (
148149
networkEndpointTypeField = "networkendpointtype"
149150
vnetResourceGroupField = "vnetresourcegroup"
150151
vnetNameField = "vnetname"
152+
vnetLinkNameField = "vnetlinkname"
151153
subnetNameField = "subnetname"
152154
shareNamePrefixField = "sharenameprefix"
153155
requireInfraEncryptionField = "requireinfraencryption"
@@ -921,6 +923,18 @@ func isSupportedAccountAccessTier(accessTier string) bool {
921923
return false
922924
}
923925

926+
func isSupportedPublicNetworkAccess(publicNetworkAccess string) bool {
927+
if publicNetworkAccess == "" {
928+
return true
929+
}
930+
for _, tier := range armstorage.PossiblePublicNetworkAccessValues() {
931+
if publicNetworkAccess == string(tier) {
932+
return true
933+
}
934+
}
935+
return false
936+
}
937+
924938
func isSupportedRootSquashType(rootSquashType string) bool {
925939
if rootSquashType == "" {
926940
return true

pkg/azurefile/azurefile_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1885,3 +1885,34 @@ func TestSetAzureCredentials(t *testing.T) {
18851885
})
18861886
}
18871887
}
1888+
1889+
func TestIsSupportedPublicNetworkAccess(t *testing.T) {
1890+
tests := []struct {
1891+
publicNetworkAccess string
1892+
expectedResult bool
1893+
}{
1894+
{
1895+
publicNetworkAccess: "",
1896+
expectedResult: true,
1897+
},
1898+
{
1899+
publicNetworkAccess: "Enabled",
1900+
expectedResult: true,
1901+
},
1902+
{
1903+
publicNetworkAccess: "Disabled",
1904+
expectedResult: true,
1905+
},
1906+
{
1907+
publicNetworkAccess: "InvalidValue",
1908+
expectedResult: false,
1909+
},
1910+
}
1911+
1912+
for _, test := range tests {
1913+
result := isSupportedPublicNetworkAccess(test.publicNetworkAccess)
1914+
if result != test.expectedResult {
1915+
t.Errorf("isSupportedPublicNetworkAccess(%s) returned %v, expected %v", test.publicNetworkAccess, result, test.expectedResult)
1916+
}
1917+
}
1918+
}

pkg/azurefile/controllerserver.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
118118
var sku, subsID, resourceGroup, location, account, fileShareName, diskName, fsType, secretName string
119119
var secretNamespace, pvcNamespace, protocol, customTags, storageEndpointSuffix, networkEndpointType, shareAccessTier, accountAccessTier, rootSquashType, tagValueDelimiter string
120120
var createAccount, useSeretCache, matchTags, selectRandomMatchingAccount, getLatestAccountKey bool
121-
var vnetResourceGroup, vnetName, subnetName, shareNamePrefix, fsGroupChangePolicy, useDataPlaneAPI string
121+
var vnetResourceGroup, vnetName, vnetLinkName, publicNetworkAccess, subnetName, shareNamePrefix, fsGroupChangePolicy, useDataPlaneAPI string
122122
var requireInfraEncryption, disableDeleteRetentionPolicy, enableLFS, isMultichannelEnabled, allowSharedKeyAccess *bool
123123
// set allowBlobPublicAccess as false by default
124124
allowBlobPublicAccess := ptr.To(false)
@@ -212,6 +212,8 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
212212
return nil, status.Errorf(codes.InvalidArgument, "invalid %s: %s in storage class", allowBlobPublicAccessField, v)
213213
}
214214
allowBlobPublicAccess = &value
215+
case publicNetworkAccessField:
216+
publicNetworkAccess = v
215217
case allowSharedKeyAccessField:
216218
value, err := strconv.ParseBool(v)
217219
if err != nil {
@@ -237,6 +239,8 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
237239
vnetResourceGroup = v
238240
case vnetNameField:
239241
vnetName = v
242+
case vnetLinkNameField:
243+
vnetLinkName = v
240244
case subnetNameField:
241245
subnetName = v
242246
case shareNamePrefixField:
@@ -322,6 +326,10 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
322326
return nil, status.Errorf(codes.InvalidArgument, "shareNamePrefix(%s) can only contain lowercase letters, numbers, hyphens, and length should be less than 21", shareNamePrefix)
323327
}
324328

329+
if !isSupportedPublicNetworkAccess(publicNetworkAccess) {
330+
return nil, status.Errorf(codes.InvalidArgument, "publicNetworkAccess(%s) is not supported, supported PublicNetworkAccess list: %v", publicNetworkAccess, armstorage.PossiblePublicNetworkAccessValues())
331+
}
332+
325333
if protocol == nfs && fsType != "" && fsType != nfs {
326334
return nil, status.Errorf(codes.InvalidArgument, "fsType(%s) is not supported with protocol(%s)", fsType, protocol)
327335
}
@@ -480,8 +488,10 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
480488
DisableFileServiceDeleteRetentionPolicy: disableDeleteRetentionPolicy,
481489
AllowBlobPublicAccess: allowBlobPublicAccess,
482490
AllowSharedKeyAccess: allowSharedKeyAccess,
491+
PublicNetworkAccess: publicNetworkAccess,
483492
VNetResourceGroup: vnetResourceGroup,
484493
VNetName: vnetName,
494+
VNetLinkName: vnetLinkName,
485495
SubnetName: subnetName,
486496
RequireInfrastructureEncryption: requireInfraEncryption,
487497
AccessTier: accountAccessTier,

pkg/azurefile/controllerserver_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,23 @@ var _ = ginkgo.Describe("TestCreateVolume", func() {
265265
gomega.Expect(err).To(gomega.Equal(expectedErr))
266266
})
267267
})
268+
ginkgo.When("Invalid PublicNetworkAccess", func() {
269+
ginkgo.It("should fail", func(ctx context.Context) {
270+
allParam := map[string]string{
271+
publicNetworkAccessField: "test_publicNetworkAccess",
272+
}
273+
274+
req := &csi.CreateVolumeRequest{
275+
Name: "PublicNetworkAccess-invalid",
276+
CapacityRange: stdCapRange,
277+
VolumeCapabilities: stdVolCap,
278+
Parameters: allParam,
279+
}
280+
expectedErr := status.Errorf(codes.InvalidArgument, "publicNetworkAccess(%s) is not supported, supported PublicNetworkAccess list: %v", "test_publicNetworkAccess", armstorage.PossiblePublicNetworkAccessValues())
281+
_, err := d.CreateVolume(ctx, req)
282+
gomega.Expect(err).To(gomega.Equal(expectedErr))
283+
})
284+
})
268285
ginkgo.When("nfs protocol only supports premium storage", func() {
269286
ginkgo.It("should fail", func(ctx context.Context) {
270287
allParam := map[string]string{
@@ -529,6 +546,7 @@ var _ = ginkgo.Describe("TestCreateVolume", func() {
529546
ginkgo.It("should fail", func(ctx context.Context) {
530547
allParam := map[string]string{
531548
networkEndpointTypeField: "privateendpoint",
549+
vnetLinkNameField: "vnetlink",
532550
subnetNameField: "subnet1,subnet2",
533551
}
534552

test/e2e/dynamic_provisioning_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1480,6 +1480,7 @@ var _ = ginkgo.Describe("Dynamic Provisioning", func() {
14801480
scParameters := map[string]string{
14811481
"protocol": "nfs",
14821482
"networkEndpointType": "privateEndpoint",
1483+
"publicNetworkAccess": "Disabled",
14831484
"skuName": "Premium_LRS",
14841485
"rootSquashType": "AllSquash",
14851486
"mountPermissions": "0",

0 commit comments

Comments
 (0)