10000 cli/command: Reapply "remove uses of GetAuthConfigKey, ParseRepositoryInfo" and add test by thaJeztah · Pull Request #5969 · docker/cli · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
8000

cli/command: Reapply "remove uses of GetAuthConfigKey, ParseRepositoryInfo" and add test #5969

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 27, 2025

Conversation

thaJeztah
Copy link
Member

cli/command: add unit-test for RetrieveAuthTokenFromImage

It's currently slower because it calls registry.ParseRepositoryInfo,
which does a DNS lookup for hostnames to determine if they're a loopback
address (and marked "insecure");

go test -v -run TestRetrieveAuthTokenFromImage
=== RUN   TestRetrieveAuthTokenFromImage
=== RUN   TestRetrieveAuthTokenFromImage/no-prefix
=== RUN   TestRetrieveAuthTokenFromImage/docker.io
=== RUN   TestRetrieveAuthTokenFromImage/index.docker.io
=== RUN   TestRetrieveAuthTokenFromImage/registry-1.docker.io
=== RUN   TestRetrieveAuthTokenFromImage/registry.hub.docker.com
=== RUN   TestRetrieveAuthTokenFromImage/[::1]
=== RUN   TestRetrieveAuthTokenFromImage/[::1]:5000
=== RUN   TestRetrieveAuthTokenFromImage/127.0.0.1
=== RUN   TestRetrieveAuthTokenFromImage/localhost
=== RUN   TestRetrieveAuthTokenFromImage/localhost:5000
=== RUN   TestRetrieveAuthTokenFromImage/no-auth.example.com
--- PASS: TestRetrieveAuthTokenFromImage (0.35s)
    --- PASS: TestRetrieveAuthTokenFromImage/no-prefix (0.00s)
    --- PASS: TestRetrieveAuthTokenFromImage/docker.io (0.00s)
    --- PASS: TestRetrieveAuthTokenFromImage/index.docker.io (0.00s)
    --- PASS: TestRetrieveAuthTokenFromImage/registry-1.docker.io (0.08s)
    --- PASS: TestRetrieveAuthTokenFromImage/registry.hub.docker.com (0.12s)
    --- PASS: TestRetrieveAuthTokenFromImage/[::1] (0.13s)
    --- PASS: TestRetrieveAuthTokenFromImage/[::1]:5000 (0.00s)
    --- PASS: TestRetrieveAuthTokenFromImage/127.0.0.1 (0.00s)
    --- PASS: TestRetrieveAuthTokenFromImage/localhost (0.00s)
    --- PASS: TestRetrieveAuthTokenFromImage/localhost:5000 (0.00s)
    --- PASS: TestRetrieveAuthTokenFromImage/no-auth.example.com (0.01s)
PASS
ok  	github.com/docker/cli/cli/command	1.367s

Reapply "cli/command: remove uses of GetAuthConfigKey, ParseRepositoryInfo"

This reverts commit f596202, and reapplies
79141ce.

cli/command: remove uses of GetAuthConfigKey, ParseRepositoryInfo

Re-implement locally, based on the code in github.com/docker/docker/registry,
but leaving out bits that are not used on the client-side, such as
configuration of Mirrors, and configurable insecure-registry, which
are not used on the client side.

This commit contains a regression due to a typo in authConfigKey;

const authConfigKey = "https:/index.docker.io/v1/"

Which is missing a / after the scheme.

Which currently fails the TestRetrieveAuthTokenFromImage test.

cli/command: fix regression in resolving auth from config

This was introduced in 79141ce, which
was reverted in f596202, and re-applied
in the previous commit.

Before this patch, saving credentials worked correctly;

docker login -u thajeztah
Password:
Login Succeeded

cat ~/.docker/config.json
{
	"auths": {
		"https://index.docker.io/v1/": {
			"auth": "REDACTED"
		}
	}
}

But when resolving the credentials, the credentials stored would not be found;

docker pull -q thajeztah/private-test-image
Error response from daemon: pull access denied for thajeztah/private-test-image, repository does not exist or may require 'docker login': denied: requested access to the resource is denied

With this patch applied:

docker pull -q thajeztah/private-test-image
docker.io/thajeztah/private-test-image:latest

