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

ci: Use federated auth in CI #4340

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 4 additions & 3 deletions cli/azd/test/functional/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ type cliConfig struct {

// The client ID to use for live Azure tests.
ClientID string
// The client secret to use for live Azure tests.
ClientSecret string
// The tenant ID to use for live Azure tests.
TenantID string
// The Azure subscription ID to use for live Azure tests.
Expand All @@ -82,7 +80,6 @@ type cliConfig struct {
func (c *cliConfig) init() {
c.CI = os.Getenv("CI") != ""
c.ClientID = os.Getenv("AZD_TEST_CLIENT_ID")
c.ClientSecret = os.Getenv("AZD_TEST_CLIENT_SECRET")
c.TenantID = os.Getenv("AZD_TEST_TENANT_ID")
c.SubscriptionID = os.Getenv("AZD_TEST_AZURE_SUBSCRIPTION_ID")
c.Location = os.Getenv("AZD_TEST_AZURE_LOCATION")
Expand Down Expand Up @@ -777,6 +774,8 @@ func newTestContext(t *testing.T) (context.Context, context.CancelFunc) {
}

func Test_CLI_InfraCreateAndDeleteResourceTerraform(t *testing.T) {
t.Skip("azure/azure-dev#4341")

// running this test in parallel is ok as it uses a t.TempDir()
t.Parallel()
ctx, cancel := newTestContext(t)
Expand Down Expand Up @@ -818,6 +817,8 @@ func Test_CLI_InfraCreateAndDeleteResourceTerraform(t *testing.T) {
}

func Test_CLI_InfraCreateAndDeleteResourceTerraformRemote(t *testing.T) {
t.Skip("azure/azure-dev#4341")

ctx, cancel := newTestContext(t)
defer cancel()

Expand Down
2 changes: 2 additions & 0 deletions cli/azd/test/functional/deployment_stacks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
)

func Test_DeploymentStacks(t *testing.T) {
t.Skip("azure/azure-dev#4341")

t.Run("Subscription_Scope_Up_Down", func(t *testing.T) {
t.Parallel()
ctx, cancel := newTestContext(t)
Expand Down
6 changes: 4 additions & 2 deletions cli/azd/test/functional/login_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ func Test_CLI_AuthLoginStatus(t *testing.T) {
}

func Test_CLI_LoginServicePrincipal(t *testing.T) {
t.Skip("azure/azure-dev#4341")

ctx, cancel := newTestContext(t)
defer cancel()

Expand All @@ -62,7 +64,7 @@ func Test_CLI_LoginServicePrincipal(t *testing.T) {
cli := azdcli.NewCLI(t)
// Isolate login to a separate configuration directory
cli.Env = append(cli.Env, "AZD_CONFIG_DIR="+dir)
if cfg.ClientID == "" || cfg.TenantID == "" || cfg.ClientSecret == "" {
if cfg.ClientID == "" || cfg.TenantID == "" /* || cfg.ClientSecret == "" */ {
if cfg.CI {
panic("Service principal is not configured. AZD_TEST_* variables are required to be set for live testing.")
}
Expand All @@ -78,7 +80,7 @@ func Test_CLI_LoginServicePrincipal(t *testing.T) {
_, err := cli.RunCommand(ctx,
"auth", "login",
"--client-id", cfg.ClientID,
"--client-secret", cfg.ClientSecret,
// "--client-secret", cfg.ClientSecret,
"--tenant-id", cfg.TenantID)
require.NoError(t, err)

Expand Down
6 changes: 2 additions & 4 deletions eng/pipelines/templates/jobs/build-cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,12 @@ jobs:
CI: true
AZD_TEST_CLI_VERSION: $(CLI_VERSION)
AZD_TEST_CLIENT_ID: $(arm-client-id)
AZD_TEST_CLIENT_SECRET: $(arm-client-secret)
AZD_TEST_TENANT_ID: $(arm-tenant-id)
AZD_TEST_AZURE_SUBSCRIPTION_ID: $(SubscriptionId)
AZD_TEST_AZURE_LOCATION: eastus2
AZURE_RECORD_MODE: $(AZURE_RECORD_MODE)
# AZD Live Test: Terraform service principal authentication
ARM_CLIENT_ID: $(arm-client-id)
ARM_CLIENT_SECRET: $(arm-client-secret)
# AZD Live Test: Terraform authentication via `az`
ARM_USE_CLI: true
ARM_TENANT_ID: $(arm-tenant-id)
# Code Coverage: Generate junit report to publish results
GOTESTSUM_JUNITFILE: junitTestReport.xml
Expand Down
7 changes: 2 additions & 5 deletions eng/pipelines/templates/steps/azd-login.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ steps:
${{ parameters.SubscriptionConfiguration }}
'@ | ConvertFrom-Json -AsHashtable;
& $azdCmd login `
--client-id "$($subscriptionConfiguration.TestApplicationId)" `
--client-secret "$($subscriptionConfiguration.TestApplicationSecret)" `
--tenant-id "$($subscriptionConfiguration.TenantId)"
# Delegate auth to az CLI which supports federated auth in AzDo
& $azdCmd config set auth.useAzCliAuth true
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
Expand All @@ -30,7 +28,6 @@ steps:
# Export service principal auth information for terraform testing
Write-Host "##vso[task.setvariable variable=arm-client-id;issecret=false]$($subscriptionConfiguration.TestApplicationId)"
Write-Host "##vso[task.setvariable variable=arm-client-secret;issecret=true]$($subscriptionConfiguration.TestApplicationSecret)"
Write-Host "##vso[task.setvariable variable=arm-tenant-id;issecret=false]$($subscriptionConfiguration.TenantId)"
condition: and(succeeded(), ne(variables['Skip.LiveTest'], 'true'))
Expand Down
Loading