Skip to content
This repository was archived by the owner on Feb 1, 2021. It is now read-only.

Add token pass-thru for Authconfig#1384

Merged
vieux merged 2 commits intodocker-archive:masterfrom
dhiltgen:token_auth
Dec 14, 2015
Merged

Add token pass-thru for Authconfig#1384
vieux merged 2 commits intodocker-archive:masterfrom
dhiltgen:token_auth

Conversation

@dhiltgen
Copy link
Copy Markdown
Contributor

@dhiltgen dhiltgen commented Nov 6, 2015

Add token pass-thru for Authconfig

This augments the CreateContainer call to detect the AuthConfig header
and use any supplied auth for pull operations. This will allow pulling
of protected image on to specific node during the create operation.

CLI usage example using username/password:

# Calculate the header
REPO_USER=yourusername
read -s PASSWORD
HEADER=$(echo "{\"username\":\"${REPO_USER}\",\"password\":\"${PASSWORD}\"}"|base64 -w 0 )
unset PASSWORD
echo HEADER=$HEADER

# Then add the following to your ~/.docker/config.json
"HttpHeaders": {
    "X-Registry-Auth": "<HEADER string from above>"
}

# Now run a private image against swarm:
docker run --rm -it yourprivateimage:latest

CLI usage example using registry tokens: (Required engine 1.10 with new auth token support)

REPO=yourrepo/yourimage
REPO_USER=yourusername
read -s PASSWORD
AUTH_URL=https://auth.docker.io/token
TOKEN=$(curl -s -u "${REPO_USER}:${PASSWORD}" "${AUTH_URL}?scope=repository:${REPO}:pull&service=registry.docker.io" |
    jq -r ".token")
HEADER=$(echo "{\"registrytoken\":\"${TOKEN}\"}"|base64 -w 0 )
echo HEADER=$HEADER

# Update the docker config as above, but the token will expire quickly...

Signed-off-by: Daniel Hiltgen daniel.hiltgen@docker.com

@dhiltgen
Copy link
Copy Markdown
Contributor Author

dhiltgen commented Nov 6, 2015

Related to moby/moby#17741 and samalba/dockerclient#184

@MHBauer
Copy link
Copy Markdown
Contributor

MHBauer commented Nov 6, 2015

Looks a lot like #1350, but with a godep update.

@aluzzardi
Copy link
Copy Markdown
Contributor

@ezrasilvera @dhiltgen There seems to be another implementation of this feature in #1350.

I agree with the feature per se - we need this.

Could you two figure out if both PRs address your use case and which one we should merge? I'm happy with either.

Thanks!

@ezrasilvera
Copy link
Copy Markdown
Contributor

@dhiltgen I think there are two separate set of changes here:

  1. Change Swarm to handle auth header during create()
  2. Change the dockerclient to load the auth file and push the credential during run
    This PR tries to cover both (1) and (2). Your changes for (1) are similar/identical to Pass the X-Registry-Auth info in createContainer for the internal pull #1350 - so I suggest we first just merge Pass the X-Registry-Auth info in createContainer for the internal pull #1350 to get the Swarm support. Note that it can already be fully utilized without any change to the dockerclient using the --config flag)
    If needed we can then have a separate unrelated PR to update the GODEP when the dockerclient is updated. (BTW, I actually have additional idea on changing the dockerclient that will save a lot of code for this ..)
    What do you think ?

@dhiltgen
Copy link
Copy Markdown
Contributor Author

dhiltgen commented Dec 8, 2015

Now that the engine PR has merged, and dockerclient has support for the new registrytoken field in AuthConfig, I've updated this PR to include a proper vendoring of dockerclient.

I've also updated the example to show usage from the CLI.

If the maintainers want to split into two PRs that's OK with me.

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.

Do we want to use authConfig here when creating the container? Or up above? Otherwise, what is the point of the godep update?

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.

The engine itself currently does not pull on CreateContainer API calls. Swarm is the only place where this logic is implemented.

The reason I updated dockerclient was to make sure that when the incoming AuthConfig is unmarshaled at https://github.com/docker/swarm/pull/1384/files#diff-379151c15066f365334797e959e6ea94R435 that the registrytoken isn't dropped. I suppose an alternative would have been to pass the base64 encoded header around, but that felt like a bigger deviation from the current flow.