Thanks to @mtrmac (Miloslav Trmač) for spotting this mistake!

Note that this PR also improves performance, as no DNS lookups happen to determine
if the registry is a loopback (and "insecure");

go test -v -run TestRetrieveAuthTokenFromImage
=== RUN   TestRetrieveAuthTokenFromImage
=== RUN   TestRetrieveAuthTokenFromImage/no-prefix
=== RUN   TestRetrieveAuthTokenFromImage/docker.io
=== RUN   TestRetrieveAuthTokenFromImage/index.docker.io
=== RUN   TestRetrieveAuthTokenFromImage/registry-1.docker.io
=== RUN   TestRetrieveAuthTokenFromImage/registry.hub.docker.com
=== RUN   TestRetrieveAuthTokenFromImage/[::1]
=== RUN   TestRetrieveAuthTokenFromImage/[::1]:5000
=== RUN   TestRetrieveAuthTokenFromImage/127.0.0.1
=== RUN   TestRetrieveAuthTokenFromImage/localhost
=== RUN   TestRetrieveAuthTokenFromImage/localhost:5000
=== RUN   TestRetrieveAuthTokenFromImage/no-auth.example.com
--- PASS: TestRetrieveAuthTokenFromImage (0.00s)
    --- PASS: TestRetrieveAuthTokenFromImage/no-prefix (0.00s)
    --- PASS: TestRetrieveAuthTokenFromImage/docker.io (0.00s)
    --- PASS: TestRetrieveAuthTokenFromImage/index.docker.io (0.00s)
    --- PASS: TestRetrieveAuthTokenFromImage/registry-1.docker.io (0.00s)
    --- PASS: TestRetrieveAuthTokenFromImage/registry.hub.docker.com (0.00s)
    --- PASS: TestRetrieveAuthTokenFromImage/[::1] (0.00s)
    --- PASS: TestRetrieveAuthTokenFromImage/[::1]:5000 (0.00s)
    --- PASS: TestRetrieveAuthTokenFromImage/127.0.0.1 (0.00s)
    --- PASS: TestRetrieveAuthTokenFromImage/localhost (0.00s)
    --- PASS: TestRetrieveAuthTokenFromImage/localhost:5000 (0.00s)
    --- PASS: TestRetrieveAuthTokenFromImage/no-auth.example.com (0.00s)
PASS
ok  	github.com/docker/cli/cli/command	0.388s

- Human readable description for the release notes

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

It's currently slower because it calls registry.ParseRepositoryInfo,
which does a DNS lookup for hostnames to determine if they're a loopback
address (and marked "insecure");

    go test -v -run TestRetrieveAuthTokenFromImage
    === RUN   TestRetrieveAuthTokenFromImage
    === RUN   TestRetrieveAuthTokenFromImage/no-prefix
    === RUN   TestRetrieveAuthTokenFromImage/docker.io
    === RUN   TestRetrieveAuthTokenFromImage/index.docker.io
    === RUN   TestRetrieveAuthTokenFromImage/registry-1.docker.io
    === RUN   TestRetrieveAuthTokenFromImage/registry.hub.docker.com
    === RUN   TestRetrieveAuthTokenFromImage/[::1]
    === RUN   TestRetrieveAuthTokenFromImage/[::1]:5000
    === RUN   TestRetrieveAuthTokenFromImage/127.0.0.1
    === RUN   TestRetrieveAuthTokenFromImage/localhost
    === RUN   TestRetrieveAuthTokenFromImage/localhost:5000
    === RUN   TestRetrieveAuthTokenFromImage/no-auth.example.com
    --- PASS: TestRetrieveAuthTokenFromImage (0.35s)
        --- PASS: TestRetrieveAuthTokenFromImage/no-prefix (0.00s)
        --- PASS: TestRetrieveAuthTokenFromImage/docker.io (0.00s)
        --- PASS: TestRetrieveAuthTokenFromImage/index.docker.io (0.00s)
        --- PASS: TestRetrieveAuthTokenFromImage/registry-1.docker.io (0.08s)
        --- PASS: TestRetrieveAuthTokenFromImage/registry.hub.docker.com (0.12s)
        --- PASS: TestRetrieveAuthTokenFromImage/[::1] (0.13s)
        --- PASS: TestRetrieveAuthTokenFromImage/[::1]:5000 (0.00s)
        --- PASS: TestRetrieveAuthTokenFromImage/127.0.0.1 (0.00s)
        --- PASS: TestRetrieveAuthTokenFromImage/localhost (0.00s)
        --- PASS: TestRetrieveAuthTokenFromImage/localhost:5000 (0.00s)
        --- PASS: TestRetrieveAuthTokenFromImage/no-auth.example.com (0.01s)
    PASS
    ok  	github.com/docker/cli/cli/command	1.367s

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
…yInfo"

