Skip to content

Commit a444192

Browse files
authored
ci: migrate az login to workload identity federation (#1733)
Signed-off-by: Anish Ramasekar <anish.ramasekar@gmail.com>
1 parent 981e839 commit a444192

25 files changed

Lines changed: 158 additions & 85 deletions

.github/workflows/azwi-build.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
persist-credentials: false
3737
- uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
3838
with:
39-
go-version: "1.25"
39+
go-version: "1.26"
4040
check-latest: true
4141
- name: Build azwi
4242
run: |

.github/workflows/azwi-e2e.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
persist-credentials: false
3535
- uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
3636
with:
37-
go-version: "1.25"
37+
go-version: "1.26"
3838
check-latest: true
3939
- name: Build azwi
4040
run: |

.github/workflows/codecov.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
persist-credentials: false
2525
- uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
2626
with:
27-
go-version: "^1.24"
27+
go-version: "1.26"
2828
check-latest: true
2929
- name: Run tests
3030
run: make test

.github/workflows/create-release-pull-request.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
persist-credentials: false
3636
- uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
3737
with:
38-
go-version: "1.25"
38+
go-version: "1.26"
3939
check-latest: true
4040
- run: make release-manifest
4141
env:

.github/workflows/create-release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
persist-credentials: false
3434
- uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
3535
with:
36-
go-version: "1.25"
36+
go-version: "1.26"
3737
check-latest: true
3838
- name: Goreleaser
3939
uses: goreleaser/goreleaser-action@336e29918d653399e599bfca99fadc1d7ffbc9f7 # v4.3.0

.github/workflows/scan-vulns.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626

2727
- uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
2828
with:
29-
go-version: "1.25"
29+
go-version: "1.26"
3030
check-latest: true
3131
- uses: golang/govulncheck-action@31f7c5463448f83528bd771c2d978d940080c9fd # v1.0.4
3232

@@ -47,7 +47,7 @@ jobs:
4747

4848
- uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
4949
with:
50-
go-version: "1.25"
50+
go-version: "1.26"
5151
check-latest: true
5252

5353
- name: Check out code into the Go module directory

.golangci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
run:
22
deadline: 20m
3-
go-version: "1.25"
3+
go-version: "1.26"
44

55
linters:
66
disable-all: true

.pipelines/nightly.yaml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ schedules:
1010
include:
1111
- main
1212

13+
parameters:
14+
- name: serviceConnection
15+
type: string
16+
default: 'Upstream-CI-ServiceConnection'
17+
1318
pool:
1419
name: staging-pool-amd64-mariner-2
1520
demands:
@@ -42,8 +47,11 @@ jobs:
4247
steps:
4348
- task: GoTool@0
4449
inputs:
45-
version: "1.25.9"
50+
version: "1.26.4"
4651
- template: templates/prepare-deps.yaml
52+
- template: templates/az-login.yaml
53+
parameters:
54+
serviceConnection: ${{ parameters.serviceConnection }}
4755
- script: make test-e2e
4856
displayName: Webhook E2E test suite
4957
env:
@@ -54,6 +62,7 @@ jobs:
5462
- template: templates/publish-logs.yaml
5563
- template: templates/upgrade.yaml
5664
parameters:
65+
serviceConnection: ${{ parameters.serviceConnection }}
5766
matrix:
5867
upgrade_aks_windows:
5968
WINDOWS_CLUSTER: "true"
@@ -90,8 +99,11 @@ jobs:
9099
steps:
91100
- task: GoTool@0
92101
inputs:
93-
version: "1.25.9"
102+
version: "1.26.4"
94103
- template: templates/prepare-deps.yaml
104+
- template: templates/az-login.yaml
105+
parameters:
106+
serviceConnection: ${{ parameters.serviceConnection }}
95107
- script: make test-e2e
96108
displayName: Webhook E2E test suite
97109
env:

.pipelines/pr.yaml

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ pr:
1515
- '*'
1616
- examples/msal-go/*
1717

18+
parameters:
19+
- name: serviceConnection
20+
type: string
21+
default: 'Upstream-CI-ServiceConnection'
22+
1823
pool:
1924
name: staging-pool-amd64-mariner-2
2025
demands:
@@ -28,7 +33,7 @@ jobs:
2833
steps:
2934
- task: GoTool@0
3035
inputs:
31-
version: "1.25.9"
36+
version: "1.26.4"
3237
- template: templates/prepare-deps.yaml
3338
- script: make lint
3439
displayName: golangci-lint
@@ -55,7 +60,7 @@ jobs:
5560
steps:
5661
- task: GoTool@0
5762
inputs:
58-
version: "1.25.9"
63+
version: "1.26.4"
5964
- template: templates/prepare-deps.yaml
6065
- script: make test
6166
displayName: Unit test
@@ -95,8 +100,11 @@ jobs:
95100
steps:
96101
- task: GoTool@0
97102
inputs:
98-
version: "1.25.9"
103+
version: "1.26.4"
99104
- template: templates/prepare-deps.yaml
105+
- template: templates/az-login.yaml
106+
parameters:
107+
serviceConnection: ${{ parameters.serviceConnection }}
100108
- script: echo "##vso[task.setvariable variable=CLUSTER_NAME]azwi-e2e-$(openssl rand -hex 2)"
101109
displayName: Set CLUSTER_NAME
102110
condition: ne(variables.LOCAL_ONLY, 'true')
@@ -148,8 +156,11 @@ jobs:
148156
steps:
149157
- task: GoTool@0
150158
inputs:
151-
version: "1.25.9"
159+
version: "1.26.4"
152160
- template: templates/prepare-deps.yaml
161+
- template: templates/az-login.yaml
162+
parameters:
163+
serviceConnection: ${{ parameters.serviceConnection }}
153164
- script: echo "##vso[task.setvariable variable=CLUSTER_NAME]azwi-e2e-$(openssl rand -hex 2)"
154165
displayName: Set CLUSTER_NAME
155166
condition: ne(variables.LOCAL_ONLY, 'true')

.pipelines/templates/az-login.yaml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Logs in to Azure for use by subsequent az / kubectl / helm commands.
2+
#
3+
# Prefers Workload Identity Federation (WIF) when a `serviceConnection`
4+
# name is supplied. Falls back to `az login --identity` for pools that
5+
# still have a Managed Identity assigned. Pipelines whose pool MI was
6+
# removed must pass a WIF-capable service connection; without one the
7+
# MI path will fail.
8+
parameters:
9+
- name: serviceConnection
10+
type: string
11+
default: ''
12+
13+
steps:
14+
- script: az --version || sudo tdnf install -y azure-cli
15+
displayName: "Install azure-cli (if missing)"
16+
17+
- ${{ if ne(parameters.serviceConnection, '') }}:
18+
- task: AzureCLI@2
19+
displayName: "Extract WIF identity"
20+
inputs:
21+
azureSubscription: ${{ parameters.serviceConnection }}
22+
addSpnToEnvironment: true
23+
scriptType: bash
24+
scriptLocation: inlineScript
25+
inlineScript: |
26+
set -u
27+
echo "servicePrincipalId set: ${servicePrincipalId:+yes} (len=${#servicePrincipalId})"
28+
echo "tenantId set: ${tenantId:+yes} (len=${#tenantId})"
29+
echo "idToken set: ${idToken:+yes} (len=${#idToken})"
30+
echo "##vso[task.setvariable variable=ARM_CLIENT_ID]$servicePrincipalId"
31+
echo "##vso[task.setvariable variable=ARM_ID_TOKEN;issecret=true]$idToken"
32+
echo "##vso[task.setvariable variable=ARM_TENANT_ID]$tenantId"
33+
34+
- bash: |
35+
set -eu
36+
az login \
37+
--service-principal \
38+
-u "$(ARM_CLIENT_ID)" \
39+
--tenant "$(ARM_TENANT_ID)" \
40+
--allow-no-subscriptions \
41+
--federated-token "$(ARM_ID_TOKEN)" > /dev/null
42+
az account set -s=$(AZURE_SUBSCRIPTION_ID)
43+
displayName: "az login (WIF)"
44+
- ${{ else }}:
45+
- script: |
46+
az login -i > /dev/null
47+
az account set -s=$(AZURE_SUBSCRIPTION_ID)
48+
displayName: "az login (managed identity)"

0 commit comments

Comments
 (0)