mirror of
https://github.com/tailscale/tailscale.git
synced 2026-11-24 02:31:18 -08:00
updates tailscale/corp#33007 When a selected exit node can't carry internet traffic due to a misconfiguration (wrong ID, node deleted, routes removed, etc), blackhole default routes are installed and all internet traffic is dropped. That is the correct behavior -- better to drop than leak to the local network -- but it was entirely silent: the stable-ID lookup in nodeBackend.updateRouteManagerPrefs misses without a log line, and Status leaves ExitNodeStatus nil. The user sees a healthy Tailscale with no internet. If an admin fat-fingers the exit node name in an IT policy, for example, it's easy to break every node with zero feedback. This adds an exit-node-unavailable health warning covering every way the selection can fail to carry traffic (short of reachability which is a separate concern), reported via exitnodehealth.ArgExitNodeReason. The warning names the exit node, caching its display name while it is still a peer so the name survives its departure, and falls back to the stable ID or IP. When the selection is mandated by the ExitNodeID or ExitNodeIP policy settings, the message tells the user to contact their network administrator instead of suggesting they pick another exit node. To test this, set a forced exit node policy with some random ip or node id. The warning has a 5 second threshold. It should clear as soon as you change to a proper exit node. Signed-off-by: Jonathan Nobels <[email protected]>
189 lines
6.0 KiB
Go
189 lines
6.0 KiB
Go
// Copyright (c) Tailscale Inc & contributors
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
package ipnlocal
|
|
|
|
import (
|
|
"crypto/tls"
|
|
"net/http"
|
|
|
|
"tailscale.com/control/controlclient"
|
|
"tailscale.com/ipn"
|
|
"tailscale.com/ipn/ipnauth"
|
|
"tailscale.com/tailcfg"
|
|
"tailscale.com/tstime"
|
|
"tailscale.com/types/key"
|
|
"tailscale.com/types/netmap"
|
|
"tailscale.com/types/persist"
|
|
"tailscale.com/util/testenv"
|
|
"tailscale.com/wgengine/filter"
|
|
)
|
|
|
|
// forTest is an unexported type to hide all the test-only
|
|
// methods on [LocalBackend] from godoc.
|
|
type forTest struct{ b *LocalBackend }
|
|
|
|
// ForTest returns a handle to test-only methods on b.
|
|
// The resulting type is unexported to make it very obvious
|
|
// in godoc that this is not stable API. This method panics
|
|
// if called outside of tests, which also centralizes all
|
|
// must-be-in-tests validation.
|
|
func (b *LocalBackend) ForTest() forTest {
|
|
testenv.AssertInTest()
|
|
return forTest{b}
|
|
}
|
|
|
|
// HandleC2N calls [LocalBackend.handleC2N], for use by feature/ packages that
|
|
// register C2N handlers and want to test them.
|
|
func (f forTest) HandleC2N(w http.ResponseWriter, r *http.Request) {
|
|
f.b.handleC2N(w, r)
|
|
}
|
|
|
|
// SetIPServiceMappings overwrites the LocalBackend's IP-to-service mappings
|
|
// and propagates them to the netstack subsystem if registered.
|
|
func (f forTest) SetIPServiceMappings(m netmap.IPServiceMappings) {
|
|
b := f.b
|
|
b.mu.Lock()
|
|
defer b.mu.Unlock()
|
|
b.ipVIPServiceMap = m
|
|
if ns, ok := b.sys.Netstack.GetOK(); ok {
|
|
ns.UpdateIPServiceMappings(m)
|
|
}
|
|
}
|
|
|
|
// GetFilter returns the current packet filter.
|
|
func (f forTest) GetFilter() *filter.Filter {
|
|
b := f.b
|
|
// Take b.mu so the read serializes with [LocalBackend.setControlClientStatusLocked],
|
|
// which installs the netmap and the filter at separate sub-steps. Without
|
|
// this, a test thread that observes the new netmap (via [LocalBackend.NetMapWithPeers])
|
|
// can race ahead of the filter store and read the previous filter.
|
|
b.mu.Lock()
|
|
defer b.mu.Unlock()
|
|
return b.currentNode().filterAtomic.Load()
|
|
}
|
|
|
|
// SetControlClientGetter sets the func that creates a control plane
|
|
// client. It can be called at most once, before Start.
|
|
func (f forTest) SetControlClientGetter(newControlClient func(controlclient.Options) (controlclient.Client, error)) {
|
|
b := f.b
|
|
b.mu.Lock()
|
|
defer b.mu.Unlock()
|
|
if b.ccGen != nil {
|
|
panic("invalid use of forTest.SetControlClientGetter after Start")
|
|
}
|
|
b.ccGen = newControlClient
|
|
}
|
|
|
|
// Peers returns all the current peers, sorted by Node.ID, for integration
|
|
// tests in another repo.
|
|
func (f forTest) Peers() []tailcfg.NodeView {
|
|
return f.b.currentNode().PeersForTest()
|
|
}
|
|
|
|
// AwaitNodeKey returns a channel that is closed once a peer with the given
|
|
// node key first appears in the current netmap. If the peer is already
|
|
// present, the returned channel is already closed. See
|
|
// [nodeBackend.AwaitNodeKeyForTest].
|
|
func (f forTest) AwaitNodeKey(k key.NodePublic) <-chan struct{} {
|
|
return f.b.currentNode().AwaitNodeKeyForTest(k)
|
|
}
|
|
|
|
// CurrentUser returns the current user and the associated WindowsUserID.
|
|
// It will be removed along with the rest of the "current user" functionality
|
|
// as we progress on the multi-user improvements (tailscale/corp#18342).
|
|
func (f forTest) CurrentUser() (ipn.WindowsUserID, ipnauth.Actor) {
|
|
b := f.b
|
|
b.mu.Lock()
|
|
defer b.mu.Unlock()
|
|
return b.pm.CurrentUserID(), b.currentUser
|
|
}
|
|
|
|
// ConfigureCerts sets a certificate retrieval function to be used by this
|
|
// local backend, skipping the usual ACME certificate registration.
|
|
func (f forTest) ConfigureCerts(getCert func(hostname string) (*TLSCertKeyPair, error)) {
|
|
hook, ok := HookConfigureCertsForTest.GetOk()
|
|
if !ok {
|
|
panic("forTest.ConfigureCerts called without cert extension registered")
|
|
}
|
|
hook(f.b, getCert)
|
|
}
|
|
|
|
// GetACMETLSALPNCert returns the short-lived ACME tls-alpn-01 challenge
|
|
// certificate for hi, if any.
|
|
func (f forTest) GetACMETLSALPNCert(hi *tls.ClientHelloInfo) (*tls.Certificate, bool) {
|
|
return f.b.getACMETLSALPNCert(hi)
|
|
}
|
|
|
|
// SetServeConfig installs sc as the backend's current
|
|
// [ipn.ServeConfig] without going through the validation in
|
|
// [LocalBackend.SetServeConfig]. It is intended for tests that need a
|
|
// specific serve config without first standing up the prerequisites
|
|
// (netmap, prefs, etc.).
|
|
func (f forTest) SetServeConfig(sc ipn.ServeConfigView) {
|
|
b := f.b
|
|
b.mu.Lock()
|
|
defer b.mu.Unlock()
|
|
b.serveConfig = sc
|
|
}
|
|
|
|
// InitExtensions initializes the extensions without starting a control client.
|
|
func (f forTest) InitExtensions() {
|
|
f.b.mu.Lock()
|
|
defer f.b.mu.Unlock()
|
|
f.b.startOnce.Do(f.b.initOnce)
|
|
}
|
|
|
|
// SetNetMap installs nm as the backend's current netmap without going
|
|
// through control-plane plumbing. It is intended for tests that need a
|
|
// specific netmap (e.g. CertDomains, capabilities).
|
|
func (f forTest) SetNetMap(nm *netmap.NetworkMap) {
|
|
b := f.b
|
|
b.mu.Lock()
|
|
defer b.mu.Unlock()
|
|
b.currentNode().SetNetMap(nm)
|
|
}
|
|
|
|
// SetClock replaces b's clock with c, for tests that need
|
|
// time-dependent behavior to be deterministic.
|
|
func (f forTest) SetClock(c tstime.Clock) { f.b.clock = c }
|
|
|
|
// SetPrefs replaces the current prefs with newp.
|
|
func (f forTest) SetPrefs(newp *ipn.Prefs) {
|
|
if newp == nil {
|
|
panic("forTest.SetPrefs got nil prefs")
|
|
}
|
|
b := f.b
|
|
b.mu.Lock()
|
|
defer b.mu.Unlock()
|
|
b.setPrefsLocked(newp)
|
|
}
|
|
|
|
// AuthReconfig applies the current network map and preferences to the engine.
|
|
func (f forTest) AuthReconfig() { f.b.authReconfig() }
|
|
|
|
// SetPersist seeds the current profile's persisted identity without running
|
|
// the control client or backend state machine.
|
|
func (f forTest) SetPersist(p *persist.Persist) error {
|
|
b := f.b
|
|
b.mu.Lock()
|
|
defer b.mu.Unlock()
|
|
prefs := b.pm.CurrentPrefs().AsStruct()
|
|
prefs.Persist = p.Clone()
|
|
return b.pm.SetPrefs(prefs.View(), ipn.NetworkProfile{})
|
|
}
|
|
|
|
// SetState changes the backend state and dispatches its state change hooks.
|
|
func (f forTest) SetState(state ipn.State) {
|
|
f.b.mu.Lock()
|
|
defer f.b.mu.Unlock()
|
|
f.b.setStateLocked(state)
|
|
}
|
|
|
|
// ApplyNetMap installs a map through the production path, including feature hooks.
|
|
func (f forTest) ApplyNetMap(nm *netmap.NetworkMap) {
|
|
f.b.mu.Lock()
|
|
defer f.b.mu.Unlock()
|
|
f.b.setNetMapLocked(nm)
|
|
}
|