Merge pull request #3903 from Azure/slawande/ARO-10948/adopt-correct-convention-for-OIDC-issuer-urls

Correct convention for OIDC issuer urls
This commit is contained in:
Ayato Tokubi 2024-10-18 09:18:36 +01:00 коммит произвёл GitHub
Родитель 02bba703b2 e237f01586
Коммит 4bbe114caa
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
5 изменённых файлов: 28 добавлений и 16 удалений

Просмотреть файл

@ -514,7 +514,7 @@ func (m *manager) Delete(ctx context.Context) error {
if err != nil {
return err
}
err = oidcbuilder.DeleteOidcFolder(ctx, env.OIDCBlobDirectoryPrefix+m.doc.ID, azBlobClient)
err = oidcbuilder.DeleteOidcFolder(ctx, oidcbuilder.GetBlobName(m.subscriptionDoc.Subscription.Properties.TenantID, m.doc.ID), azBlobClient)
if err != nil {
return err
}

Просмотреть файл

@ -57,8 +57,7 @@ func (m *manager) createOIDC(ctx context.Context) error {
// For Production Azure Front Door Endpoint will be the OIDC Endpoint
oidcEndpoint = m.env.OIDCEndpoint()
}
oidcBuilder, err := oidcbuilder.NewOIDCBuilder(m.env, oidcEndpoint, env.OIDCBlobDirectoryPrefix+m.doc.ID)
oidcBuilder, err := oidcbuilder.NewOIDCBuilder(m.env, oidcEndpoint, oidcbuilder.GetBlobName(m.subscriptionDoc.Subscription.Properties.TenantID, m.doc.ID))
if err != nil {
return err
}

Просмотреть файл

@ -1411,11 +1411,21 @@ func TestCreateOIDC(t *testing.T) {
resourceGroupName := "fakeResourceGroup"
oidcStorageAccountName := "eastusoic"
afdEndpoint := "fake.oic.aro.test.net"
tenantId := "00000000-0000-0000-0000-000000000000"
m := manager{
subscriptionDoc: &api.SubscriptionDocument{
Subscription: &api.Subscription{
Properties: &api.SubscriptionProperties{
TenantID: tenantId,
},
},
},
}
storageWebEndpointForDev := oidcStorageAccountName + ".web." + azureclient.PublicCloud.StorageEndpointSuffix
resourceID := "/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/resourceGroup/providers/Microsoft.RedHatOpenShift/openShiftClusters/resourceName"
blobContainerURL := fmt.Sprintf("https://%s.blob.%s/%s", oidcStorageAccountName, azureclient.PublicCloud.StorageEndpointSuffix, oidcbuilder.WebContainer)
prodOIDCIssuer := fmt.Sprintf("https://%s/%s%s", afdEndpoint, env.OIDCBlobDirectoryPrefix, clusterID)
devOIDCIssuer := fmt.Sprintf("https://%s/%s%s", storageWebEndpointForDev, env.OIDCBlobDirectoryPrefix, clusterID)
prodOIDCIssuer := fmt.Sprintf("https://%s/%s", afdEndpoint, oidcbuilder.GetBlobName(m.subscriptionDoc.Subscription.Properties.TenantID, clusterID))
devOIDCIssuer := fmt.Sprintf("https://%s/%s", storageWebEndpointForDev, oidcbuilder.GetBlobName(m.subscriptionDoc.Subscription.Properties.TenantID, clusterID))
containerProperties := azstorage.AccountsClientGetPropertiesResponse{
Account: azstorage.Account{
Properties: &azstorage.AccountProperties{
@ -1491,8 +1501,8 @@ func TestCreateOIDC(t *testing.T) {
menv.EXPECT().OIDCStorageAccountName().Return(oidcStorageAccountName)
menv.EXPECT().Environment().Return(&azureclient.PublicCloud)
blob.EXPECT().GetAZBlobClient(blobContainerURL, &azblob.ClientOptions{}).Return(azblobClient, nil)
azblobClient.EXPECT().UploadBuffer(gomock.Any(), "", oidcbuilder.DocumentKey(env.OIDCBlobDirectoryPrefix+clusterID, oidcbuilder.DiscoveryDocumentKey), gomock.Any()).Return(nil)
azblobClient.EXPECT().UploadBuffer(gomock.Any(), "", oidcbuilder.DocumentKey(env.OIDCBlobDirectoryPrefix+clusterID, oidcbuilder.JWKSKey), gomock.Any()).Return(nil)
azblobClient.EXPECT().UploadBuffer(gomock.Any(), "", oidcbuilder.DocumentKey(oidcbuilder.GetBlobName(m.subscriptionDoc.Subscription.Properties.TenantID, clusterID), oidcbuilder.DiscoveryDocumentKey), gomock.Any()).Return(nil)
azblobClient.EXPECT().UploadBuffer(gomock.Any(), "", oidcbuilder.DocumentKey(oidcbuilder.GetBlobName(m.subscriptionDoc.Subscription.Properties.TenantID, clusterID), oidcbuilder.JWKSKey), gomock.Any()).Return(nil)
},
wantedOIDCIssuer: pointerutils.ToPtr(api.OIDCIssuer(prodOIDCIssuer)),
wantBoundServiceAccountSigningKey: true,
@ -1519,8 +1529,8 @@ func TestCreateOIDC(t *testing.T) {
blob.EXPECT().GetContainerProperties(gomock.Any(), resourceGroupName, oidcStorageAccountName, oidcbuilder.WebContainer).Return(containerProperties, nil)
menv.EXPECT().Environment().Return(&azureclient.PublicCloud)
blob.EXPECT().GetAZBlobClient(blobContainerURL, &azblob.ClientOptions{}).Return(azblobClient, nil)
azblobClient.EXPECT().UploadBuffer(gomock.Any(), "", oidcbuilder.DocumentKey(env.OIDCBlobDirectoryPrefix+clusterID, oidcbuilder.DiscoveryDocumentKey), gomock.Any()).Return(nil)
azblobClient.EXPECT().UploadBuffer(gomock.Any(), "", oidcbuilder.DocumentKey(env.OIDCBlobDirectoryPrefix+clusterID, oidcbuilder.JWKSKey), gomock.Any()).Return(nil)
azblobClient.EXPECT().UploadBuffer(gomock.Any(), "", oidcbuilder.DocumentKey(oidcbuilder.GetBlobName(m.subscriptionDoc.Subscription.Properties.TenantID, clusterID), oidcbuilder.DiscoveryDocumentKey), gomock.Any()).Return(nil)
azblobClient.EXPECT().UploadBuffer(gomock.Any(), "", oidcbuilder.DocumentKey(oidcbuilder.GetBlobName(m.subscriptionDoc.Subscription.Properties.TenantID, clusterID), oidcbuilder.JWKSKey), gomock.Any()).Return(nil)
},
wantedOIDCIssuer: pointerutils.ToPtr(api.OIDCIssuer(devOIDCIssuer)),
wantBoundServiceAccountSigningKey: true,
@ -1594,7 +1604,7 @@ func TestCreateOIDC(t *testing.T) {
menv.EXPECT().OIDCStorageAccountName().Return(oidcStorageAccountName)
menv.EXPECT().Environment().Return(&azureclient.PublicCloud)
blob.EXPECT().GetAZBlobClient(blobContainerURL, &azblob.ClientOptions{}).Return(azblobClient, nil)
azblobClient.EXPECT().UploadBuffer(gomock.Any(), "", oidcbuilder.DocumentKey(env.OIDCBlobDirectoryPrefix+clusterID, oidcbuilder.DiscoveryDocumentKey), gomock.Any()).Return(errors.New("generic error"))
azblobClient.EXPECT().UploadBuffer(gomock.Any(), "", oidcbuilder.DocumentKey(oidcbuilder.GetBlobName(m.subscriptionDoc.Subscription.Properties.TenantID, clusterID), oidcbuilder.DiscoveryDocumentKey), gomock.Any()).Return(errors.New("generic error"))
},
wantBoundServiceAccountSigningKey: false,
wantErr: "generic error",
@ -1627,11 +1637,12 @@ func TestCreateOIDC(t *testing.T) {
}
m := &manager{
db: dbOpenShiftClusters,
log: logrus.NewEntry(logrus.StandardLogger()),
rpBlob: rpBlobManager,
doc: doc,
env: env,
db: dbOpenShiftClusters,
log: logrus.NewEntry(logrus.StandardLogger()),
rpBlob: rpBlobManager,
doc: doc,
env: env,
subscriptionDoc: m.subscriptionDoc,
}
err = m.createOIDC(ctx)

1
pkg/env/env.go поставляемый
Просмотреть файл

@ -61,7 +61,6 @@ const (
ClusterMsiKeyVaultSuffix = "-msi"
RPPrivateEndpointPrefix = "rp-pe-"
ProxyHostName = "PROXY_HOSTNAME"
OIDCBlobDirectoryPrefix = "oic-"
)
// Interface is clunky and somewhat legacy and only used in the RP codebase (not

Просмотреть файл

@ -103,3 +103,6 @@ func DeleteOidcFolder(ctx context.Context, directory string, azBlobClient utilaz
func DocumentKey(directory string, blobKey string) string {
return fmt.Sprintf("%s/%s", directory, blobKey)
}
func GetBlobName(tenantID string, docID string) string {
return fmt.Sprintf("%s/%s", tenantID, docID)
}