-
Notifications
You must be signed in to change notification settings - Fork 99
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
Replace Azure Service Principal auth with Azure Workload Identity auth in functional tests #7787
Changes from all commits
3357a06
ddcf11c
a231493
442e778
4be5bd4
36cee08
96ead44
6427e2b
efb4494
9197ee1
b203cd9
bdfb399
7356e43
b1e6fc2
53b5066
88e2965
ece0901
1dc273a
0bac281
4993704
5529ca1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,7 +63,7 @@ env: | |
# Azure Keyvault CSI driver chart version | ||
AZURE_KEYVAULT_CSI_DRIVER_VER: "1.4.2" | ||
# Azure workload identity webhook chart version | ||
AZURE_WORKLOAD_IDENTITY_WEBHOOK_VER: "1.1.0" | ||
AZURE_WORKLOAD_IDENTITY_WEBHOOK_VER: "1.3.0" | ||
# Container registry for storing container images | ||
CONTAINER_REGISTRY: ghcr.io/radius-project/dev | ||
# Container registry for storing Bicep recipe artifacts | ||
|
@@ -97,7 +97,7 @@ jobs: | |
build: | ||
name: Build Radius for test | ||
runs-on: ubuntu-latest | ||
if: github.event_name == 'repository_dispatch' || (github.event_name == 'schedule' && github.repository == 'radius-project/radius') || github.event_name == 'workflow_run' | ||
if: github.event_name == 'repository_dispatch' || (github.event_name == 'schedule' && github.repository == 'radius-project/radius') || github.event_name == 'workflow_run' || github.event_name == 'workflow_dispatch' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
env: | ||
DE_IMAGE: "ghcr.io/radius-project/deployment-engine" | ||
DE_TAG: "latest" | ||
|
@@ -119,7 +119,13 @@ jobs: | |
private_key: ${{ secrets.FUNCTIONAL_TEST_APP_PRIVATE_KEY }} | ||
|
||
- name: Set up checkout target (scheduled) | ||
if: github.event_name == 'schedule' || github.event_name == 'repository_dispatch' | ||
if: github.event_name == 'schedule' | ||
run: | | ||
echo "CHECKOUT_REPO=${{ github.repository }}" >> $GITHUB_ENV | ||
echo "CHECKOUT_REF=refs/heads/main" >> $GITHUB_ENV | ||
|
||
- name: Set up checkout target (repository_dispatch) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. separated for clarity |
||
if: github.event_name == 'repository_dispatch' | ||
run: | | ||
echo "CHECKOUT_REPO=${{ github.repository }}" >> $GITHUB_ENV | ||
echo "CHECKOUT_REF=refs/heads/main" >> $GITHUB_ENV | ||
|
@@ -412,7 +418,7 @@ jobs: | |
tests: | ||
name: Run ${{ matrix.name }} functional tests | ||
needs: [build] | ||
if: github.event_name == 'repository_dispatch' || (github.event_name == 'schedule' && github.repository == 'radius-project/radius') || github.event_name == 'workflow_run' | ||
if: github.event_name == 'repository_dispatch' || (github.event_name == 'schedule' && github.repository == 'radius-project/radius') || github.event_name == 'workflow_run' || github.event_name == 'workflow_dispatch' | ||
strategy: | ||
fail-fast: true | ||
matrix: | ||
|
@@ -616,7 +622,7 @@ jobs: | |
echo "*** Installing Radius to Kubernetes ***" | ||
rad install kubernetes \ | ||
--chart ${{ env.RADIUS_CHART_LOCATION }} \ | ||
--set rp.image=${{ env.CONTAINER_REGISTRY }}/applications-rp,rp.tag=${{ env.REL_VERSION }},controller.image=${{ env.CONTAINER_REGISTRY }}/controller,controller.tag=${{ env.REL_VERSION }},ucp.image=${{ env.CONTAINER_REGISTRY }}/ucpd,ucp.tag=${{ env.REL_VERSION }},de.image=${{ env.DE_IMAGE }},de.tag=${{ env.DE_TAG }} | ||
--set rp.image=${{ env.CONTAINER_REGISTRY }}/applications-rp,rp.tag=${{ env.REL_VERSION }},controller.image=${{ env.CONTAINER_REGISTRY }}/controller,controller.tag=${{ env.REL_VERSION }},ucp.image=${{ env.CONTAINER_REGISTRY }}/ucpd,ucp.tag=${{ env.REL_VERSION }},de.image=${{ env.DE_IMAGE }},de.tag=${{ env.DE_TAG }},global.azureWorkloadIdentity.enabled=true | ||
|
||
echo "*** Create workspace, group and environment for test ***" | ||
rad workspace create kubernetes | ||
|
@@ -630,8 +636,8 @@ jobs: | |
echo "*** Configuring Azure provider ***" | ||
rad env update kind-radius --azure-subscription-id ${{ secrets.AZURE_SUBSCRIPTIONID_TESTS }} \ | ||
--azure-resource-group ${{ env.AZURE_TEST_RESOURCE_GROUP }} | ||
rad credential register azure sp --client-id ${{ secrets.AZURE_SP_TESTS_APPID }} \ | ||
--client-secret ${{ secrets.INTEGRATION_TEST_SP_PASSWORD }} \ | ||
rad credential register azure wi \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here's the important change |
||
--client-id ${{ secrets.AZURE_SP_TESTS_APPID }} \ | ||
--tenant-id ${{ secrets.AZURE_SP_TESTS_TENANTID }} | ||
|
||
echo "*** Configuring AWS provider ***" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,6 +49,9 @@ type UCPCredentialOptions struct { | |
|
||
// ClientOptions is the options for azure client. | ||
ClientOptions *azcore.ClientOptions | ||
|
||
// TokenFilePath is the path to the azure token file (for use with Azure workload identity) | ||
TokenFilePath string | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added this to make this file unit testable. the azure sdk library will use the environment variable in the real world |
||
} | ||
|
||
// UCPCredential authenticates service principal using UCP credential APIs. | ||
|
@@ -171,14 +174,23 @@ func refreshAzureWorkloadIdentityCredentials(ctx context.Context, c *UCPCredenti | |
|
||
logger.Info("Retrieved Azure Credential - ClientID: " + azureWorkloadIdentityCredential.ClientID) | ||
|
||
var opt *azidentity.DefaultAzureCredentialOptions | ||
var opt *azidentity.WorkloadIdentityCredentialOptions | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I misunderstood what this code did on the first workload identity PR. this should have been WorkloadIdentityCredential instead. |
||
if c.options.ClientOptions != nil { | ||
opt = &azidentity.DefaultAzureCredentialOptions{ | ||
opt = &azidentity.WorkloadIdentityCredentialOptions{ | ||
ClientID: azureWorkloadIdentityCredential.ClientID, | ||
TenantID: azureWorkloadIdentityCredential.TenantID, | ||
TokenFilePath: c.options.TokenFilePath, | ||
ClientOptions: *c.options.ClientOptions, | ||
} | ||
} else { | ||
opt = &azidentity.WorkloadIdentityCredentialOptions{ | ||
TokenFilePath: c.options.TokenFilePath, | ||
ClientID: azureWorkloadIdentityCredential.ClientID, | ||
TenantID: azureWorkloadIdentityCredential.TenantID, | ||
} | ||
} | ||
|
||
azCred, err := azidentity.NewDefaultAzureCredential(opt) | ||
azCred, err := azidentity.NewWorkloadIdentityCredential(opt) | ||
if err != nil { | ||
return err | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,13 +39,20 @@ import ( | |
const ( | ||
AzureProviderName = "azurerm" | ||
|
||
azureFeaturesParam = "features" | ||
azureSubIDParam = "subscription_id" | ||
azureClientIDParam = "client_id" | ||
azureClientSecretParam = "client_secret" | ||
azureTenantIDParam = "tenant_id" | ||
azureUseAKSWorkloadIdentityParam = "use_aks_workload_identity" | ||
azureUseCLIParam = "use_cli" | ||
azureFeaturesParam = "features" | ||
azureSubIDParam = "subscription_id" | ||
azureClientIDParam = "client_id" | ||
azureClientSecretParam = "client_secret" | ||
azureTenantIDParam = "tenant_id" | ||
azureUseOIDCParam = "use_oidc" | ||
azureUseCLIParam = "use_cli" | ||
azureOIDCTokenFilePathParam = "oidc_token_file_path" | ||
|
||
// The Azure AD Workload Identity Mutating Admission Webhook projects a signed service account token to | ||
// this well known path. | ||
// https://azure.github.io/azure-workload-identity/docs/installation/mutating-admission-webhook.html | ||
// https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs#argument-reference | ||
azureOIDCTokenFilePath = "/var/run/secrets/azure/tokens/azure-identity-token" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these are the changes to make Terraform + Azure WI work. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Q: will we be able to retrieve the TokenFilePath in the fetchAzureCredentials() call (eg line 129 below) instead of the const value here, say, in a future PR? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we totally could - if we have a user ask us to make this configurable then we can. for now it looks like most if not everyone uses the standard well known file path established by the azure ad workload identity project. |
||
) | ||
|
||
var _ Provider = (*azureProvider)(nil) | ||
|
@@ -175,13 +182,14 @@ func (p *azureProvider) generateProviderConfigMap(configMap map[string]any, cred | |
if credentials.WorkloadIdentity != nil && | ||
credentials.WorkloadIdentity.ClientID != "" && | ||
credentials.WorkloadIdentity.TenantID != "" { | ||
|
||
// Use OIDC for Workload Identity | ||
// https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/guides/service_principal_oidc | ||
configMap[azureClientIDParam] = credentials.WorkloadIdentity.ClientID | ||
configMap[azureTenantIDParam] = credentials.WorkloadIdentity.TenantID | ||
|
||
// Use AKS Workload Identity for Azure provider | ||
// https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/guides/aks_workload_identity#configuring-with-environment-variables | ||
configMap[azureUseAKSWorkloadIdentityParam] = true | ||
configMap[azureUseCLIParam] = false | ||
configMap[azureUseOIDCParam] = true | ||
configMap[azureOIDCTokenFilePathParam] = azureOIDCTokenFilePath | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. now this should work for AKS and non-AKS clusters There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good catch! |
||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
module github.com/radius-project/radius/test/magpiego | ||
|
||
go 1.22 | ||
go 1.22.0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I changed this because I was getting an error trying to build this image on arm64 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting. Can you share the error message? It was working fine for me. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. go: downloading go1.22 (darwin/arm64) |
||
|
||
require ( | ||
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.13.0 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ terraform { | |
required_providers { | ||
azurerm = { | ||
source = "hashicorp/azurerm" | ||
version = "~> 3.0.0" | ||
version = "~> 3.114.0" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ~> 3.0.0 will only match 3.0.*, but workload identity for azurerm needs greater than 3.7. 3.114 is the latest version as of today |
||
} | ||
} | ||
} | ||
|
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 bumping to latest