Skip to content
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

Add token pass-thru for AuthConfig #17741

Merged
merged 1 commit into from Dec 6, 2015
Merged

Conversation

dhiltgen
Copy link
Contributor

@dhiltgen dhiltgen commented Nov 6, 2015

This change allows API clients to retrieve an authentication token from
a registry, and then pass that token directly to the API.

Example usage:

REPO_USER=dhiltgen
read -s PASSWORD
REPO=privateorg/repo
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 )
curl -s -D - -H "X-Registry-Auth: ${HEADER}" -X POST "http://localhost:2376/images/create?fromImage=${REPO}"

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

@calavera
Copy link
Contributor

calavera commented Nov 6, 2015

@docker/security what do you think about this?

@NathanMcCauley
Copy link
Contributor

This makes a lot of sense to me. Design LGTM.

@calavera
Copy link
Contributor

calavera commented Nov 9, 2015

Token sounds like a very generic name to me. Should we use something more specific, like RegistryToken or AuthToken? I'm open to suggestions, and to keep it like this if other people agree.

@NathanMcCauley
Copy link
Contributor

I like RegistryToken in order to distinguish it from AuthToken which will be confused with #15365 and #17412.

@dhiltgen
Copy link
Contributor Author

Name change sounds fine to me. If nobody else speaks up, I'll update this and the related PRs to make the change.

@LK4D4
Copy link
Contributor

LK4D4 commented Nov 14, 2015

LGTM

@calavera
Copy link
Contributor

Is there a way to test this?

PS: We definitely need documentation before merging it 😸

@dhiltgen dhiltgen force-pushed the pull_token branch 4 times, most recently from 7fdfb90 to 1f8a78e Compare November 19, 2015 21:25
@dhiltgen
Copy link
Contributor Author

Unit test and API level documentation added. I wasn't sure if there was someplace better to doc it, since AuthConfig wasn't really described in any of the docs I found.

@dhiltgen
Copy link
Contributor Author

Not sure what to make of the CI build failures - janky seems to be a GPG key download failure. The windows one is a bit harder to make heads or tails of, but I don't see anything related to my change in the log.

@dhiltgen
Copy link
Contributor Author

Hmm... looks like the graph package just went poof - so I need to figure out where this logic needs to shift to.

@aaronlehmann
Copy link
Contributor

This code moved to the distribution package.

@thaJeztah
Copy link
Member

@dhiltgen yup, huge PR was just merged for content addressability; #17924, apologies for that ☺️

@dhiltgen
Copy link
Contributor Author

Thanks all - I've migrated my change over to the new layout, and am just running some final tests now to make sure nothing broke in the transition - I'll update the PR shortly.

@dhiltgen
Copy link
Contributor Author

Updated based on new layout.

@calavera
Copy link
Contributor

LGTM

@thaJeztah
Copy link
Member

not in docs review yet, but can you also add a note to the API changelog; https://github.com/docker/docker/blob/master/docs/reference/api/docker_remote_api.md#v122-api-changes

@abronan
Copy link
Contributor

abronan commented Dec 2, 2015

LGTM (but needs a rebase, sorry @dhiltgen)


{
"registrytoken": "9cbaf023786cd7..."
}
Copy link
Member

Choose a reason for hiding this comment

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

the code examples probably need to be indented more (4 spaces) to show up as code blocks, see the rendered page;

screen shot 2015-12-02 at 20 09 12

@dhiltgen dhiltgen force-pushed the pull_token branch 5 times, most recently from 48d2907 to 4491b31 Compare December 3, 2015 19:39
This change allows API clients to retrieve an authentication token from
a registry, and then pass that token directly to the API.

Example usage:

    REPO_USER=dhiltgen
    read -s PASSWORD
    REPO=privateorg/repo
    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 )
    curl -s -D - -H "X-Registry-Auth: ${HEADER}" -X POST "http://localhost:2376/images/create?fromImage=${REPO}"

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

dhiltgen commented Dec 3, 2015

Rebased and got markdown to cooperate for the code blocks. (additional indentation didn't seem to work so I resorted to the triple-back-tick)

@thaJeztah
Copy link
Member

Thanks, @dhiltgen, markdown can be a PITA with whitespace and lists. I ran make docs on your PR and it rendered correctly now \o/

docs LGTM

ping @jamtur01 @SvenDowideit @moxiegirl for review

@moxiegirl
Copy link
Contributor

LGTM

thaJeztah added a commit that referenced this pull request Dec 6, 2015
Add token pass-thru for AuthConfig
@thaJeztah thaJeztah merged commit 715f6a1 into moby:master Dec 6, 2015
@thaJeztah
Copy link
Member

Thanks @dhiltgen!

@vdemeester
Copy link
Member

🎉

@pdevine
Copy link

pdevine commented Dec 7, 2015

🎆

@thaJeztah thaJeztah added this to the 1.10.0 milestone Jan 15, 2016
@stevvooe
Copy link
Contributor

A little disappointing that this wasn't reviewed by anyone from the distribution team.

There are few issues:

  1. Tokens are typically treated as short-lived. They can be long-lived, but most of the fallback flow doesn't assume this.
  2. How will this handle authentication failures that require the resolution of further permissions? There are protocols in V2 (using 401 status codes) that can instruct the client to request further permissions.

@thaJeztah
Copy link
Member

@stevvooe please don't comment on closed tickets :trollface:

In your opinion, do we need changes to this PR before 1.10? If so, I can open an issue for that. Apologies that distribution didn't fully review this

@stevvooe
Copy link
Contributor

@stevvooe please don't comment on closed tickets :trollface:

This is one of the few cases where it's acceptable. 🐹

In your opinion, do we need changes to this PR before 1.10? If so, I can open an issue for that. Apologies that distribution didn't fully review this

I have no clue. We have no proposal showing why this is needed, other solutions considered, how this will interoperate with the existing push/pull flow or how we can support this going into the future.

I'd like to have seen a more expressive approach that includes exchanging a token on garant for a registry token. This would also have solved the unencrypted credentials issue. The difference being we can issue tokens that have require a higher level of protection and thus can have a longer expiry.

}

func (th *existingTokenHandler) AuthorizeRequest(req *http.Request, params map[string]string) error {
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", th.token))
Copy link
Contributor

Choose a reason for hiding this comment

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

After some thought, we may need to restrict the token to a particular host. Otherwise, we risk credential leak upon redirect. Also, tokens should also be included only on https requests, unless otherwise specified.

For example, this will send the token to s3, leaking it to AWS.

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.

None yet