Commit Graph

191 Commits

Author SHA1 Message Date
Csaba Sarkadi 8f632e9062 machine: isOutdated: handle machines without LastSuccefulUpdate set 2022-01-16 14:18:22 +01:00
Csaba Sarkadi 1a6e5d8770 Add support for multiple IP prefixes 2022-01-16 14:18:22 +01:00
Csaba Sarkadi 7ec8346179 Do not assume IPv4 during Tailscale node construction 2022-01-15 16:06:34 +01:00
Kristoffer Dalby 59aeaa8476 Ensure we always have the key prefix when needed 2021-11-27 20:25:12 +00:00
Kristoffer Dalby c38f00fab8 Unmarshal keys in the non-deprecated way 2021-11-26 23:50:42 +00:00
Kristoffer Dalby cfd53bc4aa Factor wgkey to types/key
This commit converts all the uses of wgkey to the new key interfaces.

It now has specific  machine, node and discovery keys and we now should
use them correctly.

Please note the new logic which strips a key prefix (in utils.go) that
is now standard inside tailscale.

In theory we could put it in the database, but to preserve backwards
compatibility and not spend a lot of resources on accounting for both,
we just strip them.
2021-11-26 23:30:42 +00:00
Kristoffer Dalby 68dc2a70db Update neighbours if node is expired or refreshed
In addition, only pass the map of registered and not expired nodes to
clients.
2021-11-22 19:51:16 +00:00
Kristoffer Dalby 021c464148 Add cache for requested expiry times
This commit adds a sentral cache to keep track of clients whom has
requested an expiry time, but were we need to keep hold of it until the
second request comes in.
2021-11-22 19:32:52 +00:00
Kristoffer Dalby e600ead3e9 Make sure nodes can reauthenticate
This commit fixes an issue where nodes were not able to reauthenticate.
2021-11-22 19:32:11 +00:00
Kristoffer Dalby 5cbd4513a4 Simplify register function if 2021-11-22 17:21:56 +00:00
Kristoffer Dalby bd1d1b1a3b Implement ExpireMachine rpc 2021-11-21 13:40:19 +00:00
Kristoffer Dalby 9aac1fb255 Remove expiry logic, this needs to be redone 2021-11-19 09:02:29 +00:00
Kristoffer Dalby 106b1e7e8d Create constants for other reg methods 2021-11-18 17:51:54 +00:00
Kristoffer Dalby d6739386a0
Get rid of dynamic errors 2021-11-15 19:18:14 +00:00
Kristoffer Dalby 25b790d025
Add and fix forcetypeassert 2021-11-15 18:42:44 +00:00
Kristoffer Dalby 715542ac1c
Add and fix stylecheck (golint replacement) 2021-11-15 17:24:24 +00:00
Kristoffer Dalby 0c005a6b01
Add and fix errname 2021-11-15 16:33:16 +00:00
Kristoffer Dalby 0c45f8d252
Add and fix errorlint 2021-11-15 16:26:41 +00:00
Kristoffer Dalby 333be80f9c
Fix rest of var name in main code 2021-11-15 16:15:50 +00:00
Kristoffer Dalby 471c0b4993
Initial work eliminating one/two letter variables 2021-11-14 20:32:03 +01:00
Kristoffer Dalby 85f28a3f4a
Remove all instances of undefined numbers (gonmd) 2021-11-14 18:31:51 +01:00
Kristoffer Dalby 796072a5a4
Add and fix ifshort 2021-11-14 18:09:22 +01:00
Kristoffer Dalby 89eb13c6cb
Add and fix nlreturn (new line return) 2021-11-14 16:46:09 +01:00
Kristoffer Dalby 2634215f12 golangci-lint --fix 2021-11-13 08:39:04 +00:00
Kristoffer Dalby 03b7ec62ca Go format with shorter lines 2021-11-13 08:36:45 +00:00
Kristoffer Dalby 787814ea89 Consolidate machine related lookups
This commit moves the routes lookup functions to be subcommands of
Machine, making them a lot simpler and more specific/composable.

It also moves the register command from cli.go into machine, so we can
clear out the extra file.

