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

Registry access with basic auth #254

Closed
wrosenauer opened this issue May 30, 2022 · 8 comments
Closed

Registry access with basic auth #254

wrosenauer opened this issue May 30, 2022 · 8 comments

Comments

@wrosenauer
Copy link

I'm not sure if there is any bug or I just don't get the documentation right.
Trying to run docker-registry-ui 2.2.1 against a self hosted docker registry on k3s.
Both the registry and the registry-ui are behind Traefik with basic auth (same credentials).

From documentation and comments here and there this should be supported but I don't get it to work.

My (k3s) configs are:

for registry-ui: (registry-ui.k3s.example.net)
- name: REGISTRY_TITLE
value: "Docker Registry UI"
- name: DELETE_IMAGES
value: "true"
- name: SINGLE_REGISTRY
value: "true"
- name: REGISTRY_URL
value: "https://registry.k3s.example.net"

registry.k3s.example.net Traefik/Middleware config:
headers:
accessControlAllowMethods:
- GET
- OPTIONS
- PUT
- POST
- DELETE
- HEAD
accessControlAllowHeaders:
- Accept
- Authorization
accessControlAllowOriginList:
- https://registry-ui.k3s.example.net
accessControlAllowCredentials: true
accessControlMaxAge: 100
addVaryHeader: true

Now in the browser I see an XHR request to registry.k3s.example.net which fails with 401 Unauthorized
The browser console than tells me:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://registry.k3s.example.net/v2/_catalog?n=100000. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing). Status code: 401.

Is this expected? Which config did I miss?

@Joxit
Copy link
Owner

Joxit commented May 30, 2022

Hi there, thank you for using my project 😄

If it's the OPTION requests that returns a 401 status code, this may be caused by a docker registry issue, see this comment #104 (comment)

You will need to bypass the miss configuration with traefik and return 200 on every OPTION requests.

@wrosenauer
Copy link
Author

The first request fired against the registry is a
GEThttps://registry.k3s.example.net/v2/_catalog?n=100000
which gets a 401 already.

@Joxit
Copy link
Owner

Joxit commented May 30, 2022

Yes this is normal since you have a basic auth.
The second request should be an OPTION because you are on a different domain name with a credential (basic auth). The OPTION must return a status 200 with all required headers Access Control Origin/Methods etc...
Then the UI will ask your credential...

Please read the thread linked bellow and check if it's also your case

@wrosenauer
Copy link
Author

Unless Firefox' browser console is useless I don't think that is my actual problem.
There is no second request to the registry at all visible neither in the console nor the network tab of the devtools.
image

@Joxit
Copy link
Owner

Joxit commented May 30, 2022

I will need the content of the response, request headers and response headers

@laggage
Copy link

laggage commented Jun 16, 2022

Seems to have the same problem. And after reading #104 (comment) , I add the following config to nginx, everythings get works properly

location / {

+        if ($request_method = 'OPTIONS') {
+           add_header Access-Control-Allow-Origin https://<your_registry_domain>;
+            add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
+            #
+            # Custom headers and headers various browsers *should* be OK with but aren't
+            #
+            add_header 'Access-Control-Allow-Headers' 'Accept,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
+            #
+            # Tell client that this pre-flight info is valid for 20 days
+            #
+            add_header 'Access-Control-Max-Age' 1728000;
+            add_header 'Content-Type' 'text/plain; charset=utf-8';
+            add_header 'Content-Length' 0;
+            add_header Access-Control-Allow-Credentials true;
+            return 204;
+        }

        ....
}

@Joxit
Copy link
Owner

Joxit commented Jun 19, 2022

Hi, thank you for your feedback, I hope this helps @wrosenauer

@Joxit
Copy link
Owner

Joxit commented Oct 21, 2022

Hi, I close this issue due to inactivity.

@Joxit Joxit closed this as completed Oct 21, 2022
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

No branches or pull requests

3 participants