dotnet / dotnet/sdk-container-builds

Don't hard-fail when the Docker credentials file isn't present

Open
#449 1 comment 0 reactions 0 assignees View on GitHub
Area: Authentication Area: Errors
Dominant language
No language data
Stars
197
Forks
53
PR merge metrics
No merged PRs in 30d

Description

When running our tooling on a clean system, we fail with an exception trying to read the Docker config.json. This a) shouldn't be required for 'authentication-less' pulls like those from Docker Hub anyway, and b) should instead be surfaced in a 'we couldn't authenticate to this registry' error instead. So we should protect/recover from failures in the DockerCredsProvider library to sidestep this failure mode.

Stack trace from runtime exception

```
Microsoft.NET.Build.Containers.Credentials.CredentialRetrievalException: CONTAINER1008: Failed retrieving credentials for "registry.hub.docker.com": Docker config '/root/.docker/config.json' doesn't exist.
---> System.IO.FileNotFoundException: Docker config '/root/.docker/config.json' doesn't exist.
at Valleysoft.DockerCredsProvider.CredsProvider.GetCredStoreAsync(String registry, IFileSystem fileSystem, IProcessService processService, IEnvironment environment)
at Valleysoft.DockerCredsProvider.CredsProvider.GetCredentialsAsync(String registry, IFileSystem fileSystem, IProcessService processService, IEnvironment environment)
at Microsoft.NET.Build.Containers.AuthHandshakeMessageHandler.GetAuthenticationAsync(String registry, String scheme, Uri realm, String service, String scope, CancellationToken cancellationToken) in /_/src/Containers/Microsoft.NET.Build.Containers/AuthHandshakeMessageHandler.cs:line 107
--- End of inner exception stack trace ---
at Microsoft.NET.Build.Containers.AuthHandshakeMessageHandler.GetAuthenticationAsync(String registry, String scheme, Uri realm, String service, String scope, CancellationToken cancellationToken) in /_/src/Containers/Microsoft.NET.Build.Containers/AuthHandshakeMessageHandler.cs:line 111
at Microsoft.NET.Build.Containers.AuthHandshakeMessageHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) in /_/src/Containers/Microsoft.NET.Build.Containers/AuthHandshakeMessageHandler.cs:line 182
at System.Net.Http.HttpClient.g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
at Microsoft.NET.Build.Containers.Registry.GetManifestAsync(String repositoryName, String reference, CancellationToken cancellationToken) in /_/src/Containers/Microsoft.NET.Build.Containers/Registry.cs:line 202
at Microsoft.NET.Build.Containers.Registry.GetImageManifestAsync(String repositoryName, String reference, String runtimeIdentifier, String runtimeIdentifierGraphPath, CancellationToken cancellationToken) in /_/src/Containers/Microsoft.NET.Build.Containers/Registry.cs:line 130
at Microsoft.NET.Build.Containers.Tasks.CreateNewImage.ExecuteAsync(CancellationToken cancellationToken) in /_/src/Containers/Microsoft.NET.Build.Containers/Tasks/CreateNewImage.cs:line 49
at Microsoft.NET.Build.Containers.Tasks.CreateNewImage.Execute() in /_/src/Containers/Microsoft.NET.Build.Containers/Tasks/CreateNewImage.cs:line 32
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask)
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in src/Containers/Microsoft.NET.Build.Containers/AuthHandshakeMessageHandler.cs at GetAuthenticationAsync, especially the paths around lines 107 and 111, and trace how DockerCredsProvider failures are handled. Done means a missing Docker config does not hard-fail authentication-less pulls and is surfaced as an authentication failure when credentials are needed.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker
Domain
authentication, build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.