Commit Graph

806 Commits

Author SHA1 Message Date
Kristoffer Dalby a22fec9ce1 servertest: drop duplicate not-found tests and use the shared client helper
The per-resource tests already assert the DeleteNode/DeleteUser/RenameUser/
ExpireApiKey/DeleteApiKey 404s; keep only the cases unique to the error
file. TestAPIv1_Health now uses apiClient like the rest.
2026-06-19 05:58:10 +00:00
Kristoffer Dalby a707201ec3 hscontrol: drop the unused grpc-zerolog response-log toggle
The RespLog global was read only by the removed gRPC server's logging
interceptor; HTTP logging goes through the chi zerologRequestLogger. Drop
the dead toggle and the grpc-zerolog dependency.
2026-06-19 05:58:10 +00:00
Kristoffer Dalby 92048385c2 servertest: cover API error translation for missing and invalid input
Asserts not-found nodes/users/keys return 404 and invalid CIDR/policy
return 400. These caught the node-500 and pre-auth-key silent-success
bugs fixed alongside.
2026-06-19 05:58:10 +00:00
Kristoffer Dalby 18f7048c58 hscontrol/api: map missing-node errors to 404
RenameNode and ExpireNode surface ErrNodeNotInNodeStore for an unknown
node; mapStateError only knew ErrNodeNotFound, so they 500'd. Treat both
as not found.
2026-06-19 05:58:10 +00:00
Kristoffer Dalby c386dfe0fd db: report a missing pre-auth key on expire and destroy
Both updated by id without checking RowsAffected, so expiring or deleting
an unknown key silently succeeded. Return ErrPreAuthKeyNotFound, matching
DestroyPreAuthKey's documented contract.
2026-06-19 05:58:10 +00:00
Kristoffer Dalby a9d5ec6202 hscontrol/api: return a minimal 401 for failed security requirements
ogen's SecurityError message echoes the operation name and internal
security text. Map it to a clean 401 so the unauthorized body stays small
and leaks nothing.
2026-06-19 05:58:10 +00:00
Kristoffer Dalby 33774888c2 all: remove dead gRPC config, tests, and helpers
Drop grpc_listen_addr/grpc_allow_insecure config, the gRPC auth integration
tests, GrpcSocketDialer, and stale gRPC comments now that the API is HTTP-only.
2026-06-19 05:58:10 +00:00
Kristoffer Dalby db6b99d414 types: drop the proto builders
Remove the Proto() methods and RegisterMethodToV1Enum; the v1 API builds
responses from the state views directly now.
2026-06-19 05:57:04 +00:00
Kristoffer Dalby 8f5e2e7291 hscontrol: remove the gRPC service and server
Delete grpcv1.go, the TCP gRPC listener, the gRPC auth interceptor, and the
now-unused HTTP bearer middleware. The v1 API is served only over HTTP (TCP +
unix socket) by the ogen stack.
2026-06-19 05:57:04 +00:00
Kristoffer Dalby b5e3b4ee27 hscontrol/api/v1: build responses from state views, not proto
Convert directly from NodeView/UserView/PreAuthKeyView (no AsStruct copies, no
proto bridge), preserving the view types on the read path. Add UserView.Username
and drop the two state.go uses of PreAuthKey.Proto().
2026-06-19 05:57:04 +00:00
Kristoffer Dalby e1325fbacd serve the OpenAPI 3.0 spec at /swagger
Embed openapi/v1/headscale.yaml and point the Swagger UI at it, replacing the
generated Swagger 2.0 document.
2026-06-19 05:57:04 +00:00
Kristoffer Dalby 29fc14dd73 cmd/headscale: run the CLI on the generated v1 HTTP client
Serve the API over the unix socket (auth bypassed; socket permissions are the
trust boundary) and convert every CLI command from the gRPC client to the
generated ogen client. Remote CLI now uses the HTTP API URL.
2026-06-19 05:57:04 +00:00
Kristoffer Dalby de85965bd8 hscontrol/api/v1: implement auth and policy endpoints
AuthRegister/Approve/Reject and GetPolicy/SetPolicy/CheckPolicy over the state
layer, completing all v1 operations. HTTP-parity tests included.
2026-06-19 05:57:04 +00:00
Kristoffer Dalby 83fb0a4548 hscontrol/api/v1: implement node endpoints
Register, Get, List, Delete, Rename, Expire, SetTags, SetApprovedRoutes (with
exit-route expansion), BackfillNodeIPs, DebugCreateNode over the state layer.
Tagged nodes present as TaggedDevices; client errors map to 4xx.
2026-06-19 05:57:04 +00:00
Kristoffer Dalby fc26c447ec hscontrol/api/v1: implement pre-auth key endpoints
CreatePreAuthKey (with ACL tag validation), ListPreAuthKeys, ExpirePreAuthKey,
DeletePreAuthKey over the state layer, with HTTP-parity tests.
2026-06-19 05:57:04 +00:00
Kristoffer Dalby df6876a570 hscontrol/api/v1: implement API key endpoints
CreateApiKey, ListApiKeys, ExpireApiKey, DeleteApiKey (by id or prefix) over
the state layer, with HTTP-parity tests.
2026-06-19 05:57:04 +00:00
Kristoffer Dalby fe76fe0f57 hscontrol/api/v1: implement user endpoints
CreateUser, ListUsers (with filters), RenameUser, DeleteUser over the state
layer; unknown users now 404. HTTP-parity tests via the generated client.
2026-06-19 05:57:04 +00:00
Kristoffer Dalby 562fcc1401 hscontrol: serve v1 API via ogen, replace grpc-gateway facade
Mount the ogen-generated server at /api/v1 with bearer-auth and RFC 7807
errors backed by the state layer; gRPC servers stay for the CLI. Add a
servertest API client harness and Health parity tests.
2026-06-19 05:57:03 +00:00
Kristoffer Dalby 9f1886f587 db: preserve user_id on untagged nodes with tags='null'
A nil tags slice marshals to JSON `null`; the clear-tagged migration
read that as tagged and cleared user_id. Exclude it, and recover
already-detached nodes from their pre-auth key.

