mirror of
https://github.com/tailscale/tailscale.git
synced 2025-12-25 20:23:43 +00:00
feature/drive: start factoring out Taildrive, add ts_omit_drive build tag
As of this commit (per the issue), the Taildrive code remains where it was, but in new files that are protected by the new ts_omit_drive build tag. Future commits will move it. Updates #17058 Change-Id: Idf0a51db59e41ae8da6ea2b11d238aefc48b219e Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
committed by
Brad Fitzpatrick
parent
82c5024f03
commit
a1dcf12b67
@@ -210,6 +210,7 @@ func noDupFlagify(c *ffcli.Command) {
|
||||
var fileCmd func() *ffcli.Command
|
||||
var sysPolicyCmd func() *ffcli.Command
|
||||
var maybeWebCmd func() *ffcli.Command
|
||||
var maybeDriveCmd func() *ffcli.Command
|
||||
|
||||
func newRootCmd() *ffcli.Command {
|
||||
rootfs := newFlagSet("tailscale")
|
||||
@@ -262,7 +263,7 @@ change in the future.
|
||||
updateCmd,
|
||||
whoisCmd,
|
||||
debugCmd(),
|
||||
driveCmd,
|
||||
nilOrCall(maybeDriveCmd),
|
||||
idTokenCmd,
|
||||
configureHostCmd(),
|
||||
systrayCmd,
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
// Copyright (c) Tailscale Inc & AUTHORS
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
//go:build !ts_omit_drive
|
||||
|
||||
package cli
|
||||
|
||||
import (
|
||||
@@ -20,43 +22,49 @@ const (
|
||||
driveListUsage = "tailscale drive list"
|
||||
)
|
||||
|
||||
var driveCmd = &ffcli.Command{
|
||||
Name: "drive",
|
||||
ShortHelp: "Share a directory with your tailnet",
|
||||
ShortUsage: strings.Join([]string{
|
||||
driveShareUsage,
|
||||
driveRenameUsage,
|
||||
driveUnshareUsage,
|
||||
driveListUsage,
|
||||
}, "\n"),
|
||||
LongHelp: buildShareLongHelp(),
|
||||
UsageFunc: usageFuncNoDefaultValues,
|
||||
Subcommands: []*ffcli.Command{
|
||||
{
|
||||
Name: "share",
|
||||
ShortUsage: driveShareUsage,
|
||||
Exec: runDriveShare,
|
||||
ShortHelp: "[ALPHA] Create or modify a share",
|
||||
func init() {
|
||||
maybeDriveCmd = driveCmd
|
||||
}
|
||||
|
||||
func driveCmd() *ffcli.Command {
|
||||
return &ffcli.Command{
|
||||
Name: "drive",
|
||||
ShortHelp: "Share a directory with your tailnet",
|
||||
ShortUsage: strings.Join([]string{
|
||||
driveShareUsage,
|
||||
driveRenameUsage,
|
||||
driveUnshareUsage,
|
||||
driveListUsage,
|
||||
}, "\n"),
|
||||
LongHelp: buildShareLongHelp(),
|
||||
UsageFunc: usageFuncNoDefaultValues,
|
||||
Subcommands: []*ffcli.Command{
|
||||
{
|
||||
Name: "share",
|
||||
ShortUsage: driveShareUsage,
|
||||
Exec: runDriveShare,
|
||||
ShortHelp: "[ALPHA] Create or modify a share",
|
||||
},
|
||||
{
|
||||
Name: "rename",
|
||||
ShortUsage: driveRenameUsage,
|
||||
ShortHelp: "[ALPHA] Rename a share",
|
||||
Exec: runDriveRename,
|
||||
},
|
||||
{
|
||||
Name: "unshare",
|
||||
ShortUsage: driveUnshareUsage,
|
||||
ShortHelp: "[ALPHA] Remove a share",
|
||||
Exec: runDriveUnshare,
|
||||
},
|
||||
{
|
||||
Name: "list",
|
||||
ShortUsage: driveListUsage,
|
||||
ShortHelp: "[ALPHA] List current shares",
|
||||
Exec: runDriveList,
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "rename",
|
||||
ShortUsage: driveRenameUsage,
|
||||
ShortHelp: "[ALPHA] Rename a share",
|
||||
Exec: runDriveRename,
|
||||
},
|
||||
{
|
||||
Name: "unshare",
|
||||
ShortUsage: driveUnshareUsage,
|
||||
ShortHelp: "[ALPHA] Remove a share",
|
||||
Exec: runDriveUnshare,
|
||||
},
|
||||
{
|
||||
Name: "list",
|
||||
ShortUsage: driveListUsage,
|
||||
ShortHelp: "[ALPHA] List current shares",
|
||||
Exec: runDriveList,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// runDriveShare is the entry point for the "tailscale drive share" command.
|
||||
|
||||
@@ -274,6 +274,7 @@ tailscale.com/cmd/tailscaled dependencies: (generated by github.com/tailscale/de
|
||||
tailscale.com/feature from tailscale.com/feature/wakeonlan+
|
||||
tailscale.com/feature/capture from tailscale.com/feature/condregister
|
||||
tailscale.com/feature/condregister from tailscale.com/cmd/tailscaled
|
||||
tailscale.com/feature/drive from tailscale.com/feature/condregister
|
||||
tailscale.com/feature/relayserver from tailscale.com/feature/condregister
|
||||
tailscale.com/feature/syspolicy from tailscale.com/feature/condregister+
|
||||
tailscale.com/feature/taildrop from tailscale.com/feature/condregister
|
||||
|
||||
@@ -61,3 +61,19 @@ func TestOmitReflectThings(t *testing.T) {
|
||||
},
|
||||
}.Check(t)
|
||||
}
|
||||
|
||||
func TestOmitDrive(t *testing.T) {
|
||||
deptest.DepChecker{
|
||||
GOOS: "linux",
|
||||
GOARCH: "amd64",
|
||||
Tags: "ts_omit_drive,ts_include_cli",
|
||||
OnDep: func(dep string) {
|
||||
if strings.Contains(dep, "driveimpl") {
|
||||
t.Errorf("unexpected dep with ts_omit_drive: %q", dep)
|
||||
}
|
||||
if strings.Contains(dep, "webdav") {
|
||||
t.Errorf("unexpected dep with ts_omit_drive: %q", dep)
|
||||
}
|
||||
},
|
||||
}.Check(t)
|
||||
}
|
||||
|
||||
@@ -33,8 +33,8 @@ import (
|
||||
"tailscale.com/client/local"
|
||||
"tailscale.com/cmd/tailscaled/childproc"
|
||||
"tailscale.com/control/controlclient"
|
||||
"tailscale.com/drive/driveimpl"
|
||||
"tailscale.com/envknob"
|
||||
"tailscale.com/feature"
|
||||
_ "tailscale.com/feature/condregister"
|
||||
"tailscale.com/hostinfo"
|
||||
"tailscale.com/ipn"
|
||||
@@ -153,7 +153,6 @@ var subCommands = map[string]*func([]string) error{
|
||||
"uninstall-system-daemon": &uninstallSystemDaemon,
|
||||
"debug": &debugModeFunc,
|
||||
"be-child": &beChildFunc,
|
||||
"serve-taildrive": &serveDriveFunc,
|
||||
}
|
||||
|
||||
var beCLI func() // non-nil if CLI is linked in with the "ts_include_cli" build tag
|
||||
@@ -480,7 +479,9 @@ func run() (err error) {
|
||||
debugMux = newDebugMux()
|
||||
}
|
||||
|
||||
sys.Set(driveimpl.NewFileSystemForRemote(logf))
|
||||
if f, ok := hookSetSysDrive.GetOk(); ok {
|
||||
f(sys, logf)
|
||||
}
|
||||
|
||||
if app := envknob.App(); app != "" {
|
||||
hostinfo.SetApp(app)
|
||||
@@ -489,6 +490,11 @@ func run() (err error) {
|
||||
return startIPNServer(context.Background(), logf, pol.PublicID, sys)
|
||||
}
|
||||
|
||||
var (
|
||||
hookSetSysDrive feature.Hook[func(*tsd.System, logger.Logf)]
|
||||
hookSetWgEnginConfigDrive feature.Hook[func(*wgengine.Config, logger.Logf)]
|
||||
)
|
||||
|
||||
var sigPipe os.Signal // set by sigpipe.go
|
||||
|
||||
func startIPNServer(ctx context.Context, logf logger.Logf, logID logid.PublicID, sys *tsd.System) error {
|
||||
@@ -749,7 +755,9 @@ func tryEngine(logf logger.Logf, sys *tsd.System, name string) (onlyNetstack boo
|
||||
SetSubsystem: sys.Set,
|
||||
ControlKnobs: sys.ControlKnobs(),
|
||||
EventBus: sys.Bus.Get(),
|
||||
DriveForLocal: driveimpl.NewFileSystemForLocal(logf),
|
||||
}
|
||||
if f, ok := hookSetWgEnginConfigDrive.GetOk(); ok {
|
||||
f(&conf, logf)
|
||||
}
|
||||
|
||||
sys.HealthTracker().SetMetricsRegistry(sys.UserMetricsRegistry())
|
||||
@@ -943,35 +951,6 @@ func beChild(args []string) error {
|
||||
return f(args[1:])
|
||||
}
|
||||
|
||||
var serveDriveFunc = serveDrive
|
||||
|
||||
// serveDrive serves one or more Taildrives on localhost using the WebDAV
|
||||
// protocol. On UNIX and MacOS tailscaled environment, Taildrive spawns child
|
||||
// tailscaled processes in serve-taildrive mode in order to access the fliesystem
|
||||
// as specific (usually unprivileged) users.
|
||||
//
|
||||
// serveDrive prints the address on which it's listening to stdout so that the
|
||||
// parent process knows where to connect to.
|
||||
func serveDrive(args []string) error {
|
||||
if len(args) == 0 {
|
||||
return errors.New("missing shares")
|
||||
}
|
||||
if len(args)%2 != 0 {
|
||||
return errors.New("need <sharename> <path> pairs")
|
||||
}
|
||||
s, err := driveimpl.NewFileServer()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to start Taildrive file server: %v", err)
|
||||
}
|
||||
shares := make(map[string]string)
|
||||
for i := 0; i < len(args); i += 2 {
|
||||
shares[args[i]] = args[i+1]
|
||||
}
|
||||
s.SetShares(shares)
|
||||
fmt.Printf("%v\n", s.Addr())
|
||||
return s.Serve()
|
||||
}
|
||||
|
||||
// dieOnPipeReadErrorOfFD reads from the pipe named by fd and exit the process
|
||||
// when the pipe becomes readable. We use this in tests as a somewhat more
|
||||
// portable mechanism for the Linux PR_SET_PDEATHSIG, which we wish existed on
|
||||
|
||||
56
cmd/tailscaled/tailscaled_drive.go
Normal file
56
cmd/tailscaled/tailscaled_drive.go
Normal file
@@ -0,0 +1,56 @@
|
||||
// Copyright (c) Tailscale Inc & AUTHORS
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
//go:build !ts_omit_drive
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"tailscale.com/drive/driveimpl"
|
||||
"tailscale.com/tsd"
|
||||
"tailscale.com/types/logger"
|
||||
"tailscale.com/wgengine"
|
||||
)
|
||||
|
||||
func init() {
|
||||
subCommands["serve-taildrive"] = &serveDriveFunc
|
||||
|
||||
hookSetSysDrive.Set(func(sys *tsd.System, logf logger.Logf) {
|
||||
sys.Set(driveimpl.NewFileSystemForRemote(logf))
|
||||
})
|
||||
hookSetWgEnginConfigDrive.Set(func(conf *wgengine.Config, logf logger.Logf) {
|
||||
conf.DriveForLocal = driveimpl.NewFileSystemForLocal(logf)
|
||||
})
|
||||
}
|
||||
|
||||
var serveDriveFunc = serveDrive
|
||||
|
||||
// serveDrive serves one or more Taildrives on localhost using the WebDAV
|
||||
// protocol. On UNIX and MacOS tailscaled environment, Taildrive spawns child
|
||||
// tailscaled processes in serve-taildrive mode in order to access the fliesystem
|
||||
// as specific (usually unprivileged) users.
|
||||
//
|
||||
// serveDrive prints the address on which it's listening to stdout so that the
|
||||
// parent process knows where to connect to.
|
||||
func serveDrive(args []string) error {
|
||||
if len(args) == 0 {
|
||||
return errors.New("missing shares")
|
||||
}
|
||||
if len(args)%2 != 0 {
|
||||
return errors.New("need <sharename> <path> pairs")
|
||||
}
|
||||
s, err := driveimpl.NewFileServer()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to start Taildrive file server: %v", err)
|
||||
}
|
||||
shares := make(map[string]string)
|
||||
for i := 0; i < len(args); i += 2 {
|
||||
shares[args[i]] = args[i+1]
|
||||
}
|
||||
s.SetShares(shares)
|
||||
fmt.Printf("%v\n", s.Addr())
|
||||
return s.Serve()
|
||||
}
|
||||
Reference in New Issue
Block a user