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

Fixed authorization against Cesenta Docker registry authentication #3795

Closed
wants to merge 4 commits into from

Conversation

skoef
Copy link

@skoef skoef commented Nov 1, 2019

I'm using Cesenta authentication for my private docker registry and could not make authorisation work from containerd. After digging through both the code of containerd and cesenta I fixed authorisation by adjusting two things:

With those 2 small fixes I could pull images from my registry.

some docker registry authentication implementations (for instance cesenta)
send a JSON response with "token" instead of the expected "access_token" during
authorization

Signed-off-by: Reinier Schoof <reinier@skoef.nl>
@skoef skoef force-pushed the cesentaCompat branch 2 times, most recently from 49af767 to ff5bdfd Compare November 1, 2019 11:01
@theopenlab-ci
Copy link

theopenlab-ci bot commented Nov 1, 2019

Build succeeded.

@fuweid
Copy link
Member

fuweid commented Nov 4, 2019

HI @skoef , the CI is not happy if you don't sign off for your commit :)

https://github.com/containerd/project/blob/master/CONTRIBUTING.md#sign-your-work
Please git commit -s for your two commits , thanks!

…e and password

Signed-off-by: Reinier Schoof <reinier@skoef.nl>
@codecov-io
Copy link

codecov-io commented Nov 4, 2019

Codecov Report

Merging #3795 into master will increase coverage by 0.01%.
The diff coverage is 70%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3795      +/-   ##
==========================================
+ Coverage      42%   42.01%   +0.01%     
==========================================
  Files         131      131              
  Lines       14589    14598       +9     
==========================================
+ Hits         6128     6134       +6     
- Misses       7547     7549       +2     
- Partials      914      915       +1
Flag Coverage Δ
#linux 45.44% <71.42%> (+0.01%) ⬆️
#windows 36.99% <70%> (+0.02%) ⬆️
Impacted Files Coverage Δ
remotes/docker/authorizer.go 70.4% <70%> (-0.12%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 257a749...28db191. Read the comment docs.

@theopenlab-ci
Copy link

theopenlab-ci bot commented Nov 4, 2019

Build succeeded.

  • containerd-build-arm64 : RETRY_LIMIT in 20m 29s (non-voting)

@skoef
Copy link
Author

skoef commented Nov 4, 2019

I'm just now seeing that a similar fallback for "token" is done in fetchToken(). I'll do a little refactoring to make it more similar. This will also return the proper errNoToken when neither token was provided.

Signed-off-by: Reinier Schoof <reinier@skoef.nl>
@theopenlab-ci
Copy link

theopenlab-ci bot commented Nov 4, 2019

Build succeeded.

  • containerd-build-arm64 : RETRY_LIMIT in 19m 37s (non-voting)

@skoef
Copy link
Author

skoef commented Nov 4, 2019

Not sure why only the travis darwin CI didn't succeed. Also the Appveyor error doesn't seem really related to my change.

@estesp estesp requested a review from dmcgowan November 4, 2019 15:36
Copy link
Member

@estesp estesp left a comment

Choose a reason for hiding this comment

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

LGTM

Signed-off-by: Reinier Schoof <reinier@skoef.nl>
@skoef
Copy link
Author

skoef commented Nov 4, 2019

Just in time I saw that SetBasicAuth() should be called áfter checking if NewRequest() resulted in an error

Copy link
Member

@dmcgowan dmcgowan left a comment

Choose a reason for hiding this comment

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

Cesenta should be either implementing the OAuth endpoint or returning a 405 that it is not implemented. These changes represent an undocumented and unsupported API deviation. I would suggest first getting these changes into Cesenta since it is an open source project. After that is fixed, we can discuss adding these special cases. Like with all special cases, we heavily document the version, date, and those which do not implement the specified protocol.

@skoef
Copy link
Author

skoef commented Nov 4, 2019

@dmcgowan I certainly think that is fair, however, for the Token/AccessToken-part of the PR: this seemed already implemented for fetchToken but never for fetchTokenWithOAuth. Although they both fulfil a different role, the functions behave kind of similar. As there apparently was a reason to implement the fallback from access_token to token in fetchToken, why not add it to fetchTokenWithOAuth as well?

OTOH: I'm far from an OAuth-expert, let's say that as well.

@theopenlab-ci
Copy link

theopenlab-ci bot commented Nov 4, 2019

Build succeeded.

  • containerd-build-arm64 : RETRY_LIMIT in 17m 45s (non-voting)

@dmcgowan
Copy link
Member

dmcgowan commented Nov 4, 2019

@skoef the problem here is that is seems Cesanta is not implementing the POST endpoint at all, however they are also not blocking it and seem to just be handling it like a GET but form data instead of query params. The GET and POST endpoints implement a different protocol (GET was just a custom thing designed by Docker and handles anonymous auth while POST is trying to follow the OAuth specification). I think if there is going to be a workaround related to Cesanta, that workaround should be to fallback to the GET endpoint when the POST fails (this is ideally done through 405 but we have a few other special cases in there). It is important that upstream Cesanta can handle this correctly, that is what that repo is designed to do.

@dmcgowan
Copy link
Member

dmcgowan commented Nov 4, 2019

@skoef what does the response look like today from the POST? If they are returning a 200 with a body that can't be handled properly, we could just fallback in that case, currently our workarounds are just related to status code but we can also consider the body.

@skoef
Copy link
Author

skoef commented Nov 5, 2019

I think if there is going to be a workaround related to Cesanta, that workaround should be to fallback to the GET endpoint when the POST fails (this is ideally done through 405 but we have a few other special cases in there). It is important that upstream Cesanta can handle this correctly, that is what that repo is designed to do.

You're right, I filed a PR with Cesenta's docker_auth (cesanta/docker_auth#265), we'll see what happens there!

@skoef
Copy link
Author

skoef commented Nov 5, 2019

The PR was merged by cesenta, so I'm closing this. Thanks anyway!

@skoef skoef closed this Nov 5, 2019
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.

None yet

5 participants