mirror of
https://github.com/tailscale/tailscale.git
synced 2026-11-24 02:31:18 -08:00
The ts_omit_<name> build tags omit a feature at build time; there has
been no way to do the same at runtime. Some users (either proactively
or in response to a security announcement) might like a way to disable
a feature that's linked-in in their binaries that they're not using.
Then a mitigation announcement can say "set this env var" without
asking users to rebuild or wait for a new release.
This adds env var TS_DISABLE_FEATURE, a comma-separated list of
feature names to disable, and the listed set is reported by the
debug-optional-features LocalAPI endpoint next to the registered set.
The legacy per-feature knobs such as TS_DISABLE_SSH_SERVER and
TS_DISABLE_TAILDROP keep working independently.
A disabled feature behaves as if it had not been linked: it is absent
from feature.IsRegistered, its hooks are unset, and its extensions and
handlers are not registered. Three pieces make that happen:
* feature.Register now returns bool, false when disabled, and
feature packages gate their registration init on it. It was added
to the feature packages that never called it (including taildrop
and ssh), which also completes the picture reported by
debug-optional-features. taildrop, routecheck, favorites, and
serviceclientprefs had registration split across several inits and
now register from one gated init.
* ipnext.RegisterExtension ignores a disabled feature's extension.
* feature.Hook.Set and feature.Hooks.Add walk the call stack and
silently skip when the calling package under feature/<name> is
disabled. This covers sub-packages such as
feature/captiveportal/netcheckhook, which cannot call Register
themselves without colliding with their parent, and future
packages whose authors forget the gate.
ssh/tailssh's registrations moved from its inits into tailssh.Register,
called from feature/ssh's gated init. The aws and kube state stores and
syspolicy's Windows store registration are gated too.
feature/register_disable_test.go runs this test binary as a child
process (it links condregister, as tailscaled does) with
TS_DISABLE_FEATURE set to every registered feature at once, and fails
if any of them register anyway, so a feature that ignores the variable
cannot land.
Updates #12614
Signed-off-by: Brad Fitzpatrick <[email protected]>
Change-Id: I720af6ccab844ae060a9dfd1539fee577fd483e3
97 lines
3.2 KiB
Go
97 lines
3.2 KiB
Go
// Copyright (c) Tailscale Inc & contributors
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
// Package remoteconfig registers a c2n endpoint that lets the control
|
|
// plane invoke this node's LocalAPI when Prefs.RemoteConfig is true.
|
|
//
|
|
// # Trust model
|
|
//
|
|
// Tailscale's default posture is per-feature double opt-in: the tailnet
|
|
// admin can request something server-side, but the local machine owner
|
|
// still has to consent (via CLI, GUI, or LocalAPI) for each individual
|
|
// setting. RemoteConfig is a different, more permissive posture: a
|
|
// single client-side "I trust the tailnet admin" switch. Once
|
|
// Prefs.RemoteConfig is true, the control plane can invoke any of this
|
|
// node's LocalAPI endpoints (which includes read/write of every pref)
|
|
// with no further local consent.
|
|
//
|
|
// This is appropriate when the tailnet admin owns the machine (e.g. a
|
|
// corporate fleet device) or when the local user has explicitly
|
|
// delegated full control to the tailnet admin. It should NOT be used
|
|
// on personal or BYOD devices where the tailnet admin is not fully
|
|
// trusted.
|
|
package remoteconfig
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
|
|
"tailscale.com/feature"
|
|
"tailscale.com/ipn/ipnauth"
|
|
"tailscale.com/ipn/ipnlocal"
|
|
"tailscale.com/ipn/localapi"
|
|
)
|
|
|
|
// c2nPrefix is the c2n URL path prefix under which requests are
|
|
// proxied to this node's LocalAPI at /localapi/*, regardless of the
|
|
// LocalAPI version (v0, v1, ...).
|
|
const c2nPrefix = "/remoteapi/localapi/"
|
|
|
|
// localAPIStrip is the portion of c2nPrefix that must be stripped from
|
|
// the incoming c2n path to yield the LocalAPI path.
|
|
const localAPIStrip = "/remoteapi"
|
|
|
|
func init() {
|
|
if !feature.Register("remoteconfig") {
|
|
return
|
|
}
|
|
ipnlocal.RegisterC2NPrefix(c2nPrefix, handleC2NRemoteAPI)
|
|
}
|
|
|
|
// handleC2NRemoteAPI proxies c2n requests under /remoteapi/localapi/*
|
|
// to this node's LocalAPI at /localapi/*, with full read/write
|
|
// permission, when the local machine has opted in via Prefs.RemoteConfig.
|
|
//
|
|
// See the package doc for the trust model this handler represents.
|
|
func handleC2NRemoteAPI(b *ipnlocal.LocalBackend, w http.ResponseWriter, r *http.Request) {
|
|
prefs := b.Prefs()
|
|
if !prefs.Valid() || !prefs.RemoteConfig() {
|
|
http.Error(w, "remote config not enabled by local machine", http.StatusForbidden)
|
|
return
|
|
}
|
|
if !strings.HasPrefix(r.URL.Path, c2nPrefix) {
|
|
http.Error(w, "unexpected remote-config path", http.StatusBadRequest)
|
|
return
|
|
}
|
|
|
|
// Rewrite the URL from /remoteapi/localapi/X to /localapi/X on a
|
|
// shallow clone so we don't mutate the caller's Request.
|
|
u := *r.URL
|
|
u.Path = strings.TrimPrefix(r.URL.Path, localAPIStrip)
|
|
if r.URL.RawPath != "" {
|
|
u.RawPath = strings.TrimPrefix(r.URL.RawPath, localAPIStrip)
|
|
}
|
|
r2 := r.WithContext(r.Context())
|
|
r2.URL = &u
|
|
if u.Path == r.URL.Path {
|
|
// Prefix strip did nothing; refuse rather than looping.
|
|
http.Error(w, "unexpected remote-config path", http.StatusBadRequest)
|
|
return
|
|
}
|
|
if !strings.HasPrefix(u.Path, "/localapi/") {
|
|
http.Error(w, "unexpected remote-config path", http.StatusBadRequest)
|
|
return
|
|
}
|
|
|
|
lah := localapi.NewHandler(localapi.HandlerConfig{
|
|
Actor: ipnauth.Self,
|
|
Backend: b,
|
|
Logf: b.Logger(),
|
|
LogID: b.BackendLogID(),
|
|
EventBus: b.Sys().Bus.Get(),
|
|
})
|
|
lah.PermitRead = true
|
|
lah.PermitWrite = true
|
|
lah.ServeHTTP(w, r2)
|
|
}
|