tailscale/tstest
Brad Fitzpatrick b6e17df646 cmd/tailscaled, util/syspolicy: add JSON syspolicy file support
Tailscaled had no way to seed device-scope syspolicy settings short of
environment variables or a custom store wired up out of tree. Add a
--syspolicy-file flag whose default points at a well-known JSON file
that, when present, is parsed as a map[string]any and registered as a
device-scope policy source. The default path is
/etc/tailscale/syspolicy.json on every non-Windows platform (Linux, the
BSDs, illumos/Solaris, and tailscaled-without-the-GUI on macOS) and
%ProgramData%\Tailscale\syspolicy.json on Windows. The flag lets users
running tailscaled by hand (development, custom installs) point it at
an alternate file, and "" disables the load entirely.

JSON values map to setting types as expected: strings to
StringValue/PreferenceOptionValue/VisibilityValue/DurationValue (e.g.
"24h" parsed by time.ParseDuration), booleans to BooleanValue, numbers
to IntegerValue, and string arrays to StringListValue. The file is
validated against the registered setting definitions at load time so
unknown keys and value/type mismatches fail startup loudly rather than
producing surprising defaults at first read.

When HuJSON support is linked into the build (default; opt out with
ts_omit_hujsonconf), the file may use HuJSON (comments, trailing
commas). With ts_omit_hujsonconf it must be pure standard JSON. This
mirrors the pattern used by ipn/conffile.

On Windows the JSON file and the existing HKLM registry store both
register at DeviceScope. rsop merges later-registered same-scope
sources over earlier ones, so per-key values in the file override the
registry while keys absent from the file fall back to the registry.

The loader is registered via a feature.Hook from a file gated by
!ts_omit_syspolicy, and called from main after flag parsing. tsnet
still does not depend on the root syspolicy package, so embedders
don't pick this up implicitly.

Fixes #20305

Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
Change-Id: Ie6326461c14efb226979ac162998a9c6373ce493
2026-06-30 13:10:16 -07:00
..
archtest all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
chonktest all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
deptest all: use Go 1.26 things, run most gofix modernizers 2026-03-06 13:32:03 -08:00
integration cmd/tailscaled, util/syspolicy: add JSON syspolicy file support 2026-06-30 13:10:16 -07:00
iosdeps wgengine/netstack, net/ping: stop using pro-bing and use our net/ping instead 2026-05-04 14:05:24 -07:00
jsdeps all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
largetailnet ipn/ipnlocal: consolidate test-only LocalBackend methods behind ForTest 2026-06-27 16:11:42 -07:00
mts all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
natlab tstest/natlab/vmtest, client/web: add web client integration tests 2026-06-30 06:55:12 -07:00
nettest go.toolchain.branch: switch to Go 1.26 2026-03-04 21:57:05 -08:00
tailmac tstest/natlab/vmtest: add macOS VM snapshot caching for fast test starts 2026-04-29 08:17:13 -07:00
tkatest all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
tlstest all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
tools all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
typewalk all: use Go 1.26 things, run most gofix modernizers 2026-03-06 13:32:03 -08:00
allocs.go all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
clock_test.go cmd/vet: add subtestnames analyzer; fix all existing violations 2026-04-05 15:52:51 -07:00
clock.go tstest/clock: explain what happens if you don't set a Start time 2026-04-28 00:15:46 +02:00
kernel_linux_test.go tstest: fix kernel version parsing for Debian-style version strings 2026-04-14 07:11:44 -07:00
kernel_linux.go tstest: fix kernel version parsing for Debian-style version strings 2026-04-14 07:11:44 -07:00
kernel_other.go all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
log_test.go all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
log.go all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
reflect.go types/ptr: deprecate ptr.To, use Go 1.26 new 2026-03-05 20:13:18 -08:00
resource_test.go cmd/vet: add subtestnames analyzer; fix all existing violations 2026-04-05 15:52:51 -07:00
resource.go all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
test-wishlist.md wf: allow limited broadcast to/from permitted interfaces when using an exit node on Windows 2026-01-23 18:30:38 -06:00
tstest_test.go all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
tstest.go cmd/testwrapper, tstest: move test sharding out of test code 2026-05-27 16:53:17 -07:00