Skip to content

Fix panic when failing to get DefaultAuthConfig#2918

Merged
silvin-lubecki merged 1 commit into
docker:masterfrom
thaJeztah:fix_login_panic
Jan 8, 2021
Merged

Fix panic when failing to get DefaultAuthConfig#2918
silvin-lubecki merged 1 commit into
docker:masterfrom
thaJeztah:fix_login_panic

Conversation

@thaJeztah

@thaJeztah thaJeztah commented Jan 7, 2021

Copy link
Copy Markdown
Member

fixes #2890 Non-root user "docker login" results in panic SIGSEGV segmentation violation
fixes moby/moby#41771 Command 'docker login' does not work
fixes #2954

Commit f32731f (#2818) fixed a potential panic when an error was returned while trying to get existing credentials.

However, other code paths currently use the result of GetDefaultAuthConfig() even in an error condition; this resulted in a panic, because a nil was returned.

We should fix the other code paths to be more resilient, and to not use the result of GetDefaultAuthConfig() if an error occurs, but starting with a minimal patch to fix the immediate issue.

- Description for the changelog

- Fix a panic on `docker login` if no config file is present

@thaJeztah

Copy link
Copy Markdown
Member Author

For reference; the problem situation is here;

authConfig, err = command.GetDefaultAuthConfig(dockerCli, opts.user == "" && opts.password == "", serverAddress, isDefaultRegistry)
if err == nil && authConfig.Username != "" && authConfig.Password != "" {
response, err = loginWithCredStoreCreds(ctx, dockerCli, authConfig)
}
if err != nil || authConfig.Username == "" || authConfig.Password == "" {
err = command.ConfigureAuth(dockerCli, opts.user, opts.password, authConfig, isDefaultRegistry)

If GetDefaultAuthConfig fails (line 118), the authConfig variable is still used (line 120 and/or line 123); those functions expect authConfig to be a *types.AuthConfig, and fail if it's nil. We should look at those code-paths, because it's incorrect to use authConfig if err != nil, but we can do so in a follow-up.

@thaJeztah

Copy link
Copy Markdown
Member Author

@silvin-lubecki @tiborvass PTAL

@thaJeztah

Copy link
Copy Markdown
Member Author

Discussing with @tiborvass @cpuguy83 - I'll update this to do a nil check outside of the function

Commit f32731f fixed a potential panic
when an error was returned while trying to get existing credentials.

However, other code paths currently use the result of `GetDefaultAuthConfig()`
even in an error condition; this resulted in a panic, because a `nil` was
returned.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
@thaJeztah

Copy link
Copy Markdown
Member Author

@tiborvass @cpuguy83 updated; PTAL

@codecov-io

Copy link
Copy Markdown

Codecov Report

Merging #2918 (c2820a7) into master (2291f61) will decrease coverage by 0.01%.
The diff coverage is 20.00%.

@@            Coverage Diff             @@
##           master    #2918      +/-   ##
==========================================
- Coverage   57.05%   57.04%   -0.02%     
==========================================
  Files         297      297              
  Lines       18653    18655       +2     
==========================================
- Hits        10643    10641       -2     
- Misses       7151     7154       +3     
- Partials      859      860       +1     

@cpuguy83 cpuguy83 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@thaJeztah

Copy link
Copy Markdown
Member Author

@silvin-lubecki PTAL

@silvin-lubecki silvin-lubecki left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

4 participants