Skip to content

Commit 7132242

Browse files
committed
Quirk for ACR 401 on ".../blobs/uploads/"
Adding auth caching per-URL works well for GitHub Container Registry and Azure Container Registry, _except_ that ACR failed in a confusing way when initiating blob uploads--if presented with a bad token at that point, it failed outright with a 401 (that did not provide enough information for the existing reauthentication flow to do its thing). To avoid this problem, I'm adding a cache exception for that URL pattern. That shouldn't be too costly, since it's called only once per blob upload, so even when doing chunked uploads the bulk of requests should be cacheable.
1 parent 78eda60 commit 7132242

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Microsoft.NET.Build.Containers/AuthHeaderCache.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,17 @@ internal static class AuthHeaderCache
1616

1717
public static bool TryGet(Uri uri, [NotNullWhen(true)] out AuthenticationHeaderValue? header)
1818
{
19+
header = null;
20+
21+
// observed quirk in Azure Container Registry: if you present a token to blobs/uploads and it's wrong,
22+
// it won't give back a www-authenticate header for the reauth mechanism to work. So never return
23+
// a cache for that URI pattern
24+
string[] segments = uri.Segments;
25+
if (segments is [.., "blobs/", "uploads/"])
26+
{
27+
return false;
28+
}
29+
1930
return HostAuthenticationCache.TryGetValue(GetCacheKey(uri), out header);
2031
}
2132

0 commit comments

Comments
 (0)