diff --git a/tstest/integration/integration.go b/tstest/integration/integration.go index 9a72783aa..d83af71b3 100644 --- a/tstest/integration/integration.go +++ b/tstest/integration/integration.go @@ -55,6 +55,7 @@ import ( "tailscale.com/types/nettype" "tailscale.com/util/cibuild" "tailscale.com/util/rands" + "tailscale.com/util/syspolicy/pkey" "tailscale.com/util/zstdframe" "tailscale.com/version" ) @@ -617,6 +618,7 @@ type TestNode struct { dir string // temp dir for sock & state configFile string // or empty for none + syspolicy map[pkey.Key]any sockFile string stateFile string upFlagGOOS string // if non-empty, sets TS_DEBUG_UP_FLAG_GOOS for cmd/tailscale CLI @@ -640,6 +642,19 @@ func (n *TestNode) writeBlankEnvFile() string { return path } +// writeSyspolicy writes the node's syspolicy settings to path as JSON. +func (n *TestNode) writeSyspolicy(path string) { + t := n.env.t + t.Helper() + b, err := json.Marshal(n.syspolicy) + if err != nil { + t.Fatalf("encoding syspolicy: %v", err) + } + if err := os.WriteFile(path, b, 0o644); err != nil { + t.Fatalf("writing %s: %v", path, err) + } +} + // TestNodeOpt represents an option that can be passed to NewTestNode. type TestNodeOpt interface { modifyTestNode(*TestNode) @@ -1017,6 +1032,13 @@ func (n *TestNode) StartDaemonAsIPNGOOS(ipnGOOS string) *Daemon { if n.configFile != "" { cmd.Args = append(cmd.Args, "--config="+n.configFile) } + var syspolicyFile string + if n.syspolicy != nil { + syspolicyFile = filepath.Join(n.dir, "syspolicy.json") + n.writeSyspolicy(syspolicyFile) + } + // An empty --syspolicy-file stops tailscaled from reading the machine-wide policy file. + cmd.Args = append(cmd.Args, "--syspolicy-file="+syspolicyFile) if n.encryptState { cmd.Args = append(cmd.Args, "--encrypt-state") } diff --git a/tstest/integration/integration_test.go b/tstest/integration/integration_test.go index bcb465145..70574ba18 100644 --- a/tstest/integration/integration_test.go +++ b/tstest/integration/integration_test.go @@ -54,6 +54,7 @@ import ( "tailscale.com/types/opt" "tailscale.com/util/must" "tailscale.com/util/set" + "tailscale.com/util/syspolicy/pkey" ) func TestMain(m *testing.M) { @@ -539,6 +540,25 @@ func TestOneNodeUpAuth(t *testing.T) { } } +func TestOneNodeUpAuthKeyPolicy(t *testing.T) { + tstest.Parallel(t) + const authKey = "opensesame" + env := NewTestEnv(t, ConfigureControl(func(control *testcontrol.Server) { + control.RequireAuthKey = authKey + })) + n1 := NewTestNode(t, env) + n1.syspolicy = map[pkey.Key]any{pkey.AuthKey: authKey} + + d1 := n1.StartDaemon() + n1.AwaitResponding() + n1.MustUp() + + t.Logf("Got IP: %v", n1.AwaitIP4()) + n1.AwaitRunning() + + d1.MustCleanShutdown(t) +} + // TestRetagStaleMapRequestRace reproduces tailscale/tailscale#20365: a node // tagged tag:tag1, where tag:tag1 owns tag:tag2, is retagged with "tailscale // up --advertise-tags=tag:tag2". This should always succeed, but sometimes @@ -847,7 +867,7 @@ func TestOneNodeUpInterruptedDeviceApproval(t *testing.T) { func TestConfigFileAuthKey(t *testing.T) { if runtime.GOOS == "windows" { - t.Skip("a config file can't set unattended mode, so Windows drops the node to NoState; see #20751") + t.Skip("the Windows service gets no --config, and outside it a CLI command swaps the config's profile for the user's own; see #20871") } t.Parallel() const authKey = "opensesame" diff --git a/tstest/integration/service_windows.go b/tstest/integration/service_windows.go index 09da2a5fc..9be55891b 100644 --- a/tstest/integration/service_windows.go +++ b/tstest/integration/service_windows.go @@ -52,6 +52,10 @@ func (n *TestNode) startWindowsServiceDaemon() *Daemon { } stageWintun(t, filepath.Dir(n.env.daemon)) n.writeServiceEnvFile() + if n.syspolicy != nil { + // The service takes no flags, so it reads the default --syspolicy-file path. + n.writeSyspolicy(filepath.Join(serviceStateDir(), "syspolicy.json")) + } if !installed { // install-system-daemon fails if the service is already there.