Skip to content
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

Migrate Identity Live tests deployment to Fed Auth. #42635

Draft
wants to merge 42 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
d4356d4
update federated auth config
g2vinay Oct 28, 2024
402c03c
update ci
g2vinay Oct 28, 2024
fc40de3
update AKS tests
g2vinay Oct 28, 2024
da2f6ee
update CI yml
g2vinay Oct 28, 2024
3cd1232
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-java in…
g2vinay Oct 28, 2024
e28ac1e
update ci
g2vinay Oct 28, 2024
bd810b3
update pre ps1 to use ARM user
g2vinay Oct 28, 2024
9672d4b
update test resources ps1
g2vinay Oct 28, 2024
24df15f
add persist oidc token flow
g2vinay Oct 29, 2024
0853563
update pre ps1
g2vinay Oct 29, 2024
ff9d5e1
Merge remote-tracking branch 'upstream/main' into update-identity-liv…
g2vinay Nov 1, 2024
7e9ffff
update env vars in tests
g2vinay Nov 4, 2024
6d3fd72
update tests
g2vinay Nov 4, 2024
e4daab6
update ci config
g2vinay Nov 4, 2024
9b9b203
update test enc var
g2vinay Nov 4, 2024
15b0c57
Merge remote-tracking branch 'upstream/main' into update-identity-liv…
g2vinay Nov 4, 2024
9dd568c
update ci to map env vars
g2vinay Nov 4, 2024
1a63b29
update oidc mapping
g2vinay Nov 4, 2024
074969a
update client and tenant env vars
g2vinay Nov 4, 2024
5578c5e
fix tenant id mapping
g2vinay Nov 4, 2024
fda32bb
fetch a new federated token in tests
g2vinay Nov 7, 2024
d840be9
update OIDC token flow
g2vinay Nov 7, 2024
0bce75f
add token rerfresh logic
g2vinay Nov 7, 2024
74bfc10
fix ci yml
g2vinay Nov 7, 2024
0fa2b06
update post resources script
g2vinay Nov 7, 2024
839781c
update post script
g2vinay Nov 7, 2024
4ec4dcf
update ci.yml
g2vinay Nov 7, 2024
7a1af04
update ci
g2vinay Nov 7, 2024
9f3e0a9
update post script
g2vinay Nov 7, 2024
d89d91c
try optimize deploy resources step
g2vinay Nov 7, 2024
7fc1c36
add refresh token logic
g2vinay Nov 7, 2024
fbd0147
update ci
g2vinay Nov 7, 2024
dfb7580
refactor ci
g2vinay Nov 7, 2024
16bd8b0
update ci
g2vinay Nov 8, 2024
786e940
update ci
g2vinay Nov 8, 2024
af25b09
update tests
g2vinay Nov 10, 2024
dea90b1
update tests
g2vinay Nov 10, 2024
fa3caa0
update live tests
g2vinay Nov 10, 2024
e6dc78a
update tests
g2vinay Nov 10, 2024
2c061d7
update ci yml
g2vinay Nov 10, 2024
e079ac2
update ci
g2vinay Nov 10, 2024
85d2a14
update tests
g2vinay Nov 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions eng/pipelines/templates/jobs/live.tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ parameters:
UseHttpFaultInjector: false
OSName:
UseFederatedAuth: false
PersistOidcToken: false
VersionOverride: $(VersionOverride)

jobs:
Expand Down Expand Up @@ -114,6 +115,7 @@ jobs:
SubscriptionConfiguration: $(SubscriptionConfiguration)
ArmTemplateParameters: $(ArmTemplateParameters)
UseFederatedAuth: ${{ parameters.UseFederatedAuth }}
PersistOidcToken: ${{ parameters.PersistOidcToken }}
ServiceConnection: ${{ parameters.CloudConfig.ServiceConnection }}
SubscriptionConfigurationFilePaths: ${{ parameters.CloudConfig.SubscriptionConfigurationFilePaths }}
EnvVars:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ parameters:
- name: AdditionalSparseCheckoutPaths
type: object
default: []
- name: PersistOidcToken
type: boolean
default: false

