feature/taildrop, ipn/ipnlocal: remove leftover dup calls to osshare

I'd moved the osshare calls to feature/taildrop hooks, but forgot to
remove them from ipnlocal, or lost them during a rebase.

But then I noticed cmd/tailscaled also had some, so turn those into a
hook.

Updates #12614

Change-Id: I024fb1d27fbcc49c013158882ee5982c2737037d
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick 2025-05-08 09:29:50 -07:00 committed by Brad Fitzpatrick
parent e2814871a7
commit 165b99278b
9 changed files with 40 additions and 32 deletions

View File

@ -936,7 +936,6 @@ tailscale.com/cmd/k8s-operator dependencies: (generated by github.com/tailscale/
tailscale.com/util/nocasemaps from tailscale.com/types/ipproto tailscale.com/util/nocasemaps from tailscale.com/types/ipproto
💣 tailscale.com/util/osdiag from tailscale.com/ipn/localapi 💣 tailscale.com/util/osdiag from tailscale.com/ipn/localapi
W 💣 tailscale.com/util/osdiag/internal/wsc from tailscale.com/util/osdiag W 💣 tailscale.com/util/osdiag/internal/wsc from tailscale.com/util/osdiag
tailscale.com/util/osshare from tailscale.com/ipn/ipnlocal
tailscale.com/util/osuser from tailscale.com/ipn/ipnlocal tailscale.com/util/osuser from tailscale.com/ipn/ipnlocal
tailscale.com/util/race from tailscale.com/net/dns/resolver tailscale.com/util/race from tailscale.com/net/dns/resolver
tailscale.com/util/racebuild from tailscale.com/logpolicy tailscale.com/util/racebuild from tailscale.com/logpolicy

View File

@ -253,6 +253,7 @@ tailscale.com/cmd/tailscaled dependencies: (generated by github.com/tailscale/de
tailscale.com/clientupdate from tailscale.com/client/web+ tailscale.com/clientupdate from tailscale.com/client/web+
LW tailscale.com/clientupdate/distsign from tailscale.com/clientupdate LW tailscale.com/clientupdate/distsign from tailscale.com/clientupdate
tailscale.com/cmd/tailscaled/childproc from tailscale.com/cmd/tailscaled+ tailscale.com/cmd/tailscaled/childproc from tailscale.com/cmd/tailscaled+
tailscale.com/cmd/tailscaled/tailscaledhooks from tailscale.com/cmd/tailscaled+
tailscale.com/control/controlbase from tailscale.com/control/controlhttp+ tailscale.com/control/controlbase from tailscale.com/control/controlhttp+
tailscale.com/control/controlclient from tailscale.com/cmd/tailscaled+ tailscale.com/control/controlclient from tailscale.com/cmd/tailscaled+
tailscale.com/control/controlhttp from tailscale.com/control/controlclient tailscale.com/control/controlhttp from tailscale.com/control/controlclient

View File

@ -15,9 +15,9 @@ import (
"golang.org/x/sys/windows" "golang.org/x/sys/windows"
"golang.org/x/sys/windows/svc" "golang.org/x/sys/windows/svc"
"golang.org/x/sys/windows/svc/mgr" "golang.org/x/sys/windows/svc/mgr"
"tailscale.com/cmd/tailscaled/tailscaledhooks"
"tailscale.com/logtail/backoff" "tailscale.com/logtail/backoff"
"tailscale.com/types/logger" "tailscale.com/types/logger"
"tailscale.com/util/osshare"
) )
func init() { func init() {
@ -81,8 +81,9 @@ func installSystemDaemonWindows(args []string) (err error) {
} }
func uninstallSystemDaemonWindows(args []string) (ret error) { func uninstallSystemDaemonWindows(args []string) (ret error) {
// Remove file sharing from Windows shell (noop in non-windows) for _, f := range tailscaledhooks.UninstallSystemDaemonWindows {
osshare.SetFileSharingEnabled(false, logger.Discard) f()
}
m, err := mgr.Connect() m, err := mgr.Connect()
if err != nil { if err != nil {

View File

@ -0,0 +1,12 @@
// Copyright (c) Tailscale Inc & AUTHORS
// SPDX-License-Identifier: BSD-3-Clause
// Package tailscaledhooks provides hooks for optional features
// to add to during init that tailscaled calls at runtime.
package tailscaledhooks
import "tailscale.com/feature"
// UninstallSystemDaemonWindows is called when the Windows
// system daemon is uninstalled.
var UninstallSystemDaemonWindows feature.Hooks[func()]

View File

@ -12,12 +12,14 @@ import (
"maps" "maps"
"os" "os"
"path/filepath" "path/filepath"
"runtime"
"slices" "slices"
"strings" "strings"
"sync" "sync"
"sync/atomic" "sync/atomic"
"tailscale.com/client/tailscale/apitype" "tailscale.com/client/tailscale/apitype"
"tailscale.com/cmd/tailscaled/tailscaledhooks"
"tailscale.com/ipn" "tailscale.com/ipn"
"tailscale.com/ipn/ipnext" "tailscale.com/ipn/ipnext"
"tailscale.com/ipn/ipnstate" "tailscale.com/ipn/ipnstate"
@ -31,6 +33,13 @@ import (
func init() { func init() {
ipnext.RegisterExtension("taildrop", newExtension) ipnext.RegisterExtension("taildrop", newExtension)
if runtime.GOOS == "windows" {
tailscaledhooks.UninstallSystemDaemonWindows.Add(func() {
// Remove file sharing from Windows shell.
osshare.SetFileSharingEnabled(false, logger.Discard)
})
}
} }
func newExtension(logf logger.Logf, b ipnext.SafeBackend) (ipnext.Extension, error) { func newExtension(logf logger.Logf, b ipnext.SafeBackend) (ipnext.Extension, error) {

View File

@ -102,7 +102,6 @@ import (
"tailscale.com/util/httpm" "tailscale.com/util/httpm"
"tailscale.com/util/mak" "tailscale.com/util/mak"
"tailscale.com/util/multierr" "tailscale.com/util/multierr"
"tailscale.com/util/osshare"
"tailscale.com/util/osuser" "tailscale.com/util/osuser"
"tailscale.com/util/rands" "tailscale.com/util/rands"
"tailscale.com/util/set" "tailscale.com/util/set"
@ -274,7 +273,6 @@ type LocalBackend struct {
machinePrivKey key.MachinePrivate machinePrivKey key.MachinePrivate
tka *tkaState // TODO(nickkhyl): move to nodeContext tka *tkaState // TODO(nickkhyl): move to nodeContext
state ipn.State // TODO(nickkhyl): move to nodeContext state ipn.State // TODO(nickkhyl): move to nodeContext
capFileSharing bool // whether netMap contains the file sharing capability
capTailnetLock bool // whether netMap contains the tailnet lock capability capTailnetLock bool // whether netMap contains the tailnet lock capability
// hostinfo is mutated in-place while mu is held. // hostinfo is mutated in-place while mu is held.
hostinfo *tailcfg.Hostinfo // TODO(nickkhyl): move to nodeContext hostinfo *tailcfg.Hostinfo // TODO(nickkhyl): move to nodeContext
@ -460,7 +458,6 @@ func NewLocalBackend(logf logger.Logf, logID logid.PublicID, sys *tsd.System, lo
} }
envknob.LogCurrent(logf) envknob.LogCurrent(logf)
osshare.SetFileSharingEnabled(false, logf)
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
clock := tstime.StdClock{} clock := tstime.StdClock{}
@ -6140,13 +6137,6 @@ func (b *LocalBackend) setNetMapLocked(nm *netmap.NetworkMap) {
b.health.SetControlHealth(nil) b.health.SetControlHealth(nil)
} }
// Determine if file sharing is enabled
fs := nm.HasCap(tailcfg.CapabilityFileSharing)
if fs != b.capFileSharing {
osshare.SetFileSharingEnabled(fs, b.logf)
}
b.capFileSharing = fs
if nm.HasCap(tailcfg.NodeAttrLinuxMustUseIPTables) { if nm.HasCap(tailcfg.NodeAttrLinuxMustUseIPTables) {
b.capForcedNetfilter = "iptables" b.capForcedNetfilter = "iptables"
} else if nm.HasCap(tailcfg.NodeAttrLinuxMustUseNfTables) { } else if nm.HasCap(tailcfg.NodeAttrLinuxMustUseNfTables) {

View File

@ -69,7 +69,6 @@ func TestHandlePeerAPI(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
isSelf bool // the peer sending the request is owned by us isSelf bool // the peer sending the request is owned by us
capSharing bool // self node has file sharing capability
debugCap bool // self node has debug capability debugCap bool // self node has debug capability
reqs []*http.Request reqs []*http.Request
checks []check checks []check
@ -77,7 +76,6 @@ func TestHandlePeerAPI(t *testing.T) {
{ {
name: "not_peer_api", name: "not_peer_api",
isSelf: true, isSelf: true,
capSharing: true,
reqs: []*http.Request{httptest.NewRequest("GET", "/", nil)}, reqs: []*http.Request{httptest.NewRequest("GET", "/", nil)},
checks: checks( checks: checks(
httpStatus(200), httpStatus(200),
@ -88,7 +86,6 @@ func TestHandlePeerAPI(t *testing.T) {
{ {
name: "not_peer_api_not_owner", name: "not_peer_api_not_owner",
isSelf: false, isSelf: false,
capSharing: true,
reqs: []*http.Request{httptest.NewRequest("GET", "/", nil)}, reqs: []*http.Request{httptest.NewRequest("GET", "/", nil)},
checks: checks( checks: checks(
httpStatus(200), httpStatus(200),
@ -161,7 +158,6 @@ func TestHandlePeerAPI(t *testing.T) {
var e peerAPITestEnv var e peerAPITestEnv
lb := &LocalBackend{ lb := &LocalBackend{
logf: e.logBuf.Logf, logf: e.logBuf.Logf,
capFileSharing: tt.capSharing,
clock: &tstest.Clock{}, clock: &tstest.Clock{},
} }
lb.currentNode().SetNetMap(&netmap.NetworkMap{SelfNode: selfNode.View()}) lb.currentNode().SetNetMap(&netmap.NetworkMap{SelfNode: selfNode.View()})

View File

@ -365,7 +365,6 @@ tailscale.com/tsnet dependencies: (generated by github.com/tailscale/depaware)
tailscale.com/util/nocasemaps from tailscale.com/types/ipproto tailscale.com/util/nocasemaps from tailscale.com/types/ipproto
💣 tailscale.com/util/osdiag from tailscale.com/ipn/localapi 💣 tailscale.com/util/osdiag from tailscale.com/ipn/localapi
W 💣 tailscale.com/util/osdiag/internal/wsc from tailscale.com/util/osdiag W 💣 tailscale.com/util/osdiag/internal/wsc from tailscale.com/util/osdiag
tailscale.com/util/osshare from tailscale.com/ipn/ipnlocal
tailscale.com/util/osuser from tailscale.com/ipn/ipnlocal tailscale.com/util/osuser from tailscale.com/ipn/ipnlocal
tailscale.com/util/race from tailscale.com/net/dns/resolver tailscale.com/util/race from tailscale.com/net/dns/resolver
tailscale.com/util/racebuild from tailscale.com/logpolicy tailscale.com/util/racebuild from tailscale.com/logpolicy

View File

@ -20,6 +20,7 @@ import (
_ "golang.zx2c4.com/wireguard/windows/tunnel/winipcfg" _ "golang.zx2c4.com/wireguard/windows/tunnel/winipcfg"
_ "tailscale.com/client/local" _ "tailscale.com/client/local"
_ "tailscale.com/cmd/tailscaled/childproc" _ "tailscale.com/cmd/tailscaled/childproc"
_ "tailscale.com/cmd/tailscaled/tailscaledhooks"
_ "tailscale.com/control/controlclient" _ "tailscale.com/control/controlclient"
_ "tailscale.com/derp/derphttp" _ "tailscale.com/derp/derphttp"
_ "tailscale.com/drive/driveimpl" _ "tailscale.com/drive/driveimpl"