-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Handle CORS headers and OPTIONS method for HTTP API #623
Comments
If you use caddy-docker-proxy, here's the same (mostly) config, done in labels: labels:
caddy: "headscale.${BASE_DOMAIN}"
[email protected]: "headscale.${BASE_DOMAIN}"
[email protected]: "headscale.${BASE_DOMAIN}"
[email protected]: OPTIONS
caddy.0_import: tlsdns
caddy.1_handle: "@hs-options"
caddy.1_handle.header.Access-Control-Allow-Origin: "https://ui.headscale.${BASE_DOMAIN}"
caddy.1_handle.header.Access-Control-Allow-Headers: "*"
caddy.1_handle.header.Access-Control-Allow-Methods: '"POST, GET, OPTIONS, DELETE"'
caddy.1_handle.respond: "204"
caddy.8_handle: /metrics
caddy.8_handle.import: auth
caddy.8_handle.reverse_proxy: "{{upstreams 9090}}"
caddy.9_handle: "@hs-other"
caddy.9_handle.reverse_proxy: "{{upstreams 80}}"
caddy.9_handle.reverse_proxy.header_down_1: "Access-Control-Allow-Origin https://ui.headscale.${BASE_DOMAIN}"
caddy.9_handle.reverse_proxy.header_down_2: "Access-Control-Allow-Headers *"
caddy.9_handle.reverse_proxy.header_down_3: 'Access-Control-Allow-Methods "POST, GET, OPTIONS, DELETE"' |
Someone know how to configure it for Traefik?
Looks like the first part of the problem is solved, but I have a problem with 204 status code in the answer.. I think maybe this plugin should help but I can't configure it properly, it shows me error "status code is smallest than minimum value: 100" |
@deimjons |
@Mikle-Bond Thank you for your attention. I tried this plugin but it didn't help me. I don't know: I doing something wrong or the plugin just not working. I have added additional routes in labels:
also, I added a plugin and middleware (like they show in the documentation example) in the configuration file of traefik: traefik.yaml
As a result, I have the same error:
|
did you manage? I also have to do this edit: https://doc.traefik.io/traefik/v2.4/middlewares/headers/ |
no, I use it via prefix /admin.. (( |
How to add this to Nginx Proxy Manager ? |
Hi, did you ever figure this out? I am also unable to access api via NPM. |
Yes, all working fine, if you using cloudflare disable the proxy (orange cloud) |
Thank you very much. That sorted it. |
I hope to support CORS, and I would like to use healscale directly instead of using Nginx and other programs for proxy, which is very inconvenient |
Has anyone else made this work I can't figure it out. |
I don't use Caddy, and I don't actually have any plans to use it. I just want to run Headscale directly. |
I am getting this error with the above implementation using Headscale-admin |
@B08Z This might be super old and you may have opened an issue on headscale-admin referencing this, but you should be able to use this value to allow CORS from anywhere:
It needs to be explicit for whatever reason. |
This issue is stale because it has been open for 90 days with no activity. |
This issue was closed because it has been inactive for 14 days since being marked as stale. |
This issue is preventing and stopping developers from creating any serious web-ui for headscale and should not be closed, without this, all we're gonna have is the five minute UI's that currently exist. |
Here's my solution for Nginx Proxy Manager. I'm no expert but it works :) I have two different URLs, for example: I put this under the NPM config for headscale.mydomain.com
|
For @mich2k and anyone else looking for the traefik config:
This should work, and prevent the error @B08Z encountered. |
Bug description
When trying to use a browser to generate API requests (like, hypothetically, if you're building a web frontend for headscale), the browser expects to to use CORS to determine if it can talk to the external server. The browser does this by the following:
OPTIONS
request, expecting back a 204 response with the CORS headers attachedFor this to work, we need two things:
OPTIONS
requests without authorization.To Reproduce
Generate a fetch request from a browser in a separate domain. Such as:
If no CORS headers are specified, you get this nice error in the browser console:
If you have the right headers (if you, for example, inject them with a reverse proxy) but the OPTIONS request is blocked by authorization, you get this nice error instead:
Because the OPTIONS request is returning a 401 unauthorized when it shouldn't.
Both are not ideal. You can fix both with a reverse proxy, but you certainly shouldn't have to. The web server (gin?) should return OPTIONS with a 204 and be setting the CORS headers on all requests (and the CORS headers should be configurable).
Context info
These problems were fixed externally by routing through a Caddy reverse proxy using these matching settings:
The text was updated successfully, but these errors were encountered: