Skip to content

cli/command/registry: login: improve flag validation #6036

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 2 commits into from
Apr 30, 2025

Conversation

thaJeztah
Copy link
Member

@thaJeztah thaJeztah commented Apr 25, 2025

cli/command/registry: login: improve flag validation

Before this change, some errors could be ambiguous as they did not
distinguish a flag to be omitted, or set, but with an empty value.

For example, if a user would try to loging but with an empty username,
the error would suggest that the --username flag was not set (which
it was);

I don't have MY_USERNAME set in this shell;

printenv MY_USERNAME || echo 'variable not set'
variable not set

Now, attempting to do a non-interactive login would result in an
ambiguous error;

echo "supersecret" | docker login --password-stdin --username "$MY_USERNAME"
Must provide --username with --password-stdin

With this patch applied, the error indicates that the username was empty,
or not set;

echo "supersecret" | docker login --password-stdin --username "$MY_USERNAME"
username is empty
echo "supersecret" | docker login --password-stdin
the --password-stdin option requires --username to be set
echo "supersecret" | docker login --password-stdin --password "supersecret"
conflicting options: cannot specify both --password and --password-stdin

- Human readable description for the release notes

Improve `docker login` error messages for invalid options.

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

Before this change, some errors could be ambiguous as they did not
distinguish a flag to be omitted, or set, but with an empty value.

For example, if a user would try to loging but with an empty username,
the error would suggest that the `--username` flag was not set (which
it was);

I don't have `MY_USERNAME` set in this shell;

    printenv MY_USERNAME || echo 'variable not set'
    variable not set

Now, attempting to do a non-interactive login would result in an
ambiguous error;

        echo "supersecret" | docker login --password-stdin --username "$MY_USERNAME"
        Must provide --username with --password-stdin

With this patch applied, the error indicates that the username was empty,
or not set;

        echo "supersecret" | docker login --password-stdin --username "$MY_USERNAME"
        username is empty
        echo "supersecret" | docker login --password-stdin
        the --password-stdin option requires --username to be set
        echo "supersecret" | docker login --password-stdin --password "supersecret"
        conflicting options: cannot specify both --password and --password-stdin

Signed-off-by: Sebastiaan van Stijn <[email protected]>
@codecov-commenter
Copy link

codecov-commenter commented Apr 25, 2025

Codecov Report

Attention: Patch coverage is 90.00000% with 2 lines in your changes missing coverage. Please review.

Project coverage is 58.99%. Comparing base (aadd787) to head (e7af181).
Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6036      +/-   ##
==========================================
+ Coverage   58.91%   58.99%   +0.08%     
==========================================
  Files         358      358              
  Lines       29988    30004      +16     
==========================================
+ Hits        17666    17700      +34     
+ Misses      11341    11323      -18     
  Partials      981      981              
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@thaJeztah thaJeztah merged commit 58d318b into docker:master Apr 30, 2025
105 checks passed
@thaJeztah thaJeztah deleted the improve_username_handling branch April 30, 2025 17:09
@thaJeztah thaJeztah modified the milestones: 28.1.2, 28.2.0 May 15, 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.

Issue with the --username option in docker login when using --password-stdin
3 participants