@MHBauer
Copy link
Copy Markdown
Contributor

MHBauer commented Dec 8, 2015

I like that there are examples provided. I don't want to lose them in the commit history. Is there a place in the documentation an example could be placed, would it be better placed in base docker documentation?

I'm not familiar with the godep update process. I'll leave others to comment on that. I do like that it is done in it's own commit.

It would be nice to separate the 'create' support of authconfig from the push/pull support of authconfig, at least by commits. That way we can be sure everything is right in separation.

@ezrasilvera
Copy link
Copy Markdown
Contributor

@dhiltgen if we change dockerclient we might as well add the auth into dockerclient.ContainerConfig and then we would be able to eliminate 99% of the changes in swarm. Basically most of the changes are just passing this additional info that as I said can be avoided.
We would need just a very small change in the handlers.go to populate that structure

@dhiltgen
Copy link
Copy Markdown
Contributor Author

dhiltgen commented Dec 8, 2015

@ezrasilvera I believe the intention in the dockerclient is to keep ContainerConfig consistent with the paylod passed in to http://docs.docker.com/engine/reference/api/docker_remote_api_v1.22/#create-a-container which does not include Auth information. Auth information is passed in through the header. The other prior examples in the client were pull/push, which passed this as a top-level argument, so I followed that pattern.

@dhiltgen dhiltgen force-pushed the token_auth branch 2 times, most recently from 1f7184f to 8bf102f Compare December 9, 2015 16:38
@dhiltgen
Copy link
Copy Markdown
Contributor Author

dhiltgen commented Dec 9, 2015

I've added the examples to the swarm-api docs. If there's a better place for this, please let me know.

@dongluochen
Copy link
Copy Markdown
Contributor

LGTM. The example is helpful. I think we may merge this one. @ezrasilvera can make changes from it. ping @docker/swarm-maintainers.

@jimmyxian
Copy link
Copy Markdown
Contributor

@dhiltgen Thanks for doing this.
Can you upgrade godep cmd and then update dockerclient.
The latest godep will remove _test file.
See this : #1319

Daniel Hiltgen added 2 commits December 11, 2015 18:36
This adds the new auth client token support.

Signed-off-by: Daniel Hiltgen <daniel.hiltgen@docker.com>
This augments the CreateContainer call to detect the AuthConfig header
and use any supplied auth for pull operations.  This will allow pulling
of protected image on to specific node during the create operation.

CLI usage example using username/password:

    # Calculate the header
    REPO_USER=yourusername
    read -s PASSWORD
    HEADER=$(echo "{\"username\":\"${REPO_USER}\",\"password\":\"${PASSWORD}\"}"|base64 -w 0 )
    unset PASSWORD
    echo HEADER=$HEADER

    # Then add the following to your ~/.docker/config.json
    "HttpHeaders": {
        "X-Registry-Auth": "<HEADER string from above>"
    }

    # Now run a private image against swarm:
    docker run --rm -it yourprivateimage:latest

CLI usage example using registry tokens: (Required engine 1.10 with new auth token support)

    REPO=yourrepo/yourimage
    REPO_USER=yourusername
    read -s PASSWORD
    AUTH_URL=https://auth.docker.io/token
    TOKEN=$(curl -s -u "${REPO_USER}:${PASSWORD}" "${AUTH_URL}?scope=repository:${REPO}:pull&service=registry.docker.io" |
        jq -r ".token")
    HEADER=$(echo "{\"registrytoken\":\"${TOKEN}\"}"|base64 -w 0 )
    echo HEADER=$HEADER

    # Update the docker config as above, but the token will expire quickly...

Signed-off-by: Daniel Hiltgen <daniel.hiltgen@docker.com>
@dhiltgen
Copy link
Copy Markdown
Contributor Author

Vendor change fixed to remove the _test files

@abronan
Copy link
Copy Markdown
Contributor

abronan commented Dec 12, 2015

LGTM

1 similar comment
@vieux
Copy link
Copy Markdown
Contributor

vieux commented Dec 14, 2015

LGTM

vieux added a commit that referenced this pull request Dec 14, 2015
Add token pass-thru for Authconfig
@vieux vieux merged commit bbbcd0e into docker-archive:master Dec 14, 2015
@pdevine
Copy link
Copy Markdown

pdevine commented Dec 14, 2015

awesome possums!

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.

10 participants