This reverts commit f596202, and reapplies
79141ce.

> cli/command: remove uses of GetAuthConfigKey, ParseRepositoryInfo
>
> Re-implement locally, based on the code in github.com/docker/docker/registry,
> but leaving out bits that are not used on the client-side, such as
> configuration of Mirrors, and configurable insecure-registry, which
> are not used on the client side.

This commit contains a regression due to a typo in `authConfigKey`;

    const authConfigKey = "https:/index.docker.io/v1/"

Which is missing a `/` after the scheme.

Which currently fails the TestRetrieveAuthTokenFromImage test.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This was introduced in 79141ce, which
was reverted in f596202, and re-applied
in the previous commit.

Before this patch, saving credentials worked correctly;

    docker login -u thajeztah
    Password:
    Login Succeeded

    cat ~/.docker/config.json
    {
        "auths": {
            "https://index.docker.io/v1/": {
                "auth": "REDACTED"
            }
        }
    }

But when resolving the credentials, the credentials stored would not be found;

    docker pull -q thajeztah/private-test-image
    Error response from daemon: pull access denied for thajeztah/private-test-image, repository does not exist or may require 'docker login': denied: requested access to the resource is denied

With this patch applied:

    docker pull -q thajeztah/private-test-image
    docker.io/thajeztah/private-test-image:latest

Thanks to mtrmac (Miloslav Trmač) for spotting this mistake!

Suggested-by: Miloslav Trmač <mitr@redhat.com>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@thaJeztah thaJeztah added this to the 28.0.5 milestone Mar 26, 2025
@thaJeztah thaJeztah changed the title Reapply "cli/command: remove uses of GetAuthConfigKey, ParseRepositoryInfo" and add test cli/command: Reapply "remove uses of GetAuthConfigKey, ParseRepositoryInfo" and add test Mar 26, 2025
@codecov-commenter
Copy link
codecov-commenter commented Mar 26, 2025

Codecov Report

Attention: Patch coverage is 53.33333% with 7 lines in your changes missing coverage. Please review.

Project coverage is 59.13%. Comparing base (b8034c0) to head (0e32baf).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5969      +/-   ##
==========================================
+ Coverage   59.09%   59.13%   +0.03%     
==========================================
  Files         354      354              
  Lines       29733    29739       +6     
==========================================
+ Hits        17572    17587      +15     
+ Misses      11191    11178      -13     
- Partials      970      974       +4     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@thaJeztah thaJeztah marked this pull request as ready for review March 26, 2025 13:59
@thaJeztah thaJeztah requested review from vvoland and Benehiko March 26, 2025 14:00
Copy link
Member
@Benehiko Benehiko left a comment

Choose a reason for hiding this comment

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

let's hope this one doesn't get reverted :)

@thaJeztah
Copy link
Member Author

@vvoland ptal 🤗

@thaJeztah
Copy link
Member Author

Bringing this in; just was discussing with @vvoland if we wanted to squash the "fix the regression" commit with the "Reapply" commit (I kept it separate to make it more visible), because it could impact git bisect, but looks like git bisect may be smart enough to handle this if it steps through merge commits (not individual commits).

Let's hope that's the case indeed (otherwise blame me!)

@thaJeztah thaJeztah merged commit 930173a into docker:master Mar 27, 2025
105 checks passed
@thaJeztah thaJeztah deleted the simplify_auth_fixed branch March 27, 2025 12:24
@thaJeztah thaJeztah modified the milestones: 28.0.5, 28.1.0 Apr 10, 2025
@thaJeztah thaJeztah self-assigned this May 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0