fix(proxy): preserve URL path prefix during registry auth discovery#22989
fix(proxy): preserve URL path prefix during registry auth discovery#22989reasonerjt merged 2 commits intogoharbor:mainfrom
Conversation
|
looks like an alternative to this is #22891 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #22989 +/- ##
==========================================
+ Coverage 66.02% 66.04% +0.01%
==========================================
Files 1073 1073
Lines 116503 116507 +4
Branches 2939 2939
==========================================
+ Hits 76922 76947 +25
+ Misses 35328 35311 -17
+ Partials 4253 4249 -4
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
Hi @mco69 , Thanks for connecting with us. I believe for this feature we need a design approved first, and you could add a proposal on here https://github.com/goharbor/community/tree/main/proposals and join our bi-weekly meeting for further discussion if needs. |
@MinerYang thanks, here is the proposal: goharbor/community#278 |
When a registry endpoint includes a path prefix (e.g. https://hostname/path), the authorizer's initialize method was hardcoded to probe scheme://host/v2/ for auth challenge discovery, discarding the path entirely. This caused two failures for path-prefixed registries: 1. Auth discovery hit the wrong endpoint (missing path prefix) 2. isTarget() refused to attach credentials to actual API requests because the stored /v2/ path didn't match the request's /path/v2/ Extract the path prefix before /v2/ from the first outgoing request and include it when constructing the auth probe URL. The isTarget comparison already handles this correctly once the stored URL contains the full prefix. Signed-off-by: mcolombet <mathieu.colombet@broadcom.com>
048806c to
8b2b98e
Compare
…discovery When a registry endpoint includes a path prefix, the authorizer was hardcoded to probe scheme://host/v2/ discarding the path entirely. This caused auth discovery and credential attachment to fail for path-prefixed registries. Upstream: goharbor/harbor#22989 Signed-off-by: mcolombet <mathieu.colombet@broadcom.com> Signed-off-by: Prasanth Baskar <bupdprasanth@gmail.com>
…discovery When a registry endpoint includes a path prefix, the authorizer was hardcoded to probe scheme://host/v2/ discarding the path entirely. This caused auth discovery and credential attachment to fail for path-prefixed registries. Upstream: goharbor/harbor#22989 Signed-off-by: mcolombet <mathieu.colombet@broadcom.com> Signed-off-by: Prasanth Baskar <bupdprasanth@gmail.com>
…oharbor#22989) When a registry endpoint includes a path prefix (e.g. https://hostname/path), the authorizer's initialize method was hardcoded to probe scheme://host/v2/ for auth challenge discovery, discarding the path entirely. This caused two failures for path-prefixed registries: 1. Auth discovery hit the wrong endpoint (missing path prefix) 2. isTarget() refused to attach credentials to actual API requests because the stored /v2/ path didn't match the request's /path/v2/ Extract the path prefix before /v2/ from the first outgoing request and include it when constructing the auth probe URL. The isTarget comparison already handles this correctly once the stored URL contains the full prefix. Signed-off-by: mcolombet <mathieu.colombet@broadcom.com> (cherry picked from commit 02bdc9e)
…oharbor#22989) When a registry endpoint includes a path prefix (e.g. https://hostname/path), the authorizer's initialize method was hardcoded to probe scheme://host/v2/ for auth challenge discovery, discarding the path entirely. This caused two failures for path-prefixed registries: 1. Auth discovery hit the wrong endpoint (missing path prefix) 2. isTarget() refused to attach credentials to actual API requests because the stored /v2/ path didn't match the request's /path/v2/ Extract the path prefix before /v2/ from the first outgoing request and include it when constructing the auth probe URL. The isTarget comparison already handles this correctly once the stored URL contains the full prefix. Signed-off-by: mcolombet <mathieu.colombet@broadcom.com> Signed-off-by: ipsitapp8 <ipsitapp8@gmail.com>
While Harbor itself does not support being deployed with a path prefix (e.g., /path/v2), it does support proxying registries that use them. This is significant; not only do registries like Artifactory utilizing such deployment structures, but in enterprise environments, where it is often impractical to create a distinct FQDN for every registry endpoint (and proxy may be used).
However when a registry endpoint includes a path prefix (e.g. https:///path), the authorizer's initialize method was hardcoded to probe scheme://host/v2/ for auth challenge discovery, discarding the path entirely. On the flip side, when injecting a Bearer token everything seems to work fine!
This caused two failures for path-prefixed registries:
Extract the path prefix before /v2/ from the first outgoing request and include it when constructing the auth probe URL. The isTarget comparison already handles this correctly once the stored URL contains the full prefix.
As seen in the NGINX logs below, Harbor correctly targets the custom path prefix but fails the subsequent authentication challenge:
As seen in the NGINX logs below, Harbor correctly targets the custom path an image pull succeeds if NGING injects bearer token:
Thank you for contributing to Harbor!
Comprehensive Summary of your change
Issue being fixed
Fixes #(issue)
Please indicate you've done the following: