Skip to content

Dockerhub returns 401 for newly granted token when load balancing to clock-skewed server #647

Closed

Description

@liggitt

moved from moby/moby#22158

Steps to reproduce the issue:

  1. Request a token from dockerhub (GET https://auth.docker.io/token?scope=repository%3Alibrary%2Fmysql%3Apull&service=registry.docker.io)
  2. Immediately use the token to make an API request

Describe the results you received:
A 401 response is sometimes returned

Describe the results you expected:
Tokens are immediately usable

Additional information you deem important (e.g. issue happens only occasionally):

  1. The JWT tokens returned from dockerhub have a nbf (not before) set to exactly the current timestamp of the granting server
  2. If that token is immediately used against dockerhub and is load-balanced to a server with a clock skewed in the past, the token is rejected
  3. Test case at https://gist.github.com/liggitt/e7d06dc1cbc9d44034f762c5654c6fff (worked recreatably with less than 50 attempts when written, but varies due to server clock skew)
$ go run token.go 
............................................
Got 401 response using newly granted token
Token response date header:     Tue, 19 Apr 2016 15:36:40 GMT
Manifest response date header:  Tue, 19 Apr 2016 15:36:39 GMT
Token:
 eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCIsIng1YyI6WyJNSUlDTHpDQ0FkU2dBd0lCQWdJQkFEQUtCZ2dxaGtqT1BRUURBakJHTVVRd1FnWURWUVFERXp0Uk5Gb3pPa2RYTjBrNldGUlFSRHBJVFRSUk9rOVVWRmc2TmtGRlF6cFNUVE5ET2tGU01rTTZUMFkzTnpwQ1ZrVkJPa2xHUlVrNlExazFTekFlRncweE5UQTJNalV4T1RVMU5EWmFGdzB4TmpBMk1qUXhPVFUxTkRaYU1FWXhSREJDQmdOVkJBTVRPMGhHU1UwNldGZFZWam8yUVZkSU9sWlpUVEk2TTFnMVREcFNWREkxT2s5VFNrbzZTMVExUmpwWVRsSklPbFJMTmtnNlMxUkxOanBCUVV0VU1Ga3dFd1lIS29aSXpqMENBUVlJS29aSXpqMERBUWNEUWdBRXl2UzIvdEI3T3JlMkVxcGRDeFdtS1NqV1N2VmJ2TWUrWGVFTUNVMDByQjI0akNiUVhreFdmOSs0MUxQMlZNQ29BK0RMRkIwVjBGZGdwajlOWU5rL2pxT0JzakNCcnpBT0JnTlZIUThCQWY4RUJBTUNBSUF3RHdZRFZSMGxCQWd3QmdZRVZSMGxBREJFQmdOVkhRNEVQUVE3U0VaSlRUcFlWMVZXT2paQlYwZzZWbGxOTWpveldEVk1PbEpVTWpVNlQxTktTanBMVkRWR09saE9Va2c2VkVzMlNEcExWRXMyT2tGQlMxUXdSZ1lEVlIwakJEOHdQWUE3VVRSYU16cEhWemRKT2xoVVVFUTZTRTAwVVRwUFZGUllPalpCUlVNNlVrMHpRenBCVWpKRE9rOUdOemM2UWxaRlFUcEpSa1ZKT2tOWk5Vc3dDZ1lJS29aSXpqMEVBd0lEU1FBd1JnSWhBTXZiT2h4cHhrTktqSDRhMFBNS0lFdXRmTjZtRDFvMWs4ZEJOVGxuWVFudkFpRUF0YVJGSGJSR2o4ZlVSSzZ4UVJHRURvQm1ZZ3dZelR3Z3BMaGJBZzNOUmFvPSJdfQ.eyJhY2Nlc3MiOlt7InR5cGUiOiJyZXBvc2l0b3J5IiwibmFtZSI6ImxpYnJhcnkvbXlzcWwiLCJhY3Rpb25zIjpbInB1bGwiXX1dLCJhdWQiOiJyZWdpc3RyeS5kb2NrZXIuaW8iLCJleHAiOjE0NjEwODA1MDAsImlhdCI6MTQ2MTA4MDIwMCwiaXNzIjoiYXV0aC5kb2NrZXIuaW8iLCJqdGkiOiJYWVVBbXllaVhhR2Zlb2dyeEtEeCIsIm5iZiI6MTQ2MTA4MDIwMCwic3ViIjoiIn0.9CBqwHk70dMdKLZrp_Frdwdx-ndKjEYmKzTUpmyJNpz7PLpF9PDzfbRcDO12ruYmLSlUxzgVVKPb1ljzmyv26A

Either of the following fixes would work:

  1. Create the JWT with a nbf far enough in the past to account for clock-skew between the servers in the auth domain
  2. Allow for clock skew when validating the nbf in a presented JWT.

Activity

  1. marcusmartins commented on Apr 19, 2016

    @marcusmartins

    Thanks for detailed report and test case. We're investigating.

    cc @nwt

  2. vito commented on Apr 26, 2016

    @vito

    We're seeing this pretty frequently. I really don't want to add retry logic for this since 401 Unauthorized is especially "fatal". I suppose we could add a sleep instead but it depends on how drifty your clocks are. :)

  3. marcusmartins commented on Apr 26, 2016

    @marcusmartins

    We're working on a fix and it should be live soon.

  4. soltysh commented on May 6, 2016

    @soltysh

    @marcusmartins any news on the progress?

  5. soltysh commented on Jun 1, 2016

    @soltysh
  6. marcusmartins commented on Jun 2, 2016

    @marcusmartins

    @soltysh @liggitt are you experiencing the issue? We have deployed a couple of fixes in the last month that should address that issue

  7. soltysh commented on Jun 2, 2016

    @soltysh

    @marcusmartins nope I haven't seen it appearing anywhere in our test cases so far. Iow. I'm ok with closing this issue.

  8. marcusmartins commented on Jun 3, 2016

    @marcusmartins

    thanks @soltysh. Closing it for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions