Skip to content

Conversation

thaJeztah
Copy link
Member

@thaJeztah thaJeztah commented Jun 23, 2025

client: Client.ServiceUpdate: don't manually construct header value

client: add staticAuth utility

Add a small utility to create a "RequestAuthConfig" from

client: client.tryImageCreate: accept registry.RequestAuthConfig

Directly accept a privilege-func, and set the auth-header optionally.

client: client.tryImagePush: accept registry.RequestAuthConfig

Directly accept a privilege-func, and set the auth-header optionally.

- Human readable description for the release notes

- A picture of a cute animal (not mandatory but encouraged)

@thaJeztah thaJeztah added this to the 29.0.0 milestone Jun 23, 2025
@thaJeztah thaJeztah changed the title client_auth_RequestAuthConfig client: omit empty headers and use registry.RequestAuthConfig Jun 23, 2025
@thaJeztah thaJeztah marked this pull request as ready for review June 23, 2025 12:11
@thaJeztah thaJeztah force-pushed the client_auth_RequestAuthConfig branch from a042766 to 45e2dcb Compare June 23, 2025 12:14
@thaJeztah thaJeztah requested review from Copilot and vvoland June 23, 2025 12:15
Copilot

This comment was marked as outdated.

@thaJeztah thaJeztah force-pushed the client_auth_RequestAuthConfig branch 4 times, most recently from 950c36b to 0a2e9ea Compare June 23, 2025 15:24
@thaJeztah thaJeztah requested a review from Copilot June 23, 2025 15:29
Copilot

This comment was marked as outdated.

@thaJeztah thaJeztah force-pushed the client_auth_RequestAuthConfig branch from 0a2e9ea to 334698f Compare June 23, 2025 15:36
@thaJeztah thaJeztah requested a review from Copilot June 23, 2025 15:37
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors header handling across client request methods to omit empty headers and to use a registry.RequestAuthConfig for authentication. Key changes include:

  • Updating header assignments to use Set and omitting headers with empty values.
  • Refactoring tryImagePush, tryImageCreate, and ImagePull/ImagePush to accept a RequestAuthConfig.
  • Introducing a new staticAuth utility function in the client/auth.go file.

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
client/service_update.go Changed header assignment to use headers.Set to handle auth header.
client/request.go Added logic to omit empty headers and introduced helper notEmpty.
client/image_push.go Updated tryImagePush signature to use RequestAuthConfig and adjusted logic.
client/image_pull.go Updated tryImageCreate call and privilege function usage for pull.
client/image_create.go Refactored tryImageCreate to accept RequestAuthConfig.
client/auth.go Added staticAuth utility to create a RequestAuthConfig from a static value.
Comments suppressed due to low confidence (2)

client/request.go:302

  • [nitpick] Consider renaming the helper function 'notEmpty' to 'hasNonEmptyValue' for improved clarity about its purpose.
func notEmpty(vals []string) bool {

client/auth.go:10

  • [nitpick] Consider renaming 'staticAuth' to a more descriptive name such as 'createStaticAuthConfig' to better convey its functionality.
func staticAuth(registryAuth string) registry.RequestAuthConfig {

return cli.post(ctx, "/images/create", query, nil, http.Header{
registry.AuthHeader: {registryAuth},
})
func (cli *Client) tryImageCreate(ctx context.Context, query url.Values, resolveAuth registry.RequestAuthConfig) (*http.Response, error) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Basically, I want to start migrating towards always using a "privilege-func" instead of assuming it's static; that way we have more consistent integration points to fetch auth (which could be dynamically)

@thaJeztah thaJeztah force-pushed the client_auth_RequestAuthConfig branch from 334698f to 769149d Compare June 26, 2025 18:54
Copy link
Contributor

@vvoland vvoland 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 err != nil {
return nil, err
}
return resp.Body, nil
}

func (cli *Client) tryImageCreate(ctx context.Context, query url.Values, registryAuth string) (*http.Response, error) {
return cli.post(ctx, "/images/create", query, nil, http.Header{
registry.AuthHeader: {registryAuth},
Copy link
Contributor

Choose a reason for hiding this comment

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

Wondering if we break Hyrum's law with this one 😅

Still, I think this makes sense!

Copy link
Member Author

Choose a reason for hiding this comment

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

This one should probably be ok; more thinking now of we should include the first commit; I realised that addHeaders is also called as part of the hijack, which does the h2c upgrade, and I just found some mention somewhere that HTTP2-Settings (obsolete though!) may have an empty string as value.

I can remove the first commit here, so that we just limit the change to not sending the empty Auth headers.

Copy link
Member Author

Choose a reason for hiding this comment

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

I dropped the first commit here; we can still discuss that one separately.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Add a small utility to create a "RequestAuthConfig" from
a static value.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Directly accept a privilege-func, and set the auth-header optionally.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Directly accept a privilege-func, and set the auth-header optionally.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@thaJeztah thaJeztah force-pushed the client_auth_RequestAuthConfig branch from 769149d to 1c0d381 Compare June 27, 2025 11:12
@thaJeztah thaJeztah changed the title client: omit empty headers and use registry.RequestAuthConfig client: omit empty auth headers and use registry.RequestAuthConfig Jun 27, 2025
@thaJeztah
Copy link
Member Author

Failure is a flaky test; #49348

=== Failed
=== FAIL: github.com/docker/docker/integration/container TestCreateByImageID/image_ID_with_algorithm (60.42s)
    create_test.go:139: assertion failed: error is not nil: error during connect: Post "http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.51/containers/create": EOF

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants