juanfont / headscale

An open source, self-hosted implementation of the Tailscale control server
BSD 3-Clause "New" or "Revised" License
21.7k stars 1.19k forks source link

Can't register a machine via HTTP API (if logged out?), only via gRPC/CLI #883

Closed joshuataylor closed 7 months ago

joshuataylor commented 1 year ago

When using the HTTP API, you can't register a machine, I think it's because I'm logged out. This issue has appeared in the past : https://github.com/juanfont/headscale/issues/749 https://github.com/juanfont/headscale/pull/754

The error is "Cannot register machine: machine not found in registration cache".

gRPC & the CLI seems to work fine.

To Reproduce

  1. Login to a namespace
  2. Logout
  3. Try and connect using the HTTP API

curl:

curl -X 'POST' \
  'https://example.com/api/v1/machine/register?namespace=mynamespace&key=xxx' \
  -H "Authorization: Bearer xxx" \
  -H 'accept: application/json' \
  -d ''

The logs for GRPC shows this, when I do tailscale up:

2022-10-23T09:32:50Z INF ../home/runner/work/headscale/headscale/api.go:255 > New machine not yet in the database follow_up= machine=josh node_key=[V1hiq] node_key_old=
2022-10-23T09:33:17Z INF unary dur=6.640852 md={":authority":"192.168.68.110:50443","authorization":"Bearer xxx","content-length":"77","content-type":"application/grpc","user-agent":"grpc-elixir/0.5.0"} method=RegisterMachine req={"key":"xxxx","namespace":"foox"} service=headscale.v1.HeadscaleService
2022-10-23T09:33:20Z INF Client is ready to access the tailnet handler=PollNetMap machine=josh

If using HTTP:

2022-10-23T09:34:55Z ERR unary error="machine not found in registration cache" code=Unknown details=[] dur=0.008619 md={":authority":"/var/run/headscale.sock","authorization":"Bearer xxxx","content-type":"application/grpc","grpcgateway-accept":"application/json,application/json","grpcgateway-authorization":"Bearer xxxx","grpcgateway-content-type":"application/json,application/json","grpcgateway-user-agent":"HeadWeb/0.1,req/0.3.1","user-agent":"grpc-go/1.48.0","x-forwarded-for":"192.168.68.108","x-forwarded-host":"example.com"} method=RegisterMachine msg="machine not found in registration cache" req={} service=headscale.v1.HeadscaleService
abheekda1 commented 1 year ago

I'm having the same issue but with the CLI. I'm unable to make sense of what was done in previous issue reports to fix that, but I'm getting the issue like this:

Client:

$ tailscale up --login-server https://headscale.example.tld 

To authenticate, visit:
    https://headscale.example.tld/register/nodekey:xxx

Server:

$ docker-compose exec headscale headscale -u user nodes register --key nodekey:xxx

Cannot register machine: machine not found in registration cache
bmcgonag commented 10 months ago

Having the same issue on a Windows 11 machine.

Start Tailscale App - Browser opens with the content:

"Machine Registration

Run the command below in the headscale sever to add this machine to your network"

headscale nodes register --user USERNAME --key nodekey:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Ran on headscale server, and get the response:

Cannot register machine: machine not found in registration cache

No idea what to try.

github-actions[bot] commented 7 months ago

This issue is stale because it has been open for 90 days with no activity.

github-actions[bot] commented 7 months ago

This issue was closed because it has been inactive for 14 days since being marked as stale.