Skip to content

Commit f32f86f

Browse files
authored
fix(trigger-e2e): mint victim cancellation token (#1599)
Use the dedicated agent-playground-write WIF identity for gate API facts and self-cancel, while retaining the build token for synth reads. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 0fe13dc9-ae18-4e54-b587-a53f5afb28f2
1 parent 05ce3f9 commit f32f86f

2 files changed

Lines changed: 31 additions & 11 deletions

File tree

tests/trigger-e2e/README.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,18 @@ In `https://dev.azure.com/msazuresphere/AgentPlayground`:
173173
orchestrator:
174174
- `TRIGGER_E2E_VICTIM_DEFINITION_ID=<victim-pipeline-id>`
175175
- `TRIGGER_E2E_VICTIM_REPO=ado-aw-mirror`
176-
5. **Grant the VICTIM build identity** Code (read) on the repo, Build (add
177-
tags / edit build quality), and permission to cancel builds (gate
178-
self-cancel). See [`docs/safe-output-permissions.md`](../../docs/safe-output-permissions.md)
179-
if it hits 401/403.
176+
5. **Grant the VICTIM build identity** Code Read on `ado-aw-mirror` for
177+
checkout and synth PR lookups.
180178
6. **Grant the principal behind `agent-playground-write`** Contribute, Create
181179
branch, delete refs, and Contribute to PRs on `ado-aw-mirror`, plus Queue
182-
builds on the victim definition. This same principal performs mirror sync
183-
and creates the transient PR context.
180+
builds on the victim definition. Grant it project-level **Stop builds**:
181+
current-build cancellation is checked against a build-instance token and
182+
does not inherit a definition-scoped Stop permission. Authorize the
183+
`agent-playground-write` service connection for both the orchestrator and
184+
victim definitions. This same identity performs mirror sync, creates the
185+
transient PR context, and supplies the gate's short-lived bearer.
186+
See [`docs/safe-output-permissions.md`](../../docs/safe-output-permissions.md)
187+
if either identity hits 401/403.
184188
7. **Set the GitHub PAT secret** on the orchestrator only:
185189
```powershell
186190
ado-aw secrets set TRIGGER_E2E_GITHUB_TOKEN `

tests/trigger-e2e/victim-pipeline.yml

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717
# Register it against the ado-aw Azure Repos mirror so the `self` checkout
1818
# also carries `scripts/ado-script/` to build the bundles from source.
1919
# - The build identity ($(System.AccessToken)) needs: Code (read) on the repo
20-
# (PR/label/iteration lookups), Build (edit build quality / add tags) and
21-
# the ability to cancel builds (gate self-cancel). See
22-
# docs/safe-output-permissions.md if it hits 401/403.
20+
# for checkout and synth PR lookups. Gate evaluation uses a short-lived ADO
21+
# token minted from `agent-playground-write`; that dedicated identity needs
22+
# repo Read plus project-level Stop builds for gate self-cancel. See
23+
# docs/safe-output-permissions.md if either path hits 401/403.
2324
#
2425
# ## Observable build tags
2526
# - trig.synth.promoted | trig.synth.skipped | trig.synth.real-pr
@@ -82,6 +83,20 @@ jobs:
8283
workingDirectory: scripts/ado-script
8384
displayName: Build gate + synth bundles from checkout
8485
86+
- task: AzureCLI@2
87+
displayName: Acquire ADO token for gate self-cancel
88+
inputs:
89+
azureSubscription: agent-playground-write
90+
scriptType: bash
91+
scriptLocation: inlineScript
92+
inlineScript: |
93+
set -euo pipefail
94+
ADO_TOKEN=$(az account get-access-token \
95+
--resource 499b84ac-1321-427f-aa17-267ca6975798 \
96+
--query accessToken -o tsv)
97+
test -n "$ADO_TOKEN"
98+
echo "##vso[task.setvariable variable=SC_WRITE_TOKEN;issecret=true]$ADO_TOKEN"
99+
85100
- script: |
86101
set -euo pipefail
87102
node scripts/ado-script/exec-context-pr-synth.js
@@ -140,8 +155,9 @@ jobs:
140155
ADO_SOURCE_BRANCH: ${{ parameters.sourceBranchFact }}
141156
ADO_TARGET_BRANCH: ${{ parameters.targetBranchFact }}
142157
ADO_COMMIT_MESSAGE: ${{ parameters.commitMessage }}
143-
# REST auth for API facts (labels, changed files) + self-cancel.
144-
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
158+
# Dedicated short-lived write identity for API facts + self-cancel.
159+
# The token is mapped only into this gate step.
160+
SYSTEM_ACCESSTOKEN: $(SC_WRITE_TOKEN)
145161
146162
- script: |
147163
set -euo pipefail

0 commit comments

Comments
 (0)