Skip to content

Commit

Permalink
improve federated cred naming
Browse files Browse the repository at this point in the history
  • Loading branch information
slawande2 committed Dec 9, 2024
1 parent 7e94614 commit af30b71
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/cluster/workloadidentityresources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ func TestGetPlatformWorkloadIdentityFederatedCredName(t *testing.T) {
serviceAccount: "openshift-cloud-controller-manager:cloud-controller-manager",
identity: api.PlatformWorkloadIdentity{ResourceID: fmt.Sprintf("%s/%s", resourceID, "ccm")},
wantErr: "",
want: fmt.Sprintf("%s-%s-%s", subID, clusterRGName, clusterName),
want: fmt.Sprintf("%s-%s", "openshift-cloud-controller-manager:cloud-controller-manager", clusterName),
},
} {
t.Run(tt.name, func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/platformworkloadidentity/federatedcredentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const (
)

func GetPlatformWorkloadIdentityFederatedCredName(clusterResourceId, identityResourceId azure.Resource, serviceAccountName string) string {
clusterResourceKey := fmt.Sprintf("%s-%s-%s", clusterResourceId.SubscriptionID, clusterResourceId.ResourceGroup, clusterResourceId.ResourceName)
clusterResourceKey := fmt.Sprintf("%s-%s", serviceAccountName, clusterResourceId.ResourceName)
name := fmt.Sprintf("%s-%s-%s", clusterResourceKey, serviceAccountName, identityResourceId.ResourceName)
// the base-36 encoded string of a SHA-224 hash will typically be around 43 to 44 characters long.
hash := sha256.Sum224([]byte(name))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestGetPlatformWorkloadIdentityFederatedCredName(t *testing.T) {
})

t.Run("has expected key as prefix", func(t *testing.T) {
wantPrefix := fmt.Sprintf("%s-%s-%s", subscriptionId, resourceGroup, clusterName)
wantPrefix := fmt.Sprintf("%s-%s", saName, clusterName)
got := GetPlatformWorkloadIdentityFederatedCredName(clusterResourceId, identityResourceId, saName)

if !strings.HasPrefix(got, wantPrefix) {
Expand Down

0 comments on commit af30b71

Please sign in to comment.