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

OCPBUGS-2895: Azure: Fix DiskEncryptionSet regex validation #6513

Merged
merged 1 commit into from
Oct 31, 2022
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
Fix DiskEncryptionSet regex validation
  • Loading branch information
SudoBrendan committed Oct 21, 2022
commit c56fbd1fead09aeb3238a7abaae6ca046cb87b2e
8 changes: 4 additions & 4 deletions pkg/types/azure/validation/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ import (

var (
// RxDiskEncryptionSetID is a regular expression that validates a disk encryption set ID.
RxDiskEncryptionSetID = regexp.MustCompile(`(?i)^/subscriptions/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})/resourceGroups/([-a-z0-9_().]{0,89}[-a-z0-9_()])/providers/Microsoft\.Compute/diskEncryptionSets/([-a-z0-9_]{1,80})$`)
RxDiskEncryptionSetID = regexp.MustCompile(`(?i)^/subscriptions/([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})/resourceGroups/([-a-zA-Z0-9_().]{0,89}[-a-zA-Z0-9_()])/providers/Microsoft\.Compute/diskEncryptionSets/([-a-zA-Z0-9_]{1,80})$`)

// RxSubscriptionID is a regular expression that validates a subscription ID.
RxSubscriptionID = regexp.MustCompile(`^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$`)
RxSubscriptionID = regexp.MustCompile(`^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$`)

// RxResourceGroup is a regular expression that validates a resource group.
RxResourceGroup = regexp.MustCompile(`^[-a-z0-9_().]{0,89}[-a-z0-9_()]$`)
RxResourceGroup = regexp.MustCompile(`^[-a-zA-Z0-9_().]{0,89}[-a-zA-Z0-9_()]$`)

// RxDiskEncryptionSetName is a regular expression that validates a disk encryption set name
RxDiskEncryptionSetName = regexp.MustCompile(`^[-a-z0-9_]{1,80}$`)
RxDiskEncryptionSetName = regexp.MustCompile(`^[-a-zA-Z0-9_]{1,80}$`)
)

// ValidateDiskEncryption checks that the specified disk encryption configuration is valid.
Expand Down
10 changes: 4 additions & 6 deletions pkg/types/azure/validation/disk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ import (
)

var (
subscriptionID = "08675309-1111-2222-3333-303606808909"
resourceGroup = "test-resource-group"
diskEncryptionSetName = "test-encryption-set"
diskEncryptionSetID = fmt.Sprintf("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Compute/diskEncryptionSets/%s",
subscriptionID, resourceGroup, diskEncryptionSetName)
subscriptionID = "aF675309-bE11-cD22-aF33-bE3606808909"
resourceGroup = "Test-res.o(ur)Ce_gRoup"
diskEncryptionSetName = "teSt-encrypTion_Set"
)

func validDiskEncryptionMachinePool() *azure.MachinePool {
Expand Down Expand Up @@ -47,7 +45,7 @@ func TestValidateDiskEncryption(t *testing.T) {
name: "invalid disk encryption set (platform is stack cloud)",
pool: validDiskEncryptionMachinePool(),
cloudName: azure.StackCloud,
expected: fmt.Sprintf(`diskEncryptionSet.diskEncryptionSet: Invalid value: azure.DiskEncryptionSet{SubscriptionID:"%s", ResourceGroup:"%s", Name:"%s"}: disk encryption sets are not supported on this platform`, subscriptionID, resourceGroup, diskEncryptionSetName),
expected: fmt.Sprintf(`diskEncryptionSet.diskEncryptionSet: Invalid value: azure.DiskEncryptionSet{SubscriptionID:"%s", ResourceGroup:".+", Name:"%s"}: disk encryption sets are not supported on this platform`, subscriptionID, diskEncryptionSetName),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately, this string is used as a regex itself, and since RGs allow characters like ., (, and ), we can't use that and still get a match.

},
{
name: "invalid disk encryption set (invalid subscription ID)",
Expand Down