stages:
- ${{ each cloud in parameters.CloudConfig }}:
Expand Down Expand Up @@ -165,6 +168,7 @@ stages:
TestOptions: ${{ parameters.TestOptions }}
UseHttpFaultInjector: ${{ parameters.UseHttpFaultInjector }}
UseFederatedAuth: ${{ parameters.UseFederatedAuth }}
PersistOidcToken: ${{ parameters.PersistOidcToken }}

MatrixConfigs:
# Enumerate platforms and additional platforms based on supported clouds (sparse platform<-->cloud matrix).
Expand Down
3 changes: 3 additions & 0 deletions eng/pipelines/templates/stages/archetype-sdk-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ parameters:
- name: UseFederatedAuth
type: boolean
default: true
- name: PersistOidcToken
type: boolean
default: false

extends:
template: /eng/pipelines/templates/stages/1es-redirect.yml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,25 @@
// Licensed under the MIT License.

import com.azure.core.credential.AccessToken;
import com.azure.core.credential.TokenCredential;
import com.azure.core.credential.TokenRequestContext;
import com.azure.core.http.HttpClient;
import com.azure.core.http.HttpMethod;
import com.azure.core.http.HttpRequest;
import com.azure.core.http.HttpResponse;
import com.azure.core.test.InterceptorManager;
import com.azure.core.test.TestProxyTestBase;
import com.azure.core.test.utils.MockTokenCredential;
import com.azure.core.util.Configuration;
import com.azure.core.util.CoreUtils;
import com.azure.core.util.logging.ClientLogger;
import com.azure.core.util.logging.LogLevel;
import com.azure.identity.ClientSecretCredential;
import com.azure.identity.ClientSecretCredentialBuilder;
import com.azure.identity.*;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
import reactor.core.scheduler.Schedulers;

