Skip to content

docker: cache bearer tokens#234

Merged
runcom merged 1 commit intocontainers:masterfrom
runcom:cache-tokens
Feb 2, 2017
Merged

docker: cache bearer tokens#234
runcom merged 1 commit intocontainers:masterfrom
runcom:cache-tokens

Conversation

@runcom
Copy link
Copy Markdown
Member

@runcom runcom commented Feb 1, 2017

@mtrmac PTAL, just WIP for now as I have to handle tokens refreshing and stuff like that.

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

Copy link
Copy Markdown
Collaborator

@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.

Yeah, something like that.

docker.io seems to expire tokens in 5 minutes, which does seem a bit risky.

Comment thread docker/docker_client.go Outdated
//
// debugging: https://github.com/containers/image/pull/211#issuecomment-273426236 and follows up
func (c *dockerClient) setupRequestAuth(req *http.Request) error {
if c.token != "" {
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.

Move this into the case "bearer" I think.

@runcom runcom force-pushed the cache-tokens branch 2 times, most recently from a9de767 to 0a9d8ea Compare February 2, 2017 10:37
@runcom runcom changed the title [WIP] docker: cache bearer tokens docker: cache bearer tokens Feb 2, 2017
@runcom
Copy link
Copy Markdown
Member Author

runcom commented Feb 2, 2017

@mtrmac PTAL - followed https://github.com/docker/distribution/blob/master/docs/spec/auth/token.md and what docker does also.

@runcom
Copy link
Copy Markdown
Member Author

runcom commented Feb 2, 2017

copying a multi-layers image shows a gain of around 4-5 seconds:

# w/o this patch
./skopeo copy docker://registry oci:registry2  0.31s user 0.24s system 2% cpu 21.696 total
# with this patch
./skopeo copy docker://registry oci:registry  0.27s user 0.20s system 2% cpu 17.360 total

Copy link
Copy Markdown
Collaborator

@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.

ACK, just a few nits.

Comment thread docker/docker_client.go Outdated
if err != nil {
return err
now := time.Now()
if now.After(c.tokenExpiration) || c.token == nil {
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.

Switch the order of the checks; c.tokenExpiration is uninitialized if c.token == nil (and the c.token == nil check is more efficient, but that should not be the decisive criterion).

Is the now variable necessary? AFAICS it has a single user.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

fixed

Comment thread docker/docker_client.go Outdated
type bearerToken struct {
Token string `json:"token"`
ExpiresIn int `json:"expires_in"`
IssuesAt time.Time `json:"issued_at"`
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.

s/IssuesAt/IssuedAt/g ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

fixed thx

Comment thread docker/docker_client.go
if token.ExpiresIn < minimumTokenLifetimeSeconds {
token.ExpiresIn = minimumTokenLifetimeSeconds
logrus.Debugf("Increasing token expiration to: %d seconds", token.ExpiresIn)
}
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.

(This works just fine. It could also be worth considering the case when Issue[sd]At is in the past, possibly even more than minimumTokenLifetimeSeconds in the past. But the current code, in that case, uses the token exactly once, which is a perfectly reasonable behavior. The alternative of extending the token to be valid at least minimumTokenLifetimeSeconds seems to be much worse.)

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

runcom commented Feb 2, 2017

@mtrmac fixed your comments.

@mtrmac
Copy link
Copy Markdown
Collaborator

mtrmac commented Feb 2, 2017

👍 Thanks!

(Also, a nice performance improvement.)

Approved with PullApprove

@runcom
Copy link
Copy Markdown
Member Author

runcom commented Feb 2, 2017

👍

Approved with PullApprove

@runcom runcom merged commit c1893ff into containers:master Feb 2, 2017
@runcom runcom deleted the cache-tokens branch February 2, 2017 15:17
@rhatdan
Copy link
Copy Markdown
Member

rhatdan commented Feb 2, 2017

Nice lets get new skopeo builds.

@runcom
Copy link
Copy Markdown
Member Author

runcom commented Feb 2, 2017

@rhatdan
Copy link
Copy Markdown
Member

rhatdan commented Feb 2, 2017

Awesome.

@mrunalp
Copy link
Copy Markdown
Contributor

mrunalp commented Feb 2, 2017

Nice! Can we pull this into cri-o?

@runcom
Copy link
Copy Markdown
Member Author

runcom commented Feb 2, 2017

@mrunalp I will (likely later today or tomorrow morning, we need to update many of the deps in CRI-O I had opened an issue iirc)

runcom added a commit to projectatomic/docker that referenced this pull request Feb 7, 2017
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
runcom added a commit to projectatomic/docker that referenced this pull request Feb 8, 2017
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
runcom added a commit to projectatomic/docker that referenced this pull request Mar 2, 2017
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
runcom added a commit to projectatomic/docker that referenced this pull request Mar 28, 2017
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
amatsus pushed a commit to amatsus/docker that referenced this pull request Aug 1, 2017
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants