Skip to content

Use Azure Pipelines Credential for authentication in ImageBuilder - #1712

Merged
lbussell merged 16 commits into
dotnet:mainfrom
lbussell:issue-1711
May 28, 2025
Merged

lbussell merged 16 commits into
dotnet:mainfrom
lbussell:issue-1711

Conversation

@lbussell

@lbussell lbussell commented May 23, 2025 •

Copy link
Copy Markdown
Member

This is part 1/2 of #1711.

Replaces all usage of WorkloadIdentityCredential with AzurePipelinesCredential. AzurePipelinesCredential uses service connection information in combination with the pipeline System.AccessToken to authenticate. AzurePipelinesCredential is simpler than WorkloadIdentityCredential, but it didn't exist when we initially moved away from service principal/token authentication. Now, we need to adopt this in order to enable using multiple service connections in one ImageBuilder command.

I have validated that all of this works in a container, in an Azure pipeline. I am preparing the pipeline template changes for this change separately.

Part 2/2 will be to add a second service connection argument to the build command, so that we can authenticate to an internal storage account for internal builds.

@lbussell
lbussell marked this pull request as ready for review May 23, 2025 22:24
@lbussell
lbussell requested a review from a team as a code owner May 23, 2025 22:24
@lbussell
lbussell enabled auto-merge (squash) May 28, 2025 16:24
@lbussell
lbussell merged commit f43d722 into dotnet:main May 28, 2025
lbussell added a commit that referenced this pull request Dec 8, 2025
Previously, AzureTokenCredentialProvider would use
`WorkloadIdentityCredential` during builds. In order to work around
Workload Identity Credential lifetimes, we implemented a
StaticTokenCredential that immediately fetched the requested token and
cached it forever (added with
#1321). WIF token lifetimes
are documented
[here](https://learn.microsoft.com/en-us/azure/devops/pipelines/release/troubleshoot-workload-identity?view=azure-devops#error-messages).

Since #1712, we use
`AzurePipelinesCredential` instead. `AzurePipelinesCredential` handles
all of the lifetime/expiration concerns. We can use it directly and
allow the Azure SDK to handle caching and automatic refresh when tokens
are close to expiring. I have not found any documented restrictions on
its lifetime. The System.AccessToken and the resulting
AzurePipelinesCredential *should* be valid for the entire length of the
pipeline job and no longer.

I have built a test version of ImageBuilder with this change and
validated it against our longest running build job, here:
https://dev.azure.com/dnceng/internal/_build/results?buildId=2854918&view=logs&j=5b10b89b-008d-5f76-ef8b-7fc595d90c00&t=a505c4d8-3f6e-56eb-f81a-e4be2494dd9a

It happily spends over 3 hours building images and then has no trouble
pushing them.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants