Skip to content

daemon/router/image: initialize default authConfig#50730

Merged
thaJeztah merged 1 commit intomoby:masterfrom
tiago-teixeira5:fix-push-wo-auth
Aug 14, 2025
Merged

daemon/router/image: initialize default authConfig#50730
thaJeztah merged 1 commit intomoby:masterfrom
tiago-teixeira5:fix-push-wo-auth

Conversation

@tiago-teixeira5
Copy link
Copy Markdown
Contributor

@tiago-teixeira5 tiago-teixeira5 commented Aug 14, 2025

- What I did

Initialize authConfig to an empty value. This should avoid nil pointer dereferences.

- How I did it

Initialize with an empty value.

- How to verify it

Invoking an image push without authentication headers (no X-Registry-Auth) should not cause a nil pointer dereference panic.

@thaJeztah
Copy link
Copy Markdown
Member

Thanks! And thanks for the stack-trace in the ticket; as a follow-up, I want to look at some of the uses of these so that they gracefully handle "no auth config" (nil); looks like various code-paths were depending on existing behavior from elsewhere, not accounting for nil at all 😞

FWIW; I had a quick check on docker pull ("image create" endpoint), and that looks to not have the same problem, as it unconditionally tries to unmarshal the header, even if not set;

// For a pull it is not an error if no auth was given. Ignore invalid
// AuthConfig to increase compatibility with the existing API.
//
// TODO(thaJeztah): accept empty values but return an error when failing to decode.
authConfig, _ := registry.DecodeAuthConfig(r.Header.Get(registry.AuthHeader))
progressErr = ir.backend.PullImage(ctx, ref, platform, metaHeaders, authConfig, output)

Copy link
Copy Markdown
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM if CI is happy (perhaps linters want authConfig := &registry.AuthConfig{})

@tiago-teixeira5
Copy link
Copy Markdown
Contributor Author

(...) (perhaps linters want authConfig := &registry.AuthConfig{})

Indeed, thanks.

Looking at how other functions handle the header, perhaps we can do the

authConfig, _ := registry.DecodeAuthConfig(r.Header.Get(registry.AuthHeader))

I would believe that the if comes from a previous version, where an else would read from the request body, as I referenced in the issue.

Looking at the source code, it seems that a missing header would result in an empty authConfig.

Thoughts?

@thaJeztah
Copy link
Copy Markdown
Member

Yes, I'd be fine with changing it to try unconditionally for now.

My ultimate goal is to be more specific about whether auth is passed or not, so that code-paths further down the line can also make decisions whether they're dealing with an unauthenticated request (and skip some handling, or use alternatives), or authentication is present.

That's not present yet, so I think it's good to just change it to "unconditionally try to unmarshal" (as docker pull does)

Copy link
Copy Markdown
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM, thank you!

@tiago-teixeira5
Copy link
Copy Markdown
Contributor Author

I did a force push to avoid multiple commits, however, I don't think the CI is picking that ...

Any idea how to force the CI to run? Make "Draft" and "Ready" again?

@thaJeztah
Copy link
Copy Markdown
Member

I gave it a kick; it requires approval for first-time contributors; should be running now 👍

@thaJeztah
Copy link
Copy Markdown
Member

All green! Thanks!

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

Projects

None yet

3 participants