From b68d008fee0622e1be57d77f36cf4ef3b693995f Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Wed, 23 Nov 2022 20:16:31 -0800 Subject: [PATCH] envknob: add CanTaildrop (TS_DISABLE_TAILDROP) to disable taildrop on device This matches CanSSHD (TS_DISABLE_SSH_SERVER) for administratively disabling the code on a node, regardless of local or server configs. This can be configured in /etc/default/tailscaled on Linux, %ProgramData%\Tailscale\tailscaled-env.txt on Windows, or /etc/tailscale/tailscaled-env.txt on Synology. (see getPlatformEnvFile) Also delete some dead code and tidy up some docs. Change-Id: I79a87c03e33209619466ea8aeb0f6651afcb8789 Signed-off-by: Brad Fitzpatrick --- envknob/envknob.go | 13 +++++++++---- ipn/ipnlocal/peerapi.go | 8 ++++---- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/envknob/envknob.go b/envknob/envknob.go index 18665f7f5..564d29d1c 100644 --- a/envknob/envknob.go +++ b/envknob/envknob.go @@ -264,13 +264,18 @@ func LookupInt(envVar string) (v int, ok bool) { // of Work-In-Progress code. func UseWIPCode() bool { return Bool("TAILSCALE_USE_WIP_CODE") } -// CanSSHD is whether the Tailscale SSH server is allowed to run. +// CanSSHD reports whether the Tailscale SSH server is allowed to run. // -// If disabled, the SSH server won't start (won't intercept port 22) -// if already enabled and any attempt to re-enable it will result in -// an error. +// If disabled (when this reports false), the SSH server won't start (won't +// intercept port 22) if previously configured to do so and any attempt to +// re-enable it will result in an error. func CanSSHD() bool { return !Bool("TS_DISABLE_SSH_SERVER") } +// CanTaildrop reports whether the Taildrop feature is allowed to function. +// +// If disabled, Taildrop won't receive files regardless of user & server config. +func CanTaildrop() bool { return !Bool("TS_DISABLE_TAILDROP") } + // SSHPolicyFile returns the path, if any, to the SSHPolicy JSON file for development. func SSHPolicyFile() string { return String("TS_DEBUG_SSH_POLICY_FILE") } diff --git a/ipn/ipnlocal/peerapi.go b/ipn/ipnlocal/peerapi.go index c81848100..579c697ce 100644 --- a/ipn/ipnlocal/peerapi.go +++ b/ipn/ipnlocal/peerapi.go @@ -94,10 +94,6 @@ const ( deletedSuffix = ".deleted" ) -func (s *peerAPIServer) canReceiveFiles() bool { - return s != nil && s.rootDir != "" -} - func validFilenameRune(r rune) bool { switch r { case '/': @@ -861,6 +857,10 @@ func (h *peerAPIHandler) peerHasCap(wantCap string) bool { } func (h *peerAPIHandler) handlePeerPut(w http.ResponseWriter, r *http.Request) { + if !envknob.CanTaildrop() { + http.Error(w, "Taildrop disabled on device", http.StatusForbidden) + return + } if !h.canPutFile() { http.Error(w, "Taildrop access denied", http.StatusForbidden) return