import java.io.BufferedReader;
import java.io.IOException;
Expand Down Expand Up @@ -69,9 +73,13 @@ public void testManagedIdentityAksDeployment() {
//Setup Env
Configuration configuration = Configuration.getGlobalConfiguration().clone();

String spClientId = configuration.get("IDENTITY_CLIENT_ID");
String secret = configuration.get("IDENTITY_CLIENT_SECRET");
String tenantId = configuration.get("IDENTITY_TENANT_ID");
String systemAccessToken = configuration.get("SYSTEM_ACCESSTOKEN");

String spClientId = configuration.get("AZURESUBSCRIPTION_CLIENT_ID");
// String oidc = configuration.get("AZ_OIDC_TOKEN");
String oidc = configuration.get("ARM_OIDC_TOKEN");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to use this token at the running of the tests you will also need to set it as an env variable in the tests.yml file.

// String oidc = configuration.get("SYSTEM_ACCESSTOKEN");
String tenantId = configuration.get("AZURESUBSCRIPTION_TENANT_ID");
String resourceGroup = configuration.get("IDENTITY_RESOURCE_GROUP");
String aksCluster = configuration.get("IDENTITY_AKS_CLUSTER_NAME");
String subscriptionId = configuration.get("IDENTITY_SUBSCRIPTION_ID");
Expand All @@ -81,7 +89,7 @@ public void testManagedIdentityAksDeployment() {
String azPath = runCommand(pathCommand, "az").trim();
String kubectlPath = runCommand(pathCommand, "kubectl").trim();

runCommand(azPath, "login", "--service-principal", "-u", spClientId, "-p", secret, "--tenant", tenantId);
runCommand(azPath, "login", "--federated-token", oidc, "--service-principal", "-u", spClientId, "--tenant", tenantId);
runCommand(azPath, "account", "set", "--subscription", subscriptionId);
runCommand(azPath, "aks", "get-credentials", "--resource-group", resourceGroup, "--name", aksCluster,
"--overwrite-existing");
Expand All @@ -105,9 +113,10 @@ public void testManagedIdentityVmDeployment() {
//Setup Env
Configuration configuration = Configuration.getGlobalConfiguration().clone();

String spClientId = configuration.get("IDENTITY_CLIENT_ID");
String secret = configuration.get("IDENTITY_CLIENT_SECRET");
String tenantId = configuration.get("IDENTITY_TENANT_ID");
String spClientId = configuration.get("AZURESUBSCRIPTION_CLIENT_ID");
// String oidc = configuration.get("SYSTEM_ACCESSTOKEN");
String oidc = configuration.get("ARM_OIDC_TOKEN");
String tenantId = configuration.get("AZURESUBSCRIPTION_TENANT_ID");
String resourceGroup = configuration.get("IDENTITY_RESOURCE_GROUP");
String subscriptionId = configuration.get("IDENTITY_SUBSCRIPTION_ID");
String vmName = configuration.get("IDENTITY_VM_NAME");
Expand All @@ -118,7 +127,7 @@ public void testManagedIdentityVmDeployment() {
String azPath = runCommand(isWindows ? "where" : "which", "az").trim();
azPath = isWindows ? extractAzCmdPath(azPath) : azPath;

runCommand(azPath, "login", "--service-principal", "-u", spClientId, "-p", secret, "--tenant", tenantId);
runCommand(azPath, "login", "--federated-token", oidc, "--service-principal", "-u", spClientId, "--tenant", tenantId);
runCommand(azPath, "account", "set", "--subscription", subscriptionId);

String storageKey = runCommand(azPath, "storage", "account", "keys", "list", "--account-name",
Expand Down
37 changes: 35 additions & 2 deletions sdk/identity/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,45 @@ extends:
LiveTestStages:
- template: /eng/pipelines/templates/stages/archetype-sdk-tests-isolated.yml
parameters:
PreSteps:
- task: AzureCLI@2
displayName: Refreh OIDC token
env:
ARM_OIDC_TOKEN: $(ARM_OIDC_TOKEN)
inputs:
azureSubscription: azure-sdk-tests-public
addSpnToEnvironment: true
scriptLocation: inlineScript
scriptType: pscore
inlineScript: |
Write-Host "##vso[task.setvariable variable=ARM_OIDC_TOKEN;issecret=true]$($env:idToken)"
# - task: AzureCLI@2
# displayName: "Refresh OIDC Token"
# inputs:
# azureSubscription: azure-sdk-tests-public
# scriptType: pscore
# scriptLocation: inlineScript
# addSpnToEnvironment: true
# inlineScript: |
# Write-Host "Logging in to Azure with service principal..."
# az login --service-principal -u $env:ARM_CLIENT_ID --federated-token $env:ARM_OIDC_TOKEN --tenant $env:ARM_TENANT_ID
# Write-Host "Fetching a new federated token for Azure Resource Manager..."
# $newToken = az account get-access-token --resource "api://AzureADTokenExchange" --query accessToken -o tsv
# # Set the new token as a pipeline variable
# Write-Host "##vso[task.setvariable variable=ARM_OIDC_TOKEN_TEST]$newToken"
# env:
# ARM_OIDC_TOKEN: $(ARM_OIDC_TOKEN)
# ARM_CLIENT_ID: $(AZURESUBSCRIPTION_CLIENT_ID)
# ARM_TENANT_ID: $(AZURESUBSCRIPTION_TENANT_ID)
PersistOidcToken: true
Location: 'westus2'
CalledFromClient: true
ServiceDirectory: identity
SupportedClouds: 'Public,UsGov,China'
UseFederatedAuth: false
EnvVars:
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
AZ_TENANT_ID: $(IDENTITY_TENANT_ID)
AZ_CLIENT_ID: $(IDENTITY_CLIENT_ID)
Comment on lines +112 to +113
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
AZ_TENANT_ID: $(IDENTITY_TENANT_ID)
AZ_CLIENT_ID: $(IDENTITY_CLIENT_ID)

I don't think those are needed.

AZ_OIDC_TOKEN: $(ARM_OIDC_TOKEN)
CloudConfig:
Public:
SubscriptionConfigurations:
Copy link
Member

@weshaggard weshaggard Nov 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should remove $(sub-config-azure-cloud-test-resources) and investigate if $(sub-config-identity-test-resources) is needed any longer as well and if not remove it also.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does referencing IDENTITY_TENANT_ID directly in LiveManagedIdentityTests.java not work?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't end up setting those variables so I had him switch to the ones we set for the azurepipelinecredential

Expand Down
5 changes: 0 additions & 5 deletions sdk/identity/test-resources-post.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ $azBuildToolsRootPom = "$PSScriptRoot/../../eng/code-quality-reports/pom.xml" |
$funcAppRoot = "$PSScriptRoot/live-test-apps/identity-test-function" | Resolve-Path
$funcAppPom = "$funcAppRoot/pom.xml" | Resolve-Path

az login --service-principal -u $(getVariable('IDENTITY_CLIENT_ID')) -p $(getVariable('IDENTITY_CLIENT_SECRET')) --tenant $(getVariable('IDENTITY_TENANT_ID'))
az account set --subscription $(getVariable('IDENTITY_SUBSCRIPTION_ID'))


mvn -ntp clean install -DskipTests "-Drevapi.skip=true" "-Dcheckstyle.skip=true" "-Dcodesnippet.skip=true" "-Dspotbugs.skip=true" "-Dmaven.javadoc.skip=true" "-Dspotless.check.skip=true" "-Dspotless.apply.skip=true" "-Djacoco.skip=true" -f $azBuildToolsRootPom | Write-Host
mvn -ntp clean install -DskipTests "-Drevapi.skip=true" "-Dcheckstyle.skip=true" "-Dcodesnippet.skip=true" "-Dspotbugs.skip=true" "-Dmaven.javadoc.skip=true" "-Dspotless.check.skip=true" "-Dspotless.apply.skip=true" "-Djacoco.skip=true" -f "$azSerRootPom/azure-json/pom.xml" | Write-Host
mvn -ntp clean install -DskipTests "-Drevapi.skip=true" "-Dcheckstyle.skip=true" "-Dcodesnippet.skip=true" "-Dspotbugs.skip=true" "-Dmaven.javadoc.skip=true" "-Dspotless.check.skip=true" "-Dspotless.apply.skip=true" "-Djacoco.skip=true" -f "$azSerRootPom/azure-xml/pom.xml" | Write-Host
Expand All @@ -61,7 +57,6 @@ mvn -ntp clean install -DskipTests "-Drevapi.skip=true" "-Dcheckstyle.skip=true"
mvn -ntp clean install -DskipTests "-Drevapi.skip=true" "-Dcheckstyle.skip=true" "-Dcodesnippet.skip=true" "-Dspotbugs.skip=true" "-Dmaven.javadoc.skip=true" "-Dspotless.check.skip=true" "-Dspotless.apply.skip=true" "-Djacoco.skip=true" -f "$azStorageRootPom/azure-storage-internal-avro/pom.xml" | Write-Host
mvn -ntp clean install -DskipTests "-Drevapi.skip=true" "-Dcheckstyle.skip=true" "-Dcodesnippet.skip=true" "-Dspotbugs.skip=true" "-Dmaven.javadoc.skip=true" "-Dspotless.check.skip=true" "-Dspotless.apply.skip=true" "-Djacoco.skip=true" -f "$azStorageRootPom/azure-storage-blob/pom.xml" | Write-Host


mvn -ntp clean install -DskipTests -f $webappRootPom | Write-Host
az webapp deploy --resource-group $(getVariable('IDENTITY_RESOURCE_GROUP')) --name $(getVariable('IDENTITY_WEBAPP_NAME')) --src-path "$webappRoot/target/identity-test-webapp-1.0.0-beta.1.jar" --type jar

Expand Down
14 changes: 12 additions & 2 deletions sdk/identity/test-resources-pre.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@ param (

[Parameter(ParameterSetName = 'Provisioner', Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string] $TenantId
[string] $TenantId,

[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string] $SubscriptionId,

[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string] $Environment
)

$az_version = az version
Expand All @@ -27,7 +35,9 @@ $sshKey = Get-Content $PSScriptRoot/sshKey.pub
$templateFileParameters['sshPubKey'] = $sshKey

# Get the max version that is not preview and then get the name of the patch version with the max value
az login --service-principal -u $TestApplicationId -p $TestApplicationSecret --tenant $TenantId
az cloud set --name $Environment
az login --service-principal -u $TestApplicationId --tenant $TenantId --allow-no-subscriptions --federated-token $env:ARM_OIDC_TOKEN
az account set --subscription $SubscriptionId
$versions = az aks get-versions -l westus -o json | ConvertFrom-Json
Write-Host "AKS versions: $($versions | ConvertTo-Json -Depth 100)"
$patchVersions = $versions.values | Where-Object { $_.isPreview -eq $null } | Select-Object -ExpandProperty patchVersions
Expand Down
Loading