Fixes #3323
2026-06-18 14:54:44 +02:00
Kristoffer Dalby ea5165e325 util, db: generate key material as hex via tailscale rands 2026-06-17 16:12:19 +02:00
Kristoffer Dalby 368b9e7edd state: add regression test for NodeKey-rotation binding 2026-06-17 16:12:19 +02:00
Kristoffer Dalby abfd5c9236 types: reject port-bearing server_url under base_domain 2026-06-17 16:12:19 +02:00
Kristoffer Dalby e4cd846075 handlers: set verify Content-Type before writing the body 2026-06-17 16:12:19 +02:00
Kristoffer Dalby 4b693a1320 oidc, types: validate pkce.method when OIDC is active 2026-06-17 16:12:19 +02:00
Kristoffer Dalby 4f4e95fc80 all: adopt strings, errors, and os helpers 2026-06-17 16:12:19 +02:00
Kristoffer Dalby 27468f944b all: adopt maps and cmp helpers 2026-06-17 16:12:19 +02:00
Kristoffer Dalby ac725f27e4 all: adopt slices helpers 2026-06-17 16:12:19 +02:00
Kristoffer Dalby 60f0544b78 dns, change, noise, auth, capver: misc consolidation 2026-06-17 16:12:19 +02:00
Kristoffer Dalby 75b09cb991 servertest: consolidate harness helpers 2026-06-17 16:12:19 +02:00
Kristoffer Dalby 0320b56911 oidc: consolidate cookie helpers and logging 2026-06-17 16:12:19 +02:00
Kristoffer Dalby 62869f01d2 app: simplify TLS and auth setup 2026-06-17 16:12:19 +02:00
Kristoffer Dalby 19d5d9deeb derp: simplify DERP map handling 2026-06-17 16:12:19 +02:00
Kristoffer Dalby c3cfbf1cc0 grpcv1: share list-RPC response helpers 2026-06-17 16:12:19 +02:00
Kristoffer Dalby fdc7e26c8a util: consolidate parsing and encoding helpers 2026-06-17 16:12:19 +02:00
Kristoffer Dalby 45e6e90d11 types: consolidate DNS, identifier, and proto helpers 2026-06-17 16:12:19 +02:00
Kristoffer Dalby 468f70a9e5 templates: consolidate shared page and component helpers 2026-06-17 16:12:19 +02:00
Kristoffer Dalby 8c10a96921 hscontrol: consolidate debug-endpoint and template helpers 2026-06-17 16:12:19 +02:00
Kristoffer Dalby 3979887d8d mapper: consolidate builder and connection helpers 2026-06-17 16:12:19 +02:00
Kristoffer Dalby 03e2d24c79 policy/v2, policy/matcher: consolidate alias and IP-set helpers 2026-06-17 16:12:19 +02:00
Kristoffer Dalby e6ef1dda4d policy: consolidate cache-invalidation and evaluation helpers 2026-06-17 16:12:19 +02:00
Kristoffer Dalby 145672f0b6 state: consolidate route-election and node helpers 2026-06-17 16:12:19 +02:00
Kristoffer Dalby 77f289a627 db: consolidate IP allocation helpers 2026-06-17 16:12:19 +02:00
Kristoffer Dalby 55b9e3cfda db, sqliteconfig: consolidate query and config helpers 2026-06-17 16:12:19 +02:00
Kristoffer Dalby b88a3cb7b2 servertest, hi, integration: remove dead test helpers 2026-06-17 16:12:19 +02:00
Kristoffer Dalby ed6596f9d7 policy, mapper, capver, hscontrol: remove dead code 2026-06-17 16:12:19 +02:00
Kristoffer Dalby f49f27adf8 db, sqliteconfig: remove dead and unreachable code 2026-06-17 16:12:19 +02:00
Kristoffer Dalby 43ba20bebb util: remove dead helpers and stale comments 2026-06-17 16:12:19 +02:00
Kristoffer Dalby c8bd4a0947 types: remove dead types, constants, and methods 2026-06-17 16:12:19 +02:00
Kristoffer Dalby 84168fb90a templates: remove dead style helpers and deprecated shims 2026-06-17 16:12:19 +02:00
Kristoffer Dalby 68a6d3cf17 db: drop ambiguous machine-key getter, match precisely in test helper
The First()-by-machine-key getter returned an undefined node when a machine
key mapped to several nodes. It was used only by RegisterNodeForTest; match on
(machine_key, user_id) there instead and remove the getter.

Updates #3312
2026-06-15 20:29:15 +02:00