9015 Commits

Author SHA1 Message Date
Brad Fitzpatrick
ab2deda4b7 tsnet: add FunnelTLSConfig FunnelOption type
And also validate opts for unknown types, before other side effects.

Fixes #15833

Change-Id: I4cabe16c49c5b7566dcafbec59f2cd1e0c8b4b3c
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2025-04-30 10:36:35 -07:00
Andrew Lytvynov
a9b3e09a1f
tool/gocross: break circular dependency on tailcfg (#15829)
Instead of using the version package (which depends on
tailcfg.CurrentCapabilityVersion) to get the git commit hash, do it
directly using debug.BuildInfo. This way, when changing struct fields in
tailcfg, we can successfully `go generate` it without compiler errors.

Updates #9634
Updates https://github.com/tailscale/corp/issues/26717

Signed-off-by: Andrew Lytvynov <awly@tailscale.com>
2025-04-29 17:35:47 -07:00
Brad Fitzpatrick
cc6f367520 tstest/integration: remove vestigial env var set in tests
TS_CONTROL_IS_PLAINTEXT_HTTP no longer does anything as of
8fd471ce5748d2129dba584b4fa14b0d29229299

Updates #13597

Change-Id: I32ae7f8c5f2a2632e80323b1302a36295ee00736
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2025-04-29 07:34:00 -07:00
James Sanderson
1f1c323eeb control/controlclient,health: add tests for control health tracking
Updates tailscale/corp#27759

Signed-off-by: James Sanderson <jsanderson@tailscale.com>
2025-04-29 12:36:38 +01:00
Brad Fitzpatrick
ac1215c7e0 tstest/integration: export test helpers
In prep for Taildrop integration tests using them from another package.

Updates #15812

Change-Id: I6a995de4e7400658229d99c90349ad5bd1f503ae
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2025-04-28 16:35:19 -07:00
Brad Fitzpatrick
81420f8944 tstest/integration: move code from integration_test.go to integration.go
So it can be exported & used by other packages in future changes.

Updates #15812

Change-Id: I319000989ebc294e29c92be7f44a0e11ae6f7761
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2025-04-28 16:35:19 -07:00
Jordan Whited
61635f8670
wgengine/magicsock: support Geneve-encap'd Disco transmission (#15811)
Updates tailscale/corp#27502

Signed-off-by: Jordan Whited <jordan@tailscale.com>
2025-04-28 15:55:49 -07:00
James Tucker
51b17483ff types/logger: release ArgWriter destination after use
Spotted after Brad showed me this utility in #15806.

Updates #cleanup

Signed-off-by: James Tucker <james@tailscale.com>
2025-04-28 12:54:43 -07:00
James Tucker
b95e8bf4a1 tsweb/varz: export GC CPU fraction gauge
We were missing this metric, but it can be important for some workloads.

Varz memstats output allocation cost reduced from 30 allocs per
invocation to 1 alloc per invocation.

Updates tailscale/corp#28033

Signed-off-by: James Tucker <james@tailscale.com>
Co-authored-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2025-04-28 11:52:21 -07:00
Brad Fitzpatrick
189e03e741 net/portmapper: fix test flakes from logging after test done
Fixes #15794

Change-Id: Ic22aa99acb10fdb6dc5f0b6482e722e48237703c
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2025-04-25 15:54:05 -07:00
Nick Khyl
66371f392a feature,ipn/ipnlocal: add profileManager.StateChangeHook
We update profileManager to allow registering a single state (profile+prefs) change hook.
This is to invert the dependency between the profileManager and the LocalBackend, so that
instead of LocalBackend asking profileManager for the state, we can have profileManager
call LocalBackend when the state changes.

We also update feature.Hook with a new (*feature.Hook).GetOk method to avoid calling both
IsSet and Get.

Updates tailscale/corp#28014
Updates #12614

Signed-off-by: Nick Khyl <nickk@tailscale.com>
2025-04-25 16:32:09 -05:00
Nick Khyl
0cfd643d95 ipn/ipnlocal: update profileManager to use SwitchToProfile when switching to the initial profile
This further minimizes the number of places where the profile manager updates the current profile and prefs.

We also document a scenario where an implicit profile switch can occur.
We should be able to address it after (partially?) inverting the dependency between
LocalBackend and profileManager, so that profileManager notifies LocalBackend
of profile changes instead of the other way around.

Updates tailscale/corp#28014
Updates #12614

Signed-off-by: Nick Khyl <nickk@tailscale.com>
2025-04-25 16:32:09 -05:00
Brad Fitzpatrick
f468919f95 util/mak: delete long-deprecated, unused, pre-generics NonNil func
Updates #5590 (which deprecated it, 2.5 years ago)

Change-Id: I137e82855ee33d91e5639b909f7ca64e237ed6ba
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2025-04-25 14:19:10 -07:00
Nick Khyl
8b72dd7873 ipn/ipnlocal: add localNodeContext with netmap-related fields and methods
Updates #12614

Signed-off-by: Nick Khyl <nickk@tailscale.com>
2025-04-25 15:44:10 -05:00
Jordan Whited
f701d39ba4
net/udprelay: change Server.AllocateEndpoint existing alloc strategy (#15792)
The previous strategy assumed clients maintained adequate state to
understand the relationship between endpoint allocation and the server
it was allocated on.

magicsock will not have awareness of the server's disco key
pre-allocation, it only understands peerAPI address at this point. The
second client to allocate on the same server could trigger
re-allocation, breaking a functional relay server endpoint.

If magicsock needs to force reallocation we can add opt-in behaviors
for this later.

Updates tailscale/corp#27502

Signed-off-by: Jordan Whited <jordan@tailscale.com>
2025-04-25 13:09:09 -07:00
Jordan Whited
dae2319e11
disco: implement CallMeMaybeVia serialization (#15779)
This message type is currently unused and considered experimental.

Updates tailscale/corp#27502

Signed-off-by: Jordan Whited <jordan@tailscale.com>
2025-04-25 13:00:00 -07:00
Brad Fitzpatrick
dbf13976d3 types/mapx, ipn/ipnext: add ordered map, akin to set.Slice
We had an ordered set type (set.Slice) already but we occasionally want
to do the same thing with a map, preserving the order things were added,
so add that too, as mapsx.OrderedMap[K, V], and then use in ipnext.

Updates #12614

Change-Id: I85e6f5e11035571a28316441075e952aef9a0863
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2025-04-25 10:03:18 -07:00
Brad Fitzpatrick
3bc10ea585 ipn/ipnext: remove some interface indirection to add hooks
Now that 25c4dc5fd70 removed unregistering hooks and made them into
slices, just expose the slices and remove the setter funcs.

This removes boilerplate ceremony around adding new hooks.

This does export the hooks and make them mutable at runtime in theory,
but that'd be a data race. If we really wanted to lock it down in the
future we could make the feature.Hooks slice type be an opaque struct
with an All() iterator and a "frozen" bool and we could freeze all the
hooks after init. But that doesn't seem worth it.

This means that hook registration is also now all in one place, rather
than being mixed into ProfilesService vs ipnext.Host vs FooService vs
BarService. I view that as a feature. When we have a ton of hooks and
the list is long, then we can rearrange the fields in the Hooks struct
as needed, or make sub-structs, or big comments.

Updates #12614

Change-Id: I05ce5baa45a61e79c04591c2043c05f3288d8587
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2025-04-25 09:03:39 -07:00
Brad Fitzpatrick
3d8533b5d0 ipn/{ipnext,ipnlocal}: add a SafeBackend interface
Updates #12614

Change-Id: I197e673666e86ea74c19e3935ed71aec269b6c94
Co-authored-by: Nick Khyl <nickk@tailscale.com>
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2025-04-24 14:48:58 -07:00
Brad Fitzpatrick
25c4dc5fd7 ipn/ipnext: remove support for unregistering extension
Updates #12614

Change-Id: I893e3ea74831deaa6f88e31bba2d95dc017e0470
Co-authored-by: Nick Khyl <nickk@tailscale.com>
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2025-04-24 13:38:00 -07:00
Andrew Lytvynov
cb7bf929aa
go.mod: bump gorilla/csrf@v1.7.3 (#15775)
This is the same version as before, but the old one confuses
govulncheck.

Updates #cleanup

Signed-off-by: Andrew Lytvynov <awly@tailscale.com>
2025-04-23 13:59:03 -07:00
Joe Tsai
1f029180c7
types/jsonx: add package for json/v2 helpers (#15756)
The typical way to implement union types in Go
is to use an interface where the set of types is limited.
However, there historically has been poor support
in v1 "encoding/json" with interface types where
you can marshal such values, but fail to unmarshal them
since type information about the concrete type is lost.

The MakeInterfaceCoders function constructs custom
marshal/unmarshal functions such that the type name
is encoded in the JSON representation.
The set of valid concrete types for an interface
must be statically specified for this to function.

Updates tailscale/corp#22024

Signed-off-by: Joe Tsai <joetsai@digital-static.net>
2025-04-23 11:08:45 -07:00
Nick Khyl
bd33eb7bd7 ipn/ipnlocal: use tsd.NewSystem instead of &tsd.System in a few more tests
These were likely added after everything else was updated to use tsd.NewSystem,
in a feature branch, and before it was merged back into main.

Updates #15160

Signed-off-by: Nick Khyl <nickk@tailscale.com>
2025-04-23 10:24:00 -05:00
Nick Khyl
c41a2d5c83 net/portmapper: fix nil pointer dereference in Client.createMapping
The EventBus in net/portmapper.Config is still optional and Client.updates can be nil.

Updates #15772

Signed-off-by: Nick Khyl <nickk@tailscale.com>
2025-04-23 09:41:44 -05:00
Jordan Whited
c28fda864a
feature/relayserver: use PeerAPIHandler.Logf() (#15765)
This was recently added, use it to be consistent.

Updates tailscale/corp#27502

Signed-off-by: Jordan Whited <jordan@tailscale.com>
2025-04-22 10:53:58 -07:00
Olivier Mengué
a3fc5150e3 client/tailscale: add godoc links in Deprecated comments
Signed-off-by: Olivier Mengué <dolmen@cpan.org>
2025-04-22 10:24:28 -07:00
Nick Khyl
7090f7fffc ipn/ipnlocal: use MagicDNSName of the current profile instead of generating a full ipnstate.Status
Both are populated from the current netmap's MagicDNSSuffix.
But building a full ipnstate.Status (with peers!) is expensive and unnecessary.

Updates #cleanup

Signed-off-by: Nick Khyl <nickk@tailscale.com>
2025-04-18 17:09:00 -05:00
Patrick O'Doherty
e649227ef2
cmd/tsidp: fix interface{} linter warnings (#15729)
Replace all instances of interface{} with any to resolve the
golangci-lint errors that appeared in the previous tsidp PR.

Updates #cleanup

Signed-off-by: Patrick O'Doherty <patrick@tailscale.com>
2025-04-17 18:05:07 -07:00
Cedric Kienzler
b34a2bdb22
cmd/tsidp: add groups claim to tsidp (#15127)
* cmd/tsidp: add groups claim to tsidp

This feature adds support for a `groups` claim in tsidp using the grants
syntax:

```json
{
  "grants": [
    {
      "src": ["group:admins"],
      "dst": ["*"],
      "ip":  ["*"],
      "app": {
        "tailscale.com/cap/tsidp": [
          {
            "groups": ["admin"]
          }
        ]
      }
    },
    {
      "src": ["group:reader"],
      "dst": ["*"],
      "ip":  ["*"],
      "app": {
        "tailscale.com/cap/tsidp": [
          {
            "groups": ["reader"]
          }
        ]
      }
    }
  ]
}
```

For #10263

Signed-off-by: Cedric Kienzler <github@cedric-kienzler.de>

* cmd/tsidp: refactor cap/tsidp to allow extraClaims

This commit refactors the `capRule` struct to allow specifying arbitrary
extra claims:

```json
{
  "src": ["group:reader"],
  "dst": ["*"],
  "ip":  ["*"],
  "app": {
    "tailscale.com/cap/tsidp": [
      {
        "extraClaims": {
          "groups": ["reader"],
          "entitlements": ["read-stuff"],
        },
      }
    ]
  }
}
```

Overwriting pre-existing claims cannot be modified/overwritten.

Also adding more unit-testing

Signed-off-by: Cedric Kienzler <github@cedric-kienzler.de>

* Update cmd/tsidp/tsidp.go

Signed-off-by: cedi <cedi@users.noreply.github.com>

* Update cmd/tsidp/tsidp_test.go

Co-authored-by: Patrick O'Doherty <hello@patrickod.com>
Signed-off-by: Cedric Kienzler <cedi@users.noreply.github.com>

* Update cmd/tsidp/tsidp_test.go

Co-authored-by: Patrick O'Doherty <hello@patrickod.com>
Signed-off-by: Cedric Kienzler <cedi@users.noreply.github.com>

* Fix logical error in test case

Signed-off-by: Cedric Kienzler <github@cedric-kienzler.de>

* fix error printing for failed to unmarshal capability in tsidp

Signed-off-by: Cedric Kienzler <github@cedric-kienzler.de>

* clarify doc string for withExtraClaims

Signed-off-by: Cedric Kienzler <github@cedric-kienzler.de>

---------

Signed-off-by: Cedric Kienzler <github@cedric-kienzler.de>
Signed-off-by: cedi <cedi@users.noreply.github.com>
Signed-off-by: Cedric Kienzler <cedi@users.noreply.github.com>
Co-authored-by: Patrick O'Doherty <hello@patrickod.com>
2025-04-17 17:31:40 -07:00
Jordan Whited
3a8a174308
net/udprelay: change ServerEndpoint time.Duration fields to tstime.GoDuration (#15725)
tstime.GoDuration JSON serializes with time.Duration.String(), which is
more human-friendly than nanoseconds.

ServerEndpoint is currently experimental, therefore breaking changes
are tolerable.

Updates tailscale/corp#27502

Signed-off-by: Jordan Whited <jordan@tailscale.com>
2025-04-17 16:21:32 -07:00
Joe Tsai
aff8f1b358
tstime: add GoDuration which JSON serializes with time.Duration.String (#15726)
The encoding/json/v2 effort may end up changing
the default represention of time.Duration in JSON.
See https://go.dev/issue/71631

The GoDuration type allows us to explicitly use
the time.Duration.String representation regardless of
whether we serialize with v1 or v2 of encoding/json.

Updates tailscale/corp#27502

Signed-off-by: Joe Tsai <joetsai@digital-static.net>
2025-04-17 15:51:41 -07:00
Brad Fitzpatrick
898cf06898 ipn/ipnlocal: remove another copy of slicesx.MapValues
We added this helper in 1e2e319e7d26. Remove this copy.

Updates #cleanup

Change-Id: I5b0681acc23692beed35951c9902ac9ceca0a8b9
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2025-04-17 11:10:36 -07:00
Jordan Whited
92027d7ae0
feature/relayserver: wire up profile/prefs changes (#15714)
The relay server is still permanently disabled until node attribute
changes are wired up in a future commit.

Updates tailscale/corp#27502

Signed-off-by: Jordan Whited <jordan@tailscale.com>
2025-04-17 09:24:11 -07:00
Tom Meadows
9666c2e700
cmd/k8s-operator: default ingress paths to '/' if not specified by user (#15706)
in resource

Fixes #14908

Signed-off-by: chaosinthecrd <tom@tmlabs.co.uk>
2025-04-17 16:14:34 +01:00
Percy Wegmann
26f31f73f4 cmd/dist,release/dist: sign QNAP builds with a Google Cloud hosted key
QNAP now requires builds to be signed with an HSM.

This removes support for signing with a local keypair.

This adds support for signing with a Google Cloud hosted key.

The key should be an RSA key with protection level `HSM` and that uses PSS padding and a SHA256 digest.

The GCloud project, keyring and key name are passed in as command-line arguments.

The GCloud credentials and the PEM signing certificate are passed in as Base64-encoded command-line arguments.

Updates tailscale/corp#23528

Signed-off-by: Percy Wegmann <percy@tailscale.com>
2025-04-17 08:39:31 -05:00
Brad Fitzpatrick
0c78f081a4 feature/taildrop: start moving Taildrop out of LocalBackend
This adds a feature/taildrop package, a ts_omit_taildrop build tag,
and starts moving code to feature/taildrop. In some cases, code
remains where it was but is now behind a build tag. Future changes
will move code to an extension and out of LocalBackend, etc.

Updates #12614

Change-Id: Idf96c61144d1a5f707039ceb2ff59c99f5c1642f
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2025-04-16 15:57:59 -07:00
M. J. Fromberger
dda2c0d2c2 wgengine/magicsock: subscribe to portmapper updates
When an event bus is plumbed in, use it to subscribe and react to port mapping
updates instead of using the client's callback mechanism. For now, the callback
remains available as a fallback when an event bus is not provided.

Updates #15160

Change-Id: I026adca44bf6187692ee87ae8ec02641c12f7774
Signed-off-by: M. J. Fromberger <fromberger@tailscale.com>
2025-04-16 10:10:45 -07:00
David Anderson
5399fa159a net/netmon: publish events to event bus
Updates #15160

Signed-off-by: David Anderson <dave@tailscale.com>
2025-04-16 10:10:45 -07:00
David Anderson
6d6f69e735 derp/derphttp: remove ban on websockets dependency
The event bus's debug page uses websockets.

Updates #15160

Signed-off-by: David Anderson <dave@tailscale.com>
2025-04-16 10:10:45 -07:00
David Anderson
e8cacd2a32 cmd/tailscaled: clean up unnecessary logf indirection #cleanup
Signed-off-by: David Anderson <dave@tailscale.com>
2025-04-16 10:10:45 -07:00
M. J. Fromberger
2731171c5e net/portmapper: fire an event when a port mapping is updated (#15371)
When an event bus is configured publish an event each time a new port mapping
is updated. Publication is unconditional and occurs prior to calling any
callback that is registered. For now, the callback is still fired in a separate
goroutine as before -- later, those callbacks should become subscriptions to
the published event.

For now, the event type is defined as a new type here in the package. We will
want to move it to a more central package when there are subscribers. The event
wrapper is effectively a subset of the data exported by the internal mapping
interface, but on a concrete struct so the bus plumbing can inspect it.

Updates #15160

Change-Id: I951f212429ac791223af8d75b6eb39a0d2a0053a
Signed-off-by: M. J. Fromberger <fromberger@tailscale.com>
2025-04-16 10:10:45 -07:00
M. J. Fromberger
deb0b255ff all: update the tsd.System constructor name (#15372)
Replace NewSystemWithEventBus with plain NewSystem, and update all usage.
See https://github.com/tailscale/tailscale/pull/15355#discussion_r2003910766

Updates #15160

Change-Id: I64d337f09576b41d9ad78eba301a74b9a9d6ebf4
Signed-off-by: M. J. Fromberger <fromberger@tailscale.com>
2025-04-16 10:10:45 -07:00
M. J. Fromberger
baead61e44 {wgengine,util/portmapper}: add and plumb an event bus (#15359)
Updates #15160

Change-Id: I2510fb4a8905fb0abe8a8e0c5b81adb15d50a6f8
Signed-off-by: M. J. Fromberger <fromberger@tailscale.com>
2025-04-16 10:10:45 -07:00
M. J. Fromberger
418e19fb5e portmapper: update NewClient to use a Config argument
In preparation for adding more parameters (and later, moving some away), rework
the portmapper constructor to accept its arguments on a Config struct rather
than positionally.

This is a breaking change to the function signature, but one that is very easy
to update, and a search of GitHub reveals only six instances of usage outside
clones and forks of Tailscale itself, that are not direct copies of the code
fixed up here.

While we could stub in another constructor, I think it is safe to let those
folks do the update in-place, since their usage is already affected by other
changes we can't test for anyway.

Updates #15160

Change-Id: I9f8a5e12b38885074c98894b7376039261b43f43
Signed-off-by: M. J. Fromberger <fromberger@tailscale.com>
2025-04-16 10:10:45 -07:00
M. J. Fromberger
2ac6e1edfd wgengine: plumb an event bus into the userspace engine
Updates #15160

Change-Id: Ia695ccdddd09cd950de22abd000d4c531d6bf3c8
Signed-off-by: M. J. Fromberger <fromberger@tailscale.com>
2025-04-16 10:10:45 -07:00
M. J. Fromberger
bcd6a0d0ac tsnet: shut down the event bus on Close
Updates #15160

Change-Id: I29c8194b4b41e95848e5f160e9970db352588449
Signed-off-by: M. J. Fromberger <fromberger@tailscale.com>
2025-04-16 10:10:45 -07:00
M. J. Fromberger
ffb22ee353 all: construct new System values with an event bus pre-populated
Although, at the moment, we do not yet require an event bus to be present, as
we start to add more pieces we will want to ensure it is always available.  Add
a new constructor and replace existing uses of new(tsd.System) throughout.
Update generated files for import changes.

Updates #15160

Change-Id: Ie5460985571ade87b8eac8b416948c7f49f0f64b
Signed-off-by: M. J. Fromberger <fromberger@tailscale.com>
2025-04-16 10:10:45 -07:00
David Anderson
6b8bbb4c37 tsd: wire up the event bus to tailscaled
Updates #15160

Signed-off-by: David Anderson <dave@tailscale.com>
2025-04-16 10:10:45 -07:00
David Anderson
a3cc7123ff tsweb: don't hook up pprof handlers in javascript builds
Updates #15160

Signed-off-by: David Anderson <dave@tailscale.com>
2025-04-16 10:10:45 -07:00
Jordan Whited
37f5fd2ec1
feature/{condregister,relayserver}: implement the skeleton for the relayserver feature (#15699)
This feature is "registered" as an ipnlocal.Extension, and
conditionally linked depending on GOOS and ts_omit_relayserver build
tag.

The feature is not linked on iOS in attempt to limit the impact to
binary size and resulting effect of pushing up against NetworkExtension
limits. Eventually we will want to support the relay server on iOS,
specifically on the Apple TV. Apple TVs are well-fitted to act as
underlay relay servers as they are effectively always-on servers.

This skeleton begins to tie a PeerAPI endpoint to a net/udprelay.Server.
The PeerAPI endpoint is currently no-op as
extension.shouldRunRelayServer() always returns false. Follow-up commits
will implement extension.shouldRunRelayServer().

Updates tailscale/corp#27502

Signed-off-by: Jordan Whited <jordan@tailscale.com>
2025-04-16 09:50:48 -07:00