4040
4141 // tagKeyPrefixRegex is for verifying that the tag value does not contain restricted prefixes.
4242 tagKeyPrefixRegex = regexp .MustCompile (`^(?i)(name$|kubernetes\.io|openshift\.io|microsoft|azure|windows)` )
43+
44+ // keyVaultNameRegex is for verifying the name of the key vault used for storage account encryption.
45+ keyVaultNameRegex = regexp .MustCompile (`^[A-Za-z][0-9A-Za-z-]{1,22}[A-Za-z0-9]$` )
46+
47+ // keyVaultKeyNameRegex is for verifying the key name of the key vault used for storage account encryption.
48+ keyVaultKeyNameRegex = regexp .MustCompile (`^[0-9A-Za-z-]{1,127}$` )
49+
50+ // keyVaultUserAssignedIdentityRegex is for verifying the user assigned identity key used for storage account encryption.
51+ keyVaultUserAssignedIdentityRegex = regexp .MustCompile (`^[0-9A-Za-z][0-9A-Za-z-_]{2,127}$` )
4352)
4453
4554// maxUserTagLimit is the maximum userTags that can be configured as defined in openshift/api.
@@ -99,6 +108,10 @@ func ValidatePlatform(p *azure.Platform, publish types.PublishingStrategy, fldPa
99108 }
100109 }
101110
111+ if p .CustomerManagedKey != nil {
112+ allErrs = append (allErrs , validateCustomerManagedKeys (p .CloudName , * p .CustomerManagedKey , fldPath .Child ("customerManagedKey" ))... )
113+ }
114+
102115 // support for Azure user-defined tags made available through
103116 // RFE-2017 is for AzurePublicCloud only.
104117 if p .CloudName != azure .PublicCloud && len (p .UserTags ) > 0 {
@@ -122,6 +135,41 @@ func ValidatePlatform(p *azure.Platform, publish types.PublishingStrategy, fldPa
122135 return allErrs
123136}
124137
138+ // validateCustomerManagedKeys validates the key vault id.
139+ func validateCustomerManagedKeys (cloudName azure.CloudEnvironment , s azure.CustomerManagedKey , fldPath * field.Path ) field.ErrorList {
140+ var allErrs field.ErrorList
141+
142+ if cloudName == azure .StackCloud {
143+ return append (allErrs , field .Invalid (fldPath , s .KeyVault .Name , "storage account encryption is not supported on this platform" ))
144+ }
145+
146+ if s .KeyVault .KeyName == "" {
147+ allErrs = append (allErrs , field .Required (fldPath , "key vault key name is required for storage account encryption" ))
148+ } else if ! keyVaultKeyNameRegex .MatchString (s .KeyVault .KeyName ) {
149+ allErrs = append (allErrs , field .Invalid (fldPath , s .KeyVault .KeyName , "invalid key name for encryption" ))
150+ }
151+
152+ if s .KeyVault .Name == "" {
153+ allErrs = append (allErrs , field .Required (fldPath , "name of the key vault is required for storage account encryption" ))
154+ } else if ! keyVaultNameRegex .MatchString (s .KeyVault .Name ) || strings .Contains (s .KeyVault .Name , "--" ) {
155+ allErrs = append (allErrs , field .Invalid (fldPath , s .KeyVault .Name , "invalid name for key vault for encryption" ))
156+ }
157+
158+ if s .KeyVault .ResourceGroup == "" {
159+ allErrs = append (allErrs , field .Required (fldPath , "resource group of the key vault is required for storage account encryption" ))
160+ } else if ! RxResourceGroup .MatchString (s .KeyVault .ResourceGroup ) {
161+ allErrs = append (allErrs , field .Invalid (fldPath , s .KeyVault .ResourceGroup , "invalid resource group for encryption" ))
162+ }
163+
164+ if s .UserAssignedIdentityKey == "" {
165+ allErrs = append (allErrs , field .Required (fldPath , "user assigned identity key is required for storage account encryption" ))
166+ } else if ! keyVaultUserAssignedIdentityRegex .MatchString (s .UserAssignedIdentityKey ) {
167+ allErrs = append (allErrs , field .Invalid (fldPath , s .UserAssignedIdentityKey , "invalid user assigned identity key for encryption" ))
168+ }
169+
170+ return allErrs
171+ }
172+
125173// validateUserTags verifies if configured number of UserTags is not more than
126174// allowed limit and the tag keys and values are valid.
127175func validateUserTags (tags map [string ]string , fldPath * field.Path ) field.ErrorList {
0 commit comments