diff --git a/cmd/tailscaled/tailscaled.go b/cmd/tailscaled/tailscaled.go index 1a9a367da..6cb821edb 100644 --- a/cmd/tailscaled/tailscaled.go +++ b/cmd/tailscaled/tailscaled.go @@ -35,6 +35,7 @@ "tailscale.com/control/controlclient" "tailscale.com/drive/driveimpl" "tailscale.com/envknob" + "tailscale.com/hostinfo" "tailscale.com/ipn" "tailscale.com/ipn/conffile" "tailscale.com/ipn/ipnlocal" @@ -154,6 +155,7 @@ func defaultPort() uint16 { func main() { envknob.PanicIfAnyEnvCheckedInInit() envknob.ApplyDiskConfig() + applyIntegrationTestEnvKnob() printVersion := false flag.IntVar(&args.verbose, "verbose", 0, "log verbosity level; 0 is default, 1 or higher are increasingly verbose") @@ -895,3 +897,24 @@ func dieOnPipeReadErrorOfFD(fd int) { f.Read(make([]byte, 1)) os.Exit(1) } + +// applyIntegrationTestEnvKnob applies the tailscaled.env=... environment +// variables specified on the Linux kernel command line, if the VM is being +// run in NATLab integration tests. +// +// They're specified as: tailscaled.env=FOO=bar tailscaled.env=BAR=baz +func applyIntegrationTestEnvKnob() { + if runtime.GOOS != "linux" || !hostinfo.IsNATLabGuestVM() { + return + } + cmdLine, _ := os.ReadFile("/proc/cmdline") + for _, s := range strings.Fields(string(cmdLine)) { + suf, ok := strings.CutPrefix(s, "tailscaled.env=") + if !ok { + continue + } + if k, v, ok := strings.Cut(suf, "="); ok { + envknob.Setenv(k, v) + } + } +} diff --git a/tstest/integration/tailscaled_deps_test_darwin.go b/tstest/integration/tailscaled_deps_test_darwin.go index 6d366d46e..6676ee22c 100644 --- a/tstest/integration/tailscaled_deps_test_darwin.go +++ b/tstest/integration/tailscaled_deps_test_darwin.go @@ -18,6 +18,7 @@ _ "tailscale.com/drive/driveimpl" _ "tailscale.com/envknob" _ "tailscale.com/health" + _ "tailscale.com/hostinfo" _ "tailscale.com/ipn" _ "tailscale.com/ipn/conffile" _ "tailscale.com/ipn/ipnlocal" diff --git a/tstest/integration/tailscaled_deps_test_freebsd.go b/tstest/integration/tailscaled_deps_test_freebsd.go index 6d366d46e..6676ee22c 100644 --- a/tstest/integration/tailscaled_deps_test_freebsd.go +++ b/tstest/integration/tailscaled_deps_test_freebsd.go @@ -18,6 +18,7 @@ _ "tailscale.com/drive/driveimpl" _ "tailscale.com/envknob" _ "tailscale.com/health" + _ "tailscale.com/hostinfo" _ "tailscale.com/ipn" _ "tailscale.com/ipn/conffile" _ "tailscale.com/ipn/ipnlocal" diff --git a/tstest/integration/tailscaled_deps_test_linux.go b/tstest/integration/tailscaled_deps_test_linux.go index 6d366d46e..6676ee22c 100644 --- a/tstest/integration/tailscaled_deps_test_linux.go +++ b/tstest/integration/tailscaled_deps_test_linux.go @@ -18,6 +18,7 @@ _ "tailscale.com/drive/driveimpl" _ "tailscale.com/envknob" _ "tailscale.com/health" + _ "tailscale.com/hostinfo" _ "tailscale.com/ipn" _ "tailscale.com/ipn/conffile" _ "tailscale.com/ipn/ipnlocal" diff --git a/tstest/integration/tailscaled_deps_test_openbsd.go b/tstest/integration/tailscaled_deps_test_openbsd.go index 6d366d46e..6676ee22c 100644 --- a/tstest/integration/tailscaled_deps_test_openbsd.go +++ b/tstest/integration/tailscaled_deps_test_openbsd.go @@ -18,6 +18,7 @@ _ "tailscale.com/drive/driveimpl" _ "tailscale.com/envknob" _ "tailscale.com/health" + _ "tailscale.com/hostinfo" _ "tailscale.com/ipn" _ "tailscale.com/ipn/conffile" _ "tailscale.com/ipn/ipnlocal" diff --git a/tstest/integration/tailscaled_deps_test_windows.go b/tstest/integration/tailscaled_deps_test_windows.go index 015bf8284..bbf46d8c2 100644 --- a/tstest/integration/tailscaled_deps_test_windows.go +++ b/tstest/integration/tailscaled_deps_test_windows.go @@ -25,6 +25,7 @@ _ "tailscale.com/drive/driveimpl" _ "tailscale.com/envknob" _ "tailscale.com/health" + _ "tailscale.com/hostinfo" _ "tailscale.com/ipn" _ "tailscale.com/ipn/conffile" _ "tailscale.com/ipn/ipnlocal"