From c31aec3425be1a34c9635e2f038fd052269cf466 Mon Sep 17 00:00:00 2001 From: Dmitriy Vasyura Date: Fri, 27 Nov 2026 00:25:20 -0800 Subject: [PATCH 1/2] Limit workflow tokens to the steps and operations that need them Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .github/workflows/codeql-analysis.yml | 1 - .github/workflows/info-needed-closer.yml | 4 ++-- .github/workflows/issue-labels.yml | 4 ++-- .github/workflows/pr-labels.yml | 3 +-- build/templates/publish.yml | 15 ++++++--------- 5 files changed, 11 insertions(+), 16 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 9e4016e1..1794155d 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -25,7 +25,6 @@ jobs: name: Analyze runs-on: ubuntu-latest permissions: - actions: read contents: read security-events: write diff --git a/.github/workflows/info-needed-closer.yml b/.github/workflows/info-needed-closer.yml index e74976c2..8b9e0979 100644 --- a/.github/workflows/info-needed-closer.yml +++ b/.github/workflows/info-needed-closer.yml @@ -6,8 +6,7 @@ on: types: [trigger-needs-more-info] workflow_dispatch: -permissions: - issues: write +permissions: {} jobs: main: @@ -19,6 +18,7 @@ jobs: - name: Checkout Actions uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: + persist-credentials: false repository: 'microsoft/vscode-github-triage-actions' path: ./actions ref: stable diff --git a/.github/workflows/issue-labels.yml b/.github/workflows/issue-labels.yml index 04496546..ef2ec94e 100644 --- a/.github/workflows/issue-labels.yml +++ b/.github/workflows/issue-labels.yml @@ -7,8 +7,7 @@ on: env: TRIAGERS: '["karthiknadig","eleanorjboyd","anthonykim1"]' -permissions: - issues: write +permissions: {} jobs: # From https://github.com/marketplace/actions/github-script#apply-a-label-to-an-issue. @@ -22,6 +21,7 @@ jobs: - name: Checkout Actions uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: + persist-credentials: false repository: 'microsoft/vscode-github-triage-actions' ref: stable path: ./actions diff --git a/.github/workflows/pr-labels.yml b/.github/workflows/pr-labels.yml index a79571de..190f2d8d 100644 --- a/.github/workflows/pr-labels.yml +++ b/.github/workflows/pr-labels.yml @@ -13,8 +13,7 @@ jobs: name: 'Ensure Required Labels' runs-on: ubuntu-latest permissions: - issues: write - pull-requests: write + pull-requests: read steps: - name: 'PR impact specified' uses: mheap/github-action-required-labels@23e10fde7e062233401931a0eece796cd9bf3177 # v5.6.0 diff --git a/build/templates/publish.yml b/build/templates/publish.yml index a8460ac4..69f3d652 100644 --- a/build/templates/publish.yml +++ b/build/templates/publish.yml @@ -19,7 +19,7 @@ # # Notes: # - Azure DevOps Marketplace resource GUID (499b84ac-1321-427f-aa17-267ca6975798) is hardcoded in publish script. -# - This uses Managed Identity via AzureCLI@2 to acquire an AAD token and passes it as a PAT. +# - Each publish step uses the managed identity's AAD token through VSCE_PAT. # - Requires extension artifacts already signed (signature file present). # - Node & vsce expected to be prepared by parent pipeline; omit local installation here. # - Artifacts are expected at: $(Build.ArtifactStagingDirectory)/publishFolder/{platform}/ @@ -71,11 +71,12 @@ steps: - ${{ each platform in parameters.buildPlatforms }}: - task: PowerShell@2 displayName: "Publish extension (${{ coalesce(platform.vsceTarget, 'universal') }})" + env: + VSCE_PAT: $(MarketplaceAADToken) inputs: targetType: inline script: | - $aadToken = "$(MarketplaceAADToken)" - if (-not $aadToken) { Write-Error 'MarketplaceAADToken is empty (token acquisition failed).'; exit 1 } + if (-not $env:VSCE_PAT) { Write-Error 'MarketplaceAADToken is empty (token acquisition failed).'; exit 1 } $platformFolder = "${{ coalesce(platform.vsceTarget, 'universal') }}" $root = "$(Build.ArtifactStagingDirectory)/${{ parameters.publishFolder }}/$platformFolder" @@ -105,14 +106,10 @@ steps: if ('${{ parameters.preRelease }}' -eq 'True') { Write-Host 'Publishing as pre-release' - $displayCmd = "Executing: npx @vscode/vsce@latest publish --pat *** --packagePath $vsixPath --manifestPath $manifestPath --signaturePath $signaturePath --no-verify --pre-release" - Write-Host $displayCmd - npx @vscode/vsce@latest publish --pat $aadToken --packagePath $vsixPath --manifestPath $manifestPath --signaturePath $signaturePath --no-verify --pre-release + npx @vscode/vsce@latest publish --packagePath $vsixPath --manifestPath $manifestPath --signaturePath $signaturePath --no-verify --pre-release } else { Write-Host 'Publishing as stable release' - $displayCmd = "Executing: npx @vscode/vsce@latest publish --pat *** --packagePath $vsixPath --manifestPath $manifestPath --signaturePath $signaturePath --no-verify" - Write-Host $displayCmd - npx @vscode/vsce@latest publish --pat $aadToken --packagePath $vsixPath --manifestPath $manifestPath --signaturePath $signaturePath --no-verify + npx @vscode/vsce@latest publish --packagePath $vsixPath --manifestPath $manifestPath --signaturePath $signaturePath --no-verify } if ($LASTEXITCODE -ne 0) { From 80d21223b89fb0387f18472b8cc0b62f5c7bf46e Mon Sep 17 00:00:00 2001 From: Dmitriy Vasyura Date: Fri, 27 Nov 2026 22:45:20 -0800 Subject: [PATCH 2/2] Install the Marketplace publisher before acquiring its token Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- build/templates/publish.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/build/templates/publish.yml b/build/templates/publish.yml index 69f3d652..798a82ae 100644 --- a/build/templates/publish.yml +++ b/build/templates/publish.yml @@ -21,7 +21,7 @@ # - Azure DevOps Marketplace resource GUID (499b84ac-1321-427f-aa17-267ca6975798) is hardcoded in publish script. # - Each publish step uses the managed identity's AAD token through VSCE_PAT. # - Requires extension artifacts already signed (signature file present). -# - Node & vsce expected to be prepared by parent pipeline; omit local installation here. +# - The parent pipeline prepares Node and the npm registry; no source checkout is required. # - Artifacts are expected at: $(Build.ArtifactStagingDirectory)/publishFolder/{platform}/ parameters: @@ -47,9 +47,9 @@ parameters: default: '' steps: - # Node & vsce expected to be prepared by parent pipeline; omit local installation. - - # Assumes files already present at $(Build.ArtifactStagingDirectory)/publishFolder/{platform}/ + # Install once, before the Marketplace credential exists on the publish agent. + - pwsh: npm install --global --prefix "$(Agent.TempDirectory)/marketplace-vsce" @vscode/vsce@4.1.1 --no-audit --no-fund + displayName: Install Marketplace publisher # Step 1: Acquire token only (store secret variable MarketplaceAADToken) - task: AzureCLI@2 @@ -106,10 +106,10 @@ steps: if ('${{ parameters.preRelease }}' -eq 'True') { Write-Host 'Publishing as pre-release' - npx @vscode/vsce@latest publish --packagePath $vsixPath --manifestPath $manifestPath --signaturePath $signaturePath --no-verify --pre-release + & "$(Agent.TempDirectory)/marketplace-vsce/vsce.cmd" publish --packagePath $vsixPath --manifestPath $manifestPath --signaturePath $signaturePath --no-verify --pre-release } else { Write-Host 'Publishing as stable release' - npx @vscode/vsce@latest publish --packagePath $vsixPath --manifestPath $manifestPath --signaturePath $signaturePath --no-verify + & "$(Agent.TempDirectory)/marketplace-vsce/vsce.cmd" publish --packagePath $vsixPath --manifestPath $manifestPath --signaturePath $signaturePath --no-verify } if ($LASTEXITCODE -ne 0) {