Finally a toProto function has been added to convert between the machine
database model and the proto/rpc model.
2021-11-04 22:11:38 +00:00
Kristoffer Dalby cbf3f5d640 Resolve merge conflict 2021-10-30 15:33:01 +00:00
Raal Goff 2d252da221 suggested documentation and comments 2021-10-29 21:35:07 +08:00
Kristoffer Dalby da14750396
Merge branch 'main' into main 2021-10-19 15:26:18 +01:00
Juan Font Alonso 8094e6fdef Preload the Namespace from SharedMachines 2021-10-17 11:59:08 +02:00
unreality afbfc1d370
Merge branch 'main' into main 2021-10-16 22:31:37 +08:00
Juan Font Alonso fa8cd96108 Get peers from namespaces where shared nodes are shared to
This is rather shameful. Shared nodes should have never worked without this.
2021-10-12 17:20:14 +02:00
Juan Font Alonso 48f5a9a18c Fix error 500 when deleting shared node (fixes #133) 2021-10-10 23:55:03 +02:00
Raal Goff 74e6c1479e updates from code review 2021-10-10 17:22:42 +08:00
Juan Font c4487b73c4
Merge branch 'main' into magic-dns-support 2021-10-09 12:24:07 +02:00
Kristoffer Dalby 2997f4d251
Merge branch 'main' into main 2021-10-08 22:21:41 +01:00
Kristoffer Dalby 06f56411dd
Update machine.go 2021-10-07 15:45:45 +01:00
Kristoffer Dalby f0c54490ed Allow multiple namespaces to be checked for state at the same time 2021-10-06 22:06:07 +00:00
Kristoffer Dalby 95f726fb31 Fix logic 2021-10-06 19:56:14 +00:00
Kristoffer Dalby ba391bc2ed Account for updates in shared namespaces 2021-10-06 19:32:15 +00:00
Raal Goff c487591437 use go-oidc instead of verifying and extracting tokens ourselves, rename oidc_endpoint to oidc_issuer to be more inline with spec 2021-10-06 17:19:15 +08:00
Kristoffer Dalby a01a0d1039 Remove unstable update channel, replace with state updates 2021-10-05 16:24:46 +00:00
Juan Font c9a411e341 Preload namespace 2021-10-05 17:47:21 +02:00
Juan Font Alonso a0fa652449 MagicDNS changes merged back 2021-10-04 23:49:16 +02:00
Kristoffer Dalby 2eb57e6288 Clean up pointer usage consistency.
This tries to make the same functions emit and consume the same type of
data all over the application.

If a function transform data, it should emit new data, not a pointer.
2021-10-04 17:39:01 +00:00
Kristoffer Dalby 1d5b090579 Initial work on Prometheus metrics
This commit adds some Prometheus metrics to /metrics in headscale.

It will add the standard go metrics, some automatic gin metrics and some
initial headscale specific ones.

Some of them has been added to aid debugging #97 (loop bug)

In the future, we can use the metrics to get rid of the sleep in the
integration tests by checking that our expected number of nodes has been
registered:

```
headscale_machine_registrations_total
```
2021-10-04 16:28:07 +00:00
Kristoffer Dalby 1bddf1147b
Resolve merge conflict 2021-10-03 11:01:13 +01:00
Kristoffer Dalby 3c3189caa6
Move toNode, add type helpers, split peers and shared
This commit moves toNode to the bottom of the file, and adds a helper
function for lists of Machines to be converted.

It also adds string helpers for Machines and lists of machines.

Lastly it splits getPeers into getDirectPeers, which exist in the same
namespace, and getShared, which is nodes shared with the namespace.

getPeers is kept as a function putting together the two lists for
convenience.
2021-10-02 22:03:34 +01:00
Kristoffer Dalby 0d4a006536
Consitently use Machine pointers
This commit rewrites a bunch of the code to always use *Machine instead
of a mix of both, and a mix of tailcfg.Node and Machine.

Now we use *Machine, and if tailcfg.Node is needed, it is converted just
before needed.
2021-10-02 22:00:09 +01:00
Kristoffer Dalby 0475eb6ef7
Move DB call of pollmap to Machine inside a function 2021-10-02 21:58:28 +01:00
Kristoffer Dalby 39abc4e973
Clarify error messages for nodes that are not connected
If a node does not have an update channel, it is probably not connected,
clarify the log messages and make sure we dont print that it was updated
successfully (continue, not return)
2021-10-02 15:38:53 +01:00
Kristoffer Dalby 6ffea2225d
Attempt to close failed streams
If we have a failed write toward any of our connections, attempt to
close the connection by returning "false" as in unsuccessful stream
2021-10-02 15:28:19 +01:00
Juan Font b83894abd6 Add support for taildrop (#118) 2021-09-24 09:49:29 +02:00
Juan Font b937f9b762
Update machine.go
Added comment on toNode
2021-09-10 00:30:02 +02:00
Juan Font 55f3e07bd4
Apply suggestions from code review
Removed one letter variables

Co-authored-by: Kristoffer Dalby <kradalby@kradalby.no>
2021-09-10 00:26:46 +02:00
Juan Font 2780623076 Renamed SharedNode to SharedMachine 2021-09-06 14:43:43 +02:00
Juan Font 7ce4738d8a Preload namespace so the name can be shown 2021-09-03 10:23:26 +02:00
Juan Font 48b73fa12f Implement node sharing functionality 2021-09-02 16:59:03 +02:00
Kristoffer Dalby ebd27b46af
Add comment to updatemachine 2021-08-23 07:35:44 +01:00
Kristoffer Dalby 88d7ac04bf
Account for racecondition in deleting/closing update channel
This commit tries to address the possible raceondition  that can happen
if a client closes its connection after we have fetched it from the
syncmap before sending the message.

To try to avoid introducing new dead lock conditions, all messages sent
to updateChannel has been moved into a function, which handles the
locking (instead of calling it all over the place)

The same lock is used around the delete/close function.
2021-08-20 16:52:34 +01:00
Kristoffer Dalby b0ec945dbb
Make lastStateChange namespaced 2021-08-19 18:19:26 +01:00
Kristoffer Dalby 8d1adaaef3
Move isOutdated logic to updateChan consumation 2021-08-19 18:05:33 +01:00
Kristoffer Dalby 2f883410d2 Add lastUpdate field to machine, function issue message on update channel
This commit adds a new field to machine, lastSuccessfulUpdate which
tracks when we last was able to send a proper mapupdate to the node. The
purpose of this is to be able to compare to a "global" last updated time
and determine if we need to send an update map request to a node.

In addition it allows us to create a scheduled check to see if all known
nodes are up to date.

Also, add a helper function to send a message to the update channel of a
machine.
2021-08-18 23:17:38 +01:00
Kristoffer Dalby 9698abbfd5
Resolve merge conflict 2021-08-13 10:33:19 +01:00
Juan Font ab61c87701 Also notify peers when deleting ephemerals 2021-08-12 21:53:37 +02:00
Kristoffer Dalby 642c7824a7
Add trace log for machine failing to parce ip in toNode 2021-08-08 17:37:04 +01:00
Kristoffer Dalby ee704f8ef3
Initial port to zerologger 2021-08-05 18:11:26 +01:00
Juan Font Alonso 97f7c90092 Added communication between Serve and CLI using KV table (helps in #52) 2021-07-25 17:59:48 +02:00
Juan Font Alonso 96b4d2f391 Mark the machine as unregistered before soft delete 2021-07-17 11:12:24 +02:00
Juan Font Alonso 9ca2ae7fc5 Implemented delete nodes (#52) 2021-07-17 00:23:12 +02:00
Juan Font Alonso f3139d26c8 Added methods to delete nodes 2021-07-17 00:14:22 +02:00
Juan Font Alonso 0159649d0a Send the namespace name as user to the clients 2021-07-11 16:39:19 +02:00
Juan Font Alonso ff9d99b9ea Use gorm connection pool 2021-07-04 21:40:46 +02:00
Juan Font Alonso aa27709e60 Update code to Tailscale 1.10 2021-06-25 18:57:08 +02:00
Juan Font Alonso 69ba750b38 Update Headscale to depend on gorm v2 2021-06-24 15:44:19 +02:00
Ward Vandewege 41f6740ddd Add support for ephemeral nodes via a special type of pre-auth key. Add
tests for that feature.

Other fixes: clean up a few typos in comments. Fix a bug that caused the
tests to run four times each. Be more consistent in the use of log
rather than fmt to print errors and notices.
2021-05-22 20:18:29 -04:00
Juan Font Alonso e0d916bb5a Remove dependency on postgres' jsonb 2021-05-15 00:05:41 +02:00
Juan Font Alonso 3110dd1575 Added fields in Machine to store authkey + validation tests 2021-05-06 00:08:36 +02:00
Ward Vandewege f7b6c68d22 Address a bunch of golint warnings. 2021-04-24 11:26:50 -04:00
Juan Font Alonso 977962736a Removed log message 2021-03-17 23:09:45 +01:00
Juan Font Alonso 1fad8e6e5b Added basic routes functionality 2021-03-14 11:38:42 +01:00
Juan Font Alonso b7655b1f68 Initial multi-user support using namespaces 2021-02-28 00:58:09 +01:00
Juan Font Alonso 562e996996 Fixed crash when NetInfo is nil 2021-02-24 23:45:27 +01:00
Juan Font Alonso 6a397345aa Headscale is working (Fixed DERP address) 2021-02-24 00:32:34 +01:00
Juan Font Alonso 2b1d92429a Added the name from the HostInfo hostname 2021-02-23 20:10:58 +01:00
Juan Font Alonso 90759688ca Send StableID 2021-02-22 23:27:33 +01:00
Juan Font Alonso a20fffc3e9 Peers is always returned sorted by Node.ID.
(https://github.com/awsong/headscale)
2021-02-22 00:53:37 +01:00
Juan Font Alonso 272eee79fd Added support for DiscoKey
(from https://github.com/awsong/headscale)
2021-02-21 21:34:28 +01:00
Juan Font Alonso acb645aa9d Check that peers are registered when fetching them
Fix from https://github.com/awsong/headscale
2021-02-21 21:03:25 +01:00
Juan Font Alonso c5fbc5baa8 Bumped dependencies 2021-02-20 22:43:07 +01:00
Juan Font Alonso 7198c8bd77 Initial commit 2020-06-21 12:32:08 +02:00