Skip to content

Conversation

@runcom
Copy link
Member

@runcom runcom commented Nov 25, 2016

We already use global flags for docker specific stuff. This patch enables --username and --password to be passed down to containers/image to setup docker's registries auth.

Fixes #253

@mtrmac @cyphar PTAL

Signed-off-by: Antonio Murdaca runcom@redhat.com

@runcom runcom force-pushed the enable-cli-userpass branch from b005861 to 0080512 Compare November 25, 2016 16:35
@mtrmac
Copy link
Contributor

mtrmac commented Nov 25, 2016

I am not really thrilled with the generic option names: if --username and --password never worked, nothing stops us from naming them --docker-username / --docker-password.

I am worried that we really shouldn’t send the same password to several different servers. OTOH the distinction really isn’t between transport types, but between individual hostnames, and that would be a horrible UI, so a generic --username and fervently hoping that the users know what they are doing might be the best we can do.

This should also restore TestCanAuthToPrivateRegistryV2WithoutDockerCfg and perhaps some of the neighboring tests, though.

After that, I guess, LGTM.

@mtrmac
Copy link
Contributor

mtrmac commented Nov 25, 2016

(As for “we already do use generic option names for Docker-specific options”, that's partly legacy. And partly using --cert-path for an unwanted service is not a vulnerability, but sending a password to an unwanted service is. But, really, I am bad at designing UIs,)

@runcom
Copy link
Member Author

runcom commented Nov 25, 2016

This should also restore TestCanAuthToPrivateRegistryV2WithoutDockerCfg and perhaps some of the neighboring tests, though

Sort of.. I have to mock an empty Docker cfg first. I'll add that though, thx.

I am not really thrilled with the generic option names: if --username and --password never worked, nothing stops us from naming them --docker-username / --docker-password.

We used to have user/pass flag in the very first skopeo versions :/

@mtrmac
Copy link
Contributor

mtrmac commented Nov 25, 2016

Yeah; I am not thrilled with --password but I can live with that.

@runcom
Copy link
Member Author

runcom commented Nov 25, 2016

@mtrmac what if we add --src-username and --src-password and the same for dest. That's not horrible to me and IIUC should solve your concern around wrongly sending a password to a wrong server.

@mtrmac
Copy link
Contributor

mtrmac commented Nov 25, 2016

That’s great idea. We can very confidently expect that the sets of servers underlying a transport(atomic: native API + Docker registry API, docker: native API + sigstore) must be under a shared control.

Yes to --{src,dest}-{username,password}, please.

@runcom
Copy link
Member Author

runcom commented Nov 25, 2016

Alright, do note that I'll make these new flags available only to copy. inspect and the now deprecated layers command will continue to behave as usual (w/o any user/pass flag set).

@runcom
Copy link
Member Author

runcom commented Nov 25, 2016

Or wait, I can add username and password flag locally for inspect/layers commands. I'll do this way.

@runcom runcom force-pushed the enable-cli-userpass branch from 0080512 to dda3750 Compare November 26, 2016 09:20
@runcom
Copy link
Member Author

runcom commented Nov 26, 2016

@mtrmac PTAL, before going ahead and add docs/tests/containers/image bits, I would like to have your ack on the direction with copy. I'll also fix layers|inspect once we agree on copy.

@runcom runcom force-pushed the enable-cli-userpass branch from dda3750 to f786369 Compare November 26, 2016 09:24
@rhatdan
Copy link
Member

rhatdan commented Nov 26, 2016

I don't like options with dashes ("-") in them. Could we look at other tools like ssh? Would

--src dwalsh/password@registry --dest mitr/foobar@remote

be better?

@runcom
Copy link
Member Author

runcom commented Nov 26, 2016

@rhatdan fine, but --src isn't clear enough because it's not saying we're talking about credentials

@runcom
Copy link
Member Author

runcom commented Nov 26, 2016

We don't need to specify the registry also, that's implied by src and dest in the command and we don't need that (something like that is how the Docker auth config file works but that's another story, here in the cli we directly honor user/pass combination without checking the registry they'll be used to authenticate against)

@runcom
Copy link
Member Author

runcom commented Nov 26, 2016

@rhatdan @mtrmac BTW, I'm fine compacting "username:password" in the cli as it doesn't make sense to have 2 flags for user/pass when you must always use both. I'll rework this PR once we agree on flags naming though.

@rhatdan
Copy link
Member

rhatdan commented Nov 26, 2016

@runcom It would help me if you gave a couple of examples of what you are proposing for a CLI.

@runcom
Copy link
Member Author

runcom commented Nov 26, 2016

Like --src-creds runcom:password - modulo no dash in the flag

@rhatdan
Copy link
Member

rhatdan commented Nov 26, 2016

I like that better

@mtrmac
Copy link
Contributor

mtrmac commented Nov 29, 2016

BTW, I'm fine compacting "username:password" in the cli as it doesn't make sense to have 2 flags for user/pass when you must always use both. I'll rework this PR once we agree on flags naming though.

That feels a bit off, as a general security habit I like to avoid formatting/parsing and in-band signalling. More importantly, it may make sense to provide an username but not a password (e.g. when authenticating using a Kerberos ticket, or a smartcard)

@runcom
Copy link
Member Author

runcom commented Nov 29, 2016

BTW, I'm fine compacting "username:password" in the cli as it doesn't make sense to have 2 flags for user/pass when you must always use both. I'll rework this PR once we agree on flags naming though.
That feels a bit off, as a general security habit I like to avoid formatting/parsing and in-band signalling. More importantly, it may make sense to provide an username but not a password (e.g. when authenticating using a Kerberos ticket, or a smartcard)

alright, no parsing then, any idea regarding Dan's issue on naming?

@rhatdan
Copy link
Member

rhatdan commented Nov 29, 2016

Why wouldn't --cred dwalsh
Cause the passwd checks to happen to use kerberos like sshd does?

I guess if you had a case where there was a password without a user then we have a problem.

@mtrmac
Copy link
Contributor

mtrmac commented Nov 29, 2016

Why wouldn't --cred dwalsh
Cause the passwd checks to happen to use kerberos like sshd does?

Good point, that works fine.

@runcom
Copy link
Member Author

runcom commented Nov 29, 2016

Why wouldn't --cred dwalsh
Cause the passwd checks to happen to use kerberos like sshd does?
Good point, that works fine.

I probably missed something, are we ok with --creds username:password? I didn't understand Dan's example 😕

@mtrmac
Copy link
Contributor

mtrmac commented Nov 29, 2016

I don't like options with dashes ("-") in them.

This could also be handled by providing aliases:

cli.StringFlag {
    Name: "src-username, suser"
    // …
}

and then

skopeo copy --suser mitr --spass sourcepass $source --duser Miloslav --dpass destpass $dest

(or even --su/--sp/--du/--dp but that’s probably too unreadable).

OTOH it is more typing than

skopeo copy --screds mitr:sourcepass $source --dcreds Miloslav:destpass $dest

@rhatdan
Copy link
Member

rhatdan commented Nov 29, 2016

runcom I am just giving a username not a password
--creds dwalsh
Means Username = dwalsh No password
--creds dwalsh:foobar
Means Username=dwalsh Password=foobar.

SignBy: signBy,
ReportWriter: os.Stdout,
SourceCtx: sourceCtx,
DestinationCtx: destinationCtx,
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess this is unavoidable :/

@mtrmac
Copy link
Contributor

mtrmac commented Nov 29, 2016

Overall, I like the separation of username/password but it does mean quite a bit of extra typing.

WRT the too-long-option names, we can provide shortcuts but it would still be nice to at least allow using long readable ones (--dcreds is also pretty cryptic).

= overall I don’t have a strong opinion on the single/two-argument decision.

@mtrmac
Copy link
Contributor

mtrmac commented Nov 29, 2016

We can very confidently expect that the sets of servers underlying a transport(atomic: native API + Docker registry API, docker: native API + sigstore) must be under a shared control.

Sadly, we can’t, when uploading to docker.io for docker/distribution vs. company-specific sigstore.

Ouch.

(This does not immediately affect this PR because that is only setting a docker/distribution username:password. But any more such cases, and telling the user to run docker login so that we have a hostname-associated configuration stored and not a bazillion of command-line options will start to look pretty good.)

@runcom
Copy link
Member Author

runcom commented Nov 29, 2016

runcom I am just giving a username not a password
--creds dwalsh
Means Username = dwalsh No password
--creds dwalsh:foobar
Means Username=dwalsh Password=foobar.

Yup, thanks @rhatdan - I was asking if @mtrmac is fine with that also, Miloslav are you?

@runcom runcom force-pushed the enable-cli-userpass branch 2 times, most recently from f46a027 to 3f88a84 Compare November 30, 2016 12:05
if err != nil {
return nil, err
}
fmt.Println(username)
Copy link
Member

Choose a reason for hiding this comment

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

Looks like debug outpuy

Copy link
Member Author

Choose a reason for hiding this comment

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

Yup I'll drop this

@rhatdan
Copy link
Member

rhatdan commented Nov 30, 2016

Missing changes to man pages and bash completions.

@runcom
Copy link
Member Author

runcom commented Nov 30, 2016

Yup, if @mtrmac ack on the changes done so far, I'll update man, docs and everything else (adding tests also)

@runcom runcom force-pushed the enable-cli-userpass branch 3 times, most recently from aa1dc73 to 5d246b3 Compare November 30, 2016 14:44
@runcom
Copy link
Member Author

runcom commented Nov 30, 2016

This is ready to be reviewed fully. @mtrmac @rhatdan added man changes, README changes, tests, completions (it's auto-generated so...). What's missing is to create a PR for containers/image changes, I'll do that shortly after this has been reviewed.

README.md Outdated
Private registries with authentication
-
When interacting with private registries, `skopeo` first looks for the Docker's cli config file (usually located at `$HOME/.docker/config.json`) to get the credentials needed to authenticate. When the file isn't available it falls back looking for `--username` and `--password` flags. The ultimate fallback, as Docker does, is to provide an empty authentication when interacting with those registries.
When interacting with private registries, `skopeo` first looks for the Docker's cli config file (usually located at `$HOME/.docker/config.json`) to get the credentials needed to authenticate. When the file isn't available it falls back looking for `--creds` (for `skopeo inspect`) or `--src-creds|--dest-creds` (for `skopeo copy`) flags. The ultimate fallback, as Docker does, is to provide an empty authentication when interacting with those registries.
Copy link
Member

Choose a reason for hiding this comment

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

I think this is wrong. If the user specified --creds, --src-creds, --dest-creds, it should override content in config.json rather then fall back.

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 think this is wrong. If the user specified --creds, --src-creds, --dest-creds, it should override content in config.json rather then fall back.

Yeah, it's already this way, this piece of the README is wrong, I'll fix it.

docs/skopeo.1.md Outdated

**--sign-by=**_key-id_ add a signature using that key ID for an image name corresponding to _destination-image_

**--src-creds** _username:password_ for accessing the source registry
Copy link
Member

Choose a reason for hiding this comment

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

Should this be

_username[:password]_

Copy link
Member Author

Choose a reason for hiding this comment

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

very likely, I'll fix it

@rhatdan
Copy link
Member

rhatdan commented Nov 30, 2016

Still missing bash completion fixes.

@runcom
Copy link
Member Author

runcom commented Nov 30, 2016

Still missing bash completion fixes.

where is bash completion? hack/make/bash_autocomplete auto generates the bash completion on make install - not sure what I should fix 😕

@rhatdan
Copy link
Member

rhatdan commented Nov 30, 2016

Looks like it only generates one level of bash completions. Lets ignore this for now and we can open an issue to have a much more complete bach completions.

@runcom
Copy link
Member Author

runcom commented Nov 30, 2016

Looks like it only generates one level of bash completions. Lets ignore this for now and we can open an issue to have a much more complete bach completions.

ack, there's already an issue upstream which tracks this urfave/cli#188

README.md Outdated
# passing --username and --password - we can see that everything goes fine
$ skopeo --docker-cfg="" --username=testuser --password=testpassword inspect docker://myregistrydomain.com:5000/busybox
# passing --creds - we can see that everything goes fine
$ skopeo --docker-cfg="" --creds=testuser:testpassword inspect docker://myregistrydomain.com:5000/busybox
Copy link
Contributor

Choose a reason for hiding this comment

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

--docker-cfg seems not to exist at all

if err := ref.DeleteImage(contextFromGlobalOptions(context)); err != nil {
ctx := contextFromGlobalOptions(context)
if context.IsSet("creds") {
ctx.DockerAuthConfig, err = getDockerAuth(context.String("creds"))
Copy link
Contributor

Choose a reason for hiding this comment

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

If everyone is going to use it like this, shouldn't it be folded into contextFromGlobalOptions(context, creds-option-name)?

cli.StringFlag{
Name: "src-creds, screds",
Value: "",
Usage: "Use `USERNAME:PASSWORD` for accessing the source registry",
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this use USERNAME[:PASSWORD], i.e. does that work with the template-variable markers? (If so, please fix everywhere)

// ParseImage converts image URL-like string to an initialized handler for that image.
// parseImage converts image URL-like string to an initialized handler for that image.
// The caller must call .Close() on the returned Image.
func parseImage(c *cli.Context) (types.Image, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should parseImageSource be also updated to support --creds? (This would make it work for skopeo layers, though I am more concerned about the API symmetry than layers as such)

@runcom runcom force-pushed the enable-cli-userpass branch from 5d246b3 to c8fd763 Compare November 30, 2016 15:55
@runcom
Copy link
Member Author

runcom commented Nov 30, 2016

@mtrmac @rhatdan updated

Copy link
Contributor

@mtrmac mtrmac left a comment

Choose a reason for hiding this comment

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

Thanks!

func contextFromGlobalOptions(c *cli.Context) *types.SystemContext {
tlsVerify := c.GlobalBoolT("tls-verify")
func contextFromGlobalOptions(c *cli.Context, credsFlag string) (*types.SystemContext, error) {
ctx := newBaseSystemContext(c)
Copy link
Contributor

Choose a reason for hiding this comment

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

I don’t think we need the separate newBaseSystemContext function now that credsFlag is handled inline. (Eventually we may support credsFlag == "" to turn that off, but we don’t need that now.)

This does work just fine, feel free to merge as is.

Copy link
Member Author

Choose a reason for hiding this comment

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

done, thx

@rhatdan
Copy link
Member

rhatdan commented Nov 30, 2016

Bash Completions #256

Signed-off-by: Antonio Murdaca <runcom@redhat.com>
@runcom
Copy link
Member Author

runcom commented Nov 30, 2016

Bash Completions #256

thanks Dan, we'll merge this one and re-iterate on #256

@runcom runcom merged commit 7cca84b into containers:master Nov 30, 2016
@runcom runcom deleted the enable-cli-userpass branch November 30, 2016 16:29
@runcom
Copy link
Member Author

runcom commented Nov 30, 2016

my bad, I have to fix containers/image and revendor here. I'll do it asap, sorry

@runcom runcom mentioned this pull request Nov 30, 2016
@mtrmac mtrmac mentioned this pull request Dec 1, 2016
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants