-
Notifications
You must be signed in to change notification settings - Fork 174
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
Fix unexpected workload identity update in workload identity clusters #3973
Open
rajdeepc2792
wants to merge
7
commits into
master
Choose a base branch
from
rajdeepc2792/ARO-12514
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d9a3fb5
ARO-12514 additional util functionsPlatformWorkloadIdentityRoleSet fu…
rajdeepc2792 78a6f7b
ARO-12514 check expected platform workload identity at frontend for c…
rajdeepc2792 13de5ad
ARO-12514 add comments and use existing getAvailablePlatformWorkloadI…
rajdeepc2792 e76443c
ARO-12514 unit test cases put/patch workload identity mismatch
rajdeepc2792 e07c4ee
ARO-12514 fix preflightvalidation such that latest apiversion tests p…
rajdeepc2792 5c01386
ARO-12514 update/add unit test cases for preflightvalidation
rajdeepc2792 3d66fea
ARO-12514 add unit tests for validatePlatformWorkloadIdentities
rajdeepc2792 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 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
609 changes: 576 additions & 33 deletions
609
pkg/frontend/openshiftcluster_preflightvalidation_test.go
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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,27 @@ | ||
package frontend | ||
|
||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the Apache License 2.0. | ||
|
||
import ( | ||
"github.com/Azure/ARO-RP/pkg/api" | ||
"github.com/Azure/ARO-RP/pkg/util/platformworkloadidentity" | ||
) | ||
|
||
// validatePlatformWorkloadIdentities validates that customer provided platform workload identities are expected | ||
func (f *frontend) validatePlatformWorkloadIdentities(oc *api.OpenShiftCluster) error { | ||
roleSets := f.getAvailablePlatformWorkloadIdentityRoleSets() | ||
|
||
platformWorkloadIdentityRolesByVersionService := platformworkloadidentity.NewPlatformWorkloadIdentityRolesByVersionService() | ||
err := platformWorkloadIdentityRolesByVersionService.PopulatePlatformWorkloadIdentityRolesByVersionUsingRoleSets(oc, roleSets) | ||
if err != nil { | ||
return err | ||
} | ||
matches := platformWorkloadIdentityRolesByVersionService.MatchesPlatformWorkloadIdentityRoles(oc) | ||
|
||
if !matches { | ||
return platformworkloadidentity.GetPlatformWorkloadIdentityMismatchError(oc, platformWorkloadIdentityRolesByVersionService.GetPlatformWorkloadIdentityRolesByRoleName()) | ||
} | ||
|
||
return nil | ||
} |
190 changes: 190 additions & 0 deletions
190
pkg/frontend/platformworkloadidentityrolesets_validate_test.go
This file contains 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,190 @@ | ||
package frontend | ||
|
||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the Apache License 2.0. | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/Azure/ARO-RP/pkg/api" | ||
"github.com/Azure/ARO-RP/pkg/util/pointerutils" | ||
utilerror "github.com/Azure/ARO-RP/test/util/error" | ||
) | ||
|
||
func TestValidatePlatformWorkloadIdentities(t *testing.T) { | ||
mockMiResourceId := "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/not-a-real-group/providers/Microsoft.ManagedIdentity/userAssignedIdentities/not-a-real-mi" | ||
|
||
for _, tt := range []struct { | ||
test string | ||
pwi map[string]api.PlatformWorkloadIdentity | ||
version string | ||
upgradeableTo *api.UpgradeableTo | ||
wantErr string | ||
}{ | ||
{ | ||
test: "Success - Valid platform workload identities provided", | ||
version: defaultVersion, | ||
pwi: map[string]api.PlatformWorkloadIdentity{ | ||
"file-csi-driver": {ResourceID: mockMiResourceId}, | ||
"cloud-controller-manager": {ResourceID: mockMiResourceId}, | ||
"ingress": {ResourceID: mockMiResourceId}, | ||
"image-registry": {ResourceID: mockMiResourceId}, | ||
"machine-api": {ResourceID: mockMiResourceId}, | ||
"cloud-network-config": {ResourceID: mockMiResourceId}, | ||
"aro-operator": {ResourceID: mockMiResourceId}, | ||
"disk-csi-driver": {ResourceID: mockMiResourceId}, | ||
}, | ||
}, | ||
{ | ||
test: "Success - Valid platform workload identities provided with UpgradeableTo", | ||
version: defaultVersion, | ||
pwi: map[string]api.PlatformWorkloadIdentity{ | ||
"file-csi-driver": {ResourceID: mockMiResourceId}, | ||
"cloud-controller-manager": {ResourceID: mockMiResourceId}, | ||
"ingress": {ResourceID: mockMiResourceId}, | ||
"image-registry": {ResourceID: mockMiResourceId}, | ||
"machine-api": {ResourceID: mockMiResourceId}, | ||
"cloud-network-config": {ResourceID: mockMiResourceId}, | ||
"aro-operator": {ResourceID: mockMiResourceId}, | ||
"disk-csi-driver": {ResourceID: mockMiResourceId}, | ||
"extra-new-operator": {ResourceID: mockMiResourceId}, | ||
}, | ||
upgradeableTo: pointerutils.ToPtr(api.UpgradeableTo(getMIWIUpgradeableToVersion().String())), | ||
}, | ||
{ | ||
test: "Success - Valid platform workload identities provided with UpgradeableTo smaller than current version", | ||
version: defaultVersion, | ||
pwi: map[string]api.PlatformWorkloadIdentity{ | ||
"file-csi-driver": {ResourceID: mockMiResourceId}, | ||
"cloud-controller-manager": {ResourceID: mockMiResourceId}, | ||
"ingress": {ResourceID: mockMiResourceId}, | ||
"image-registry": {ResourceID: mockMiResourceId}, | ||
"machine-api": {ResourceID: mockMiResourceId}, | ||
"cloud-network-config": {ResourceID: mockMiResourceId}, | ||
"aro-operator": {ResourceID: mockMiResourceId}, | ||
"disk-csi-driver": {ResourceID: mockMiResourceId}, | ||
}, | ||
upgradeableTo: pointerutils.ToPtr(api.UpgradeableTo("4.10.25")), | ||
}, | ||
{ | ||
test: "Fail - Not a MIWI Cluster", | ||
version: defaultVersion, | ||
wantErr: "PopulatePlatformWorkloadIdentityRolesByVersionUsingRoleSets called for a Cluster Service Principal cluster", | ||
}, | ||
{ | ||
test: "Fail - Invalid Cluster Version", | ||
version: "4.1052", | ||
pwi: map[string]api.PlatformWorkloadIdentity{ | ||
"file-csi-driver": {ResourceID: mockMiResourceId}, | ||
"cloud-controller-manager": {ResourceID: mockMiResourceId}, | ||
"ingress": {ResourceID: mockMiResourceId}, | ||
"image-registry": {ResourceID: mockMiResourceId}, | ||
"machine-api": {ResourceID: mockMiResourceId}, | ||
"cloud-network-config": {ResourceID: mockMiResourceId}, | ||
"aro-operator": {ResourceID: mockMiResourceId}, | ||
"disk-csi-driver": {ResourceID: mockMiResourceId}, | ||
}, | ||
wantErr: `could not parse version "4.1052"`, | ||
}, | ||
{ | ||
test: "Fail - Invalid upgradeableTo version", | ||
version: defaultVersion, | ||
pwi: map[string]api.PlatformWorkloadIdentity{ | ||
"file-csi-driver": {ResourceID: mockMiResourceId}, | ||
"cloud-controller-manager": {ResourceID: mockMiResourceId}, | ||
"ingress": {ResourceID: mockMiResourceId}, | ||
"image-registry": {ResourceID: mockMiResourceId}, | ||
"machine-api": {ResourceID: mockMiResourceId}, | ||
"cloud-network-config": {ResourceID: mockMiResourceId}, | ||
"aro-operator": {ResourceID: mockMiResourceId}, | ||
"disk-csi-driver": {ResourceID: mockMiResourceId}, | ||
}, | ||
upgradeableTo: pointerutils.ToPtr(api.UpgradeableTo("4.1052")), | ||
wantErr: `could not parse version "4.1052"`, | ||
}, | ||
{ | ||
test: "Fail - No roleset exists for the older version", | ||
version: "4.10.14", | ||
pwi: map[string]api.PlatformWorkloadIdentity{ | ||
"file-csi-driver": {ResourceID: mockMiResourceId}, | ||
"cloud-controller-manager": {ResourceID: mockMiResourceId}, | ||
"ingress": {ResourceID: mockMiResourceId}, | ||
"image-registry": {ResourceID: mockMiResourceId}, | ||
"machine-api": {ResourceID: mockMiResourceId}, | ||
"cloud-network-config": {ResourceID: mockMiResourceId}, | ||
"aro-operator": {ResourceID: mockMiResourceId}, | ||
"disk-csi-driver": {ResourceID: mockMiResourceId}, | ||
}, | ||
wantErr: "400: InvalidParameter: : No PlatformWorkloadIdentityRoleSet found for the requested or upgradeable OpenShift minor version '4.10'. Please retry with different OpenShift version, and if the issue persists, raise an Azure support ticket", | ||
}, | ||
{ | ||
test: "Fail - Unexpected platform workload identity provided", | ||
version: defaultVersion, | ||
pwi: map[string]api.PlatformWorkloadIdentity{ | ||
"file-csi-driver": {ResourceID: mockMiResourceId}, | ||
"cloud-controller-manager": {ResourceID: mockMiResourceId}, | ||
"ingress": {ResourceID: mockMiResourceId}, | ||
"image-registry": {ResourceID: mockMiResourceId}, | ||
"machine-api": {ResourceID: mockMiResourceId}, | ||
"cloud-network-config": {ResourceID: mockMiResourceId}, | ||
"aro-operator": {ResourceID: mockMiResourceId}, | ||
"unexpected-identity": {ResourceID: mockMiResourceId}, | ||
}, | ||
wantErr: unexpectedWorkloadIdentitiesError, | ||
}, | ||
{ | ||
test: "Fail - Missing platform workload identity", | ||
version: defaultVersion, | ||
pwi: map[string]api.PlatformWorkloadIdentity{ | ||
"file-csi-driver": {ResourceID: mockMiResourceId}, | ||
"cloud-controller-manager": {ResourceID: mockMiResourceId}, | ||
"ingress": {ResourceID: mockMiResourceId}, | ||
"image-registry": {ResourceID: mockMiResourceId}, | ||
"machine-api": {ResourceID: mockMiResourceId}, | ||
"cloud-network-config": {ResourceID: mockMiResourceId}, | ||
"aro-operator": {ResourceID: mockMiResourceId}, | ||
}, | ||
wantErr: unexpectedWorkloadIdentitiesError, | ||
}, | ||
{ | ||
test: "Fail - Extra platform workload identity provided", | ||
version: defaultVersion, | ||
pwi: map[string]api.PlatformWorkloadIdentity{ | ||
"file-csi-driver": {ResourceID: mockMiResourceId}, | ||
"cloud-controller-manager": {ResourceID: mockMiResourceId}, | ||
"ingress": {ResourceID: mockMiResourceId}, | ||
"image-registry": {ResourceID: mockMiResourceId}, | ||
"machine-api": {ResourceID: mockMiResourceId}, | ||
"cloud-network-config": {ResourceID: mockMiResourceId}, | ||
"aro-operator": {ResourceID: mockMiResourceId}, | ||
"disk-csi-driver": {ResourceID: mockMiResourceId}, | ||
"extra-identity": {ResourceID: mockMiResourceId}, | ||
}, | ||
wantErr: unexpectedWorkloadIdentitiesError, | ||
}, | ||
} { | ||
t.Run(tt.test, func(t *testing.T) { | ||
f := frontend{ | ||
availablePlatformWorkloadIdentityRoleSets: getPlatformWorkloadIdentityRolesChangeFeed(), | ||
} | ||
|
||
oc := &api.OpenShiftCluster{ | ||
Properties: api.OpenShiftClusterProperties{ | ||
ClusterProfile: api.ClusterProfile{ | ||
Version: tt.version, | ||
}, | ||
}, | ||
} | ||
|
||
if tt.pwi != nil { | ||
oc.Properties.PlatformWorkloadIdentityProfile = &api.PlatformWorkloadIdentityProfile{ | ||
PlatformWorkloadIdentities: tt.pwi, | ||
UpgradeableTo: tt.upgradeableTo, | ||
} | ||
} | ||
|
||
err := f.validatePlatformWorkloadIdentities(oc) | ||
utilerror.AssertErrorMessage(t, err, tt.wantErr) | ||
}) | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
pkg/util/mocks/platformworkloadidentity/platformworkloadidentity.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a nice to have, since we only expect one return here, is it not possible to simplify to just one "if" condition or create a guard clause instead of nesting another "if" condition?
e.g. if oc.UsesWorkloadIdentity() && f.validatePlatformWorkloadIdentities(oc) != nil