dotnet / docker-tools

This is a repo to house some common tools for our various docker repos.
MIT License
124 stars 46 forks source link

Improve Azure token logic #1321

Closed mthalman closed 5 months ago

mthalman commented 5 months ago

Fixes https://github.com/dotnet/docker-tools/issues/1316

The original changes from https://github.com/dotnet/docker-tools/pull/1310 and https://github.com/dotnet/docker-tools/pull/1314 were hacks in order to deal with token expiration that occurs with a long-running command. If execution of the command takes longer than an hour and then an attempt is made to retrieve an Azure access token, it will fail. This is resolved by retrieving the token at the beginning of the command instead.

This defines a provider component that returns an Azure credential that's configured with a pre-cached access token. The access tokens are retrieved during the startup of the command during component composition.

In order to get the tokens, we have to know the scope ahead of time. So these are explicitly defined and a token is retrieved for each one of them. When the caller needs the credential, it specifies which scope is needed and the appropriate credential for that scope is returned.