Skip to content

Password stdin#271

Merged
thaJeztah merged 1 commit intodocker:masterfrom
tych0:password-stdin
Jul 13, 2017
Merged

Password stdin#271
thaJeztah merged 1 commit intodocker:masterfrom
tych0:password-stdin

Conversation

@tych0
Copy link
Copy Markdown
Contributor

@tych0 tych0 commented Jun 29, 2017

Add a --password-stdin argument to the login command, and update the warning message from #270 to tell people about it.

fmt.Fprintf(dockerCli.Err(), "Using --password via the CLI is insecure. Use --password-stdin\n")
if opts.passwordStdin {
return errors.Errorf("--password and --password-stdin are mutually exclusive")
}
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.

I wonder if it would make sense to use -p - to mean stdin. Usually - is only for files, but maybe it would be ok to use that convention here as well.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It would break everyone whose password was "-", so it seems better not to.

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.

Hopefully - is not an acceptable password on any registries, and they all require at least a few more characters..

if opts.passwordStdin {
if opts.user == "" {
return errors.Errorf("Must provide --username with --password-stdin")
}
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.

This doesn't seem to be a requirement for --password, why is it necessary for password-stdin ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If you don't supply a username via --username, it asks via stdin, which then may eat parts of your password, depending on what characters it has in it (e.g. \n). Seems better to just disallow it to prevent confusion to me.

@tych0 tych0 force-pushed the password-stdin branch from 078bd7a to 65e2839 Compare July 3, 2017 14:50
@codecov-io
Copy link
Copy Markdown

codecov-io commented Jul 3, 2017

Codecov Report

Merging #271 into master will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##           master     #271   +/-   ##
=======================================
  Coverage   48.68%   48.68%           
=======================================
  Files         186      186           
  Lines       12416    12416           
=======================================
  Hits         6045     6045           
  Misses       5996     5996           
  Partials      375      375

Comment thread cli/command/registry/login.go Outdated
return err
}

if contents[len(contents)-1] == '\n' {
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.

We should still check that contents != "" before doing that.

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.

Also on Windows we have CRLF so we should test "\r\n" when running on windows.

Do we have helper functions for this @thaJeztah @vdemeester ?

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point. in fact, we should probably just use the stdlib to do all of this. Fixed, thanks!

Comment thread cli/command/registry/login.go Outdated
}

if contents[len(contents)-1] == '\n' {
opts.password = string(contents[:len(contents)-1])
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.

same here for the CRLF, make sure we don't include the '\r'

@tych0 tych0 force-pushed the password-stdin branch from 65e2839 to a3ea86b Compare July 3, 2017 15:46
Comment thread cli/command/registry/login.go Outdated
}

opts.password = strings.TrimSuffix(string(contents), "\n")
if runtime.GOOS == "windows" {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Any reason to limit this to Windows? The password could end up with a CR if it's piped from a file with DOS line endings, or pasted from a weird source. I don't think it will matter much in practice, but applying the same trimming on both platforms would be a slight simplification.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done, thanks.

@tych0 tych0 force-pushed the password-stdin branch from a3ea86b to 4b72c26 Compare July 7, 2017 14:14
@tych0
Copy link
Copy Markdown
Contributor Author

tych0 commented Jul 11, 2017

Ping. Any movement on this?

@n4ss
Copy link
Copy Markdown
Contributor

n4ss commented Jul 11, 2017

LGTM!

@n4ss
Copy link
Copy Markdown
Contributor

n4ss commented Jul 11, 2017

/cc @vdemeester

Copy link
Copy Markdown
Collaborator

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

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

Design LGTM 👼

Comment thread cli/command/registry/login.go Outdated
clnt := dockerCli.Client()

if opts.password != "" {
fmt.Fprintln(dockerCli.Err(), "WARNING! Using --password via the CLI is insecure. Use --password-stdin")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Should there be a period at the end of this? If Using --password via the CLI is insecure is formatted as a sentence, I think Use --password-stdin should be as well.

Comment thread cli/command/registry/login.go Outdated
if opts.password != "" {
fmt.Fprintln(dockerCli.Err(), "WARNING! Using --password via the CLI is insecure. Use --password-stdin")
if opts.passwordStdin {
return errors.Errorf("--password and --password-stdin are mutually exclusive")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

errors.New

And I'm wondering if there's a way to phrase this that's more friendly to people who don't speak english as a first language, but I don't have any good ideas right now.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sure, I've left it as is now and fixed everything else. If someone has a better idea, let me know and I'll change it.

Comment thread cli/command/registry/login.go Outdated

if opts.passwordStdin {
if opts.user == "" {
return errors.Errorf("Must provide --username with --password-stdin")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

errors.New.

This:

* conflicts with --password (naturally)
* conflicts with the absence of --username (both can't be grabbed by the
  stdin)
* strips a trailing newline off the password if it exists

Signed-off-by: Tycho Andersen <tycho@tycho.ws>
@aaronlehmann
Copy link
Copy Markdown

LGTM

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 --password-stdin is a bit verbose, but don't have a better solution (perhaps a -i shortcut)?

We probably want this in 17.07, so I'm ok merging as-is, but we also need;

@tych0
Copy link
Copy Markdown
Contributor Author

tych0 commented Jul 13, 2017

Sure, I can work up docs patches, feel free to merge.

nobiit pushed a commit to nobidev/docker-cli that referenced this pull request Nov 19, 2025
[17.10] backport doc fixes and shell completion script fixes
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.

8 participants