-
Notifications
You must be signed in to change notification settings - Fork 197
ARO-3837 -Add EncryptionAtHost feature flag Validation #4806
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
Merged
kimorris27
merged 16 commits into
master
from
ARO-3837-fix-encryption-at-host-validation
May 28, 2026
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
dfe7108
ARO-3837: Add EncryptionAtHost feature flag validation before cluster…
4bbbe60
ARO-3837: Add EncryptionAtHost feature flag validation before cluster…
5ea89d6
ARO-3837: add EncryptionAtHost feature flag validation
593b668
ARO-3837: fix imports and formatting
b938cfd
Update pkg/frontend/encryptionathost_validation.go
sravyanimmala 8c9918a
ARO-3837: validate EncryptionAtHost feature registration before clust…
2ce156a
ARO-3837: Add EncryptionAtHost feature validation POC
f127f35
ARO-3837: upadte the poc to use track-2 sdk
b9f349c
update encryptionathost validation to track -2 SDK
4ac9213
remove POC file
5079948
PR Review fixes
05a637f
Move FeatureClient to azureclient wrapper and rename files
b127b6e
regenerate mocks
8437053
move FP credential creation out of validators and into caller
30147dd
regenerate mocks
7b7b566
fix unit tests by adding missing FPNewclientcertificatecredential moc…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| package frontend | ||
|
|
||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the Apache License 2.0. | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "net/http" | ||
|
|
||
| "github.com/Azure/azure-sdk-for-go/sdk/azcore" | ||
|
|
||
| "github.com/Azure/ARO-RP/pkg/api" | ||
| "github.com/Azure/ARO-RP/pkg/env" | ||
| "github.com/Azure/ARO-RP/pkg/util/azureclient/azuresdk/armfeatures" | ||
| ) | ||
|
|
||
| type FeaturesValidator interface { | ||
| ValidateSubscriptionFeatures(ctx context.Context, environment env.Interface, subscriptionID string, fpCred azcore.TokenCredential, oc *api.OpenShiftCluster) error | ||
| } | ||
|
|
||
| type featuresValidator struct{} | ||
|
|
||
| func (f featuresValidator) ValidateSubscriptionFeatures(ctx context.Context, environment env.Interface, subscriptionID string, fpCred azcore.TokenCredential, oc *api.OpenShiftCluster) error { | ||
| var fieldPath string | ||
| if oc.Properties.MasterProfile.EncryptionAtHost == api.EncryptionAtHostEnabled { | ||
| fieldPath = "properties.masterProfile.encryptionAtHost" | ||
| } else if oc.Properties.WorkerProfiles[0].EncryptionAtHost == api.EncryptionAtHostEnabled { | ||
| fieldPath = "properties.workerProfiles[0].encryptionAtHost" | ||
| } | ||
|
|
||
| if fieldPath != "" { | ||
| featuresClient, err := armfeatures.NewFeaturesClient(subscriptionID, fpCred, environment.Environment().ArmClientOptions()) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return validateEncryptionAtHostFeature(ctx, featuresClient, subscriptionID, fieldPath) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func validateEncryptionAtHostFeature( | ||
| ctx context.Context, | ||
| featuresClient armfeatures.FeaturesClient, | ||
| subscriptionID, fieldPath string, | ||
| ) error { | ||
| resp, err := featuresClient.Get(ctx, "Microsoft.Compute", "EncryptionAtHost", nil) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if resp.Properties == nil || resp.Properties.State == nil { | ||
| return api.NewCloudError( | ||
| http.StatusInternalServerError, | ||
| api.CloudErrorCodeInternalServerError, | ||
| "", | ||
| fmt.Sprintf( | ||
| "Microsoft.Compute/EncryptionAtHost"+ | ||
| " feature has no state for"+ | ||
| " subscription %s.", | ||
| subscriptionID)) | ||
| } | ||
|
kimorris27 marked this conversation as resolved.
|
||
|
|
||
| if *resp.Properties.State != "Registered" { | ||
| return api.NewCloudError( | ||
| http.StatusBadRequest, | ||
| api.CloudErrorCodeInvalidParameter, | ||
| fieldPath, | ||
| fmt.Sprintf( | ||
| "Microsoft.Compute/EncryptionAtHost feature is not registered on subscription %s. "+ | ||
| "Please register the feature on your subscription before creating the cluster.", | ||
| subscriptionID)) | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| package frontend | ||
|
|
||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the Apache License 2.0. | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "testing" | ||
|
|
||
| "go.uber.org/mock/gomock" | ||
|
|
||
| "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armfeatures" | ||
|
|
||
| mock_armfeatures "github.com/Azure/ARO-RP/pkg/util/mocks/azureclient/azuresdk/armfeatures" | ||
| "github.com/Azure/ARO-RP/pkg/util/pointerutils" | ||
| ) | ||
|
|
||
| func TestValidateEncryptionAtHostFeature(t *testing.T) { | ||
| ctx := context.Background() | ||
|
|
||
| for _, tt := range []struct { | ||
| name string | ||
| fieldPath string | ||
| mockFeatureState *string | ||
| mockPropertiesNil bool | ||
| mockStateNil bool | ||
| mockGetErr error | ||
| wantErr string | ||
| }{ | ||
| { | ||
| name: "feature is registered - should return nil", | ||
| fieldPath: "properties.masterProfile.encryptionAtHost", | ||
| mockFeatureState: pointerutils.ToPtr("Registered"), | ||
| wantErr: "", | ||
| }, | ||
| { | ||
| name: "feature is not registered - should return 400 BadRequest", | ||
| fieldPath: "properties.masterProfile.encryptionAtHost", | ||
| mockFeatureState: pointerutils.ToPtr("NotRegistered"), | ||
| wantErr: "400: InvalidParameter: properties.masterProfile.encryptionAtHost: Microsoft.Compute/EncryptionAtHost feature is not registered on subscription test-subscription. Please register the feature on your subscription before creating the cluster.", | ||
| }, | ||
| { | ||
| name: "resp.Properties is nil - should return internal server error", | ||
| fieldPath: "properties.workerProfiles[0].encryptionAtHost", | ||
| mockPropertiesNil: true, | ||
| wantErr: "500: InternalServerError: : Microsoft.Compute/EncryptionAtHost feature has no state for subscription test-subscription.", | ||
| }, | ||
| { | ||
| name: "resp.Properties.State is nil - should return internal server error", | ||
| fieldPath: "properties.masterProfile.encryptionAtHost", | ||
| mockStateNil: true, | ||
| wantErr: "500: InternalServerError: : Microsoft.Compute/EncryptionAtHost feature has no state for subscription test-subscription.", | ||
| }, | ||
| { | ||
| name: "Get returns error", | ||
| fieldPath: "properties.masterProfile.encryptionAtHost", | ||
| mockGetErr: errors.New("random error"), | ||
| wantErr: "random error", | ||
| }, | ||
| } { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| controller := gomock.NewController(t) | ||
| defer controller.Finish() | ||
|
|
||
| featuresClient := mock_armfeatures.NewMockFeaturesClient(controller) | ||
|
|
||
| var mockResponse armfeatures.ClientGetResponse | ||
| if tt.mockPropertiesNil { | ||
| mockResponse = armfeatures.ClientGetResponse{ | ||
| FeatureResult: armfeatures.FeatureResult{ | ||
| Properties: nil, | ||
| }, | ||
| } | ||
| } else if tt.mockStateNil { | ||
| mockResponse = armfeatures.ClientGetResponse{ | ||
| FeatureResult: armfeatures.FeatureResult{ | ||
| Properties: &armfeatures.FeatureProperties{ | ||
| State: nil, | ||
| }, | ||
| }, | ||
| } | ||
| } else if tt.mockFeatureState != nil { | ||
| mockResponse = armfeatures.ClientGetResponse{ | ||
| FeatureResult: armfeatures.FeatureResult{ | ||
| Properties: &armfeatures.FeatureProperties{ | ||
| State: tt.mockFeatureState, | ||
| }, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| featuresClient.EXPECT(). | ||
| Get(ctx, "Microsoft.Compute", "EncryptionAtHost", nil). | ||
| Return(mockResponse, tt.mockGetErr) | ||
|
|
||
| err := validateEncryptionAtHostFeature(ctx, featuresClient, "test-subscription", tt.fieldPath) | ||
| if err != nil && err.Error() != tt.wantErr || | ||
| err == nil && tt.wantErr != "" { | ||
| t.Errorf("expected error %q, got %q", tt.wantErr, err) | ||
| } | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.