Open l2dy opened 1 year ago
Hi @l2dy,
Thank you for raising the issue :)
Make a "preflight" request to the GET /v2/ API Version Check endpoint to retrieve a token without scope constraint and cache it for future requests.
do you mean fetch a full-privileges token ? this seems not very safe
Retry the request without an Authorization header. In this case, Harbor would return the correct WWW-Authenticate header that points to the token service.
this may be a relevant option from the moment we are in the authentication retry loop, no need to have an expired ( useless) token.
I beleive that we should wait for an explanation from harbor side to find out the motivation behind this behavior ( that diverges from other registry already supported by nerdctl) then we can go further based on their feedback
as a workaround , you may prioritize push
over pull
or use an authenticate proxy to play with headers/token
Make a "preflight" request to the GET /v2/ API Version Check endpoint to retrieve a token without scope constraint and cache it for future requests.
do you mean fetch a full-privileges token ? this seems not very safe
Yes, but in your threat model, does a more privileged token impose any risk?
Retry the request without an Authorization header. In this case, Harbor would return the correct WWW-Authenticate header that points to the token service.
this may be a relevant option from the moment we are in the authentication retry loop, no need to have an expired ( useless) token.
+1
I beleive that we should wait for an explanation from harbor side to find out the motivation behind this behavior ( that diverges from other registry already supported by nerdctl) then we can go further based on their feedback
No reaction on Harbor's side yet.
as a workaround , you may prioritize
push
overpull
or use an authenticate proxy to play with headers/token
Could you elaborate on what prioritize means here? Is it to instruct clients to fetch a write-scoped token for read-only APIs, to give a more privileged token than what the client requested, or for nerdctl to attempt write-scoped APIs first in the push
command?
Edit: typo
@fahedouch Any update on this? Should we go with dropping Authorization
header on retry failure?
@fahedouch Any update on this? Should we go with dropping
Authorization
header on retry failure?
SGTM
Description
Hi, I'm trying
nerdctl push
on a private Harbor registry with Bearer authentication and a custom token service, but the command fails with401 Unauthorized
. After further investigation, it seems to be an interoperability issue between nerdctl and Harbor registries that have disabled basic authentication.When nerdctl requests
GET /v2/<name>/blobs/<digest>
, the registry returns aWWW-Authenticate
header that asks the client to request for a Bearer token with the scope ofrepository:<name>:pull
from the specifiedrealm
. nerdctl would faithfully do so and retry the request with the right credentials, so far so good.But when nerdctl reuses the same token for
POST /v2/<name>/blobs/uploads/
requests, the scope required isrepository:<name>:pull,push
, so this request is denied and the registry returns401 Unauthorized
. The problem is that when a request contains aAuthorization
header but failed to authenticate, Harbor usesBasic realm="harbor"
as the authentication challenge[ref], instead of the token service configured.The registry I'm accessing exclusively relies on Bearer tokens for authentication and has been configured to deny all requests with basic auth. Being mislead by the new
WWW-Authenticate
header, all subsequent requests made by nerdctl would fail.To solve this interop issue, nerdctl could do one of the following:
GET /v2/
API Version Check endpoint to retrieve a token without scope constraint and cache it for future requests.Authorization
header. In this case, Harbor would return the correctWWW-Authenticate
header that points to the token service.On Harbor's side, there is https://github.com/goharbor/harbor/issues/17930, but no decision has been made yet.
Steps to reproduce the issue
nerdctl login ...
nerdctl push <image>
Describe the results you received and expected
Received:
unexpected status from POST request to .../blobs/uploads/: 401 Unauthorized
Expected: Command succeed without errors.
What version of nerdctl are you using?
Are you using a variant of nerdctl? (e.g., Rancher Desktop)
Rancher Desktop for macOS
Host information