logpolicy,tsnet: remove syspolicy dependency

tsnet depends on logpolicy, which in turn depended on util/syspolicy
because of a single LogTarget policy setting it uses.

In this commit, we replace that dependency with a feature.Hook,
which only tailscaled or its platform-specific alternatives should set.

Updates #20031

Signed-off-by: Nick Khyl <nickk@tailscale.com>
This commit is contained in:
Nick Khyl
2026-06-05 16:21:27 -05:00
committed by Nick Khyl
parent eda975a9e4
commit c0d0621417
8 changed files with 30 additions and 33 deletions
+10 -4
View File
@@ -54,13 +54,15 @@ import (
"tailscale.com/util/eventbus"
"tailscale.com/util/must"
"tailscale.com/util/racebuild"
"tailscale.com/util/syspolicy/pkey"
"tailscale.com/util/syspolicy/policyclient"
"tailscale.com/util/testenv"
"tailscale.com/version"
"tailscale.com/version/distro"
)
// GetLogTarget is an optional hook to register a function
// that returns the log target URL to be used by logpolicy.
var GetLogTarget feature.Hook[func() string]
var getLogTargetOnce struct {
sync.Once
v string // URL of logs server, or empty for default
@@ -68,8 +70,12 @@ var getLogTargetOnce struct {
func getLogTarget() string {
getLogTargetOnce.Do(func() {
envTarget, _ := os.LookupEnv("TS_LOG_TARGET")
getLogTargetOnce.v, _ = policyclient.Get().GetString(pkey.LogTarget, envTarget)
if f, ok := GetLogTarget.GetOk(); ok {
getLogTargetOnce.v = f()
}
if getLogTargetOnce.v == "" {
getLogTargetOnce.v, _ = os.LookupEnv("TS_LOG_TARGET")
}
})
return getLogTargetOnce.v
-8
View File
@@ -1,8 +0,0 @@
// Copyright (c) Tailscale Inc & contributors
// SPDX-License-Identifier: BSD-3-Clause
//go:build !ts_omit_syspolicy
package logpolicy
import _ "tailscale.com/feature/syspolicy"