mirror of
https://github.com/slackhq/nebula.git
synced 2026-09-30 03:56:37 +02:00
Every diagnostic command nebula has was reachable through exactly one door:
the built-in ssh debug server. That server is off by default, and turning it
on means generating a host key, writing an sshd block with authorized public
keys, and SIGHUPing the daemon. That is a lot of ceremony to answer "what
version is this node running".
Nebula now serves the same commands over a local unix socket, enabled by
default, and `nebula ctl <command>` runs them. The socket lives in a 0700
directory so filesystem permissions are the access control; no keys, nothing
on the network. Failing to create it is logged and never blocks startup.
The command registry was already transport neutral, so this is mostly new
transport rather than new commands:
- diag/ holds the registry, dispatch, writer and wire protocol, moved out
of sshd because none of it was ever about ssh. sshd and ctl.go dispatch
against one shared registry.
- commands.go holds every command implementation, moved out of ssh.go
(which was 85% not ssh) and renamed off the ssh prefix. Adding a command
there makes it available over both transports.
- ssh.go keeps only host keys, authorized users, and the listen address.
- ctl.go supervises the socket, following the statsServer lifecycle shape.
The wire protocol frames the response rather than terminating it, because
print-cert -raw and list-hostmap -json both emit arbitrary bytes that no
sentinel could safely delimit. argv travels as a list so quoting survives.
Exit statuses are real: 0, 2 for usage, 127 for an unknown command.
Two things fall out. The ssh console now reports a real exit status instead
of a hardcoded zero, so `ssh host list-hostmap` is scriptable too. And eight
command callbacks that silently returned nil on a flags type mismatch now
report it, which the exit status makes visible.
Windows is a stub returning a clear "not supported" until it gets a named
pipe with a security descriptor; iOS and Android are never enabled, having no
daemon for a CLI to attach to.
Breaking for embedders of the sshd package: NewSSHServer takes a
*diag.Registry, SSHServer.RegisterCommand is gone in favor of registering on
that registry, and the command types live in diag rather than sshd.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014fya5fTXGiwX72FUmoL9y3
70 lines
1.8 KiB
Go
70 lines
1.8 KiB
Go
package nebula
|
|
|
|
import (
|
|
"bytes"
|
|
"log/slog"
|
|
"testing"
|
|
|
|
"github.com/slackhq/nebula/config"
|
|
"github.com/slackhq/nebula/diag"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
// attachedCommands is every command nebula exposes. The ssh console and `nebula ctl` dispatch
|
|
// against this one set, so this list is the contract for both transports.
|
|
var attachedCommands = []string{
|
|
"change-remote",
|
|
"close-tunnel",
|
|
"create-tunnel",
|
|
"device-info",
|
|
"list-hostmap",
|
|
"list-lighthouse-addrmap",
|
|
"list-pending-hostmap",
|
|
"log-format",
|
|
"log-level",
|
|
"mutex-profile-fraction",
|
|
"print-cert",
|
|
"print-relays",
|
|
"print-tunnel",
|
|
"query-lighthouse",
|
|
"reload",
|
|
"save-heap-profile",
|
|
"save-mutex-profile",
|
|
"start-cpu-profile",
|
|
"stop-cpu-profile",
|
|
"version",
|
|
}
|
|
|
|
func TestAttachCommands(t *testing.T) {
|
|
l := slog.New(slog.DiscardHandler)
|
|
reg := diag.NewRegistry()
|
|
|
|
// The callbacks capture these but do not touch them until a command runs, and this test
|
|
// only registers and asks for help.
|
|
attachCommands(l, config.NewC(l), reg, &Interface{})
|
|
|
|
t.Run("every command is registered", func(t *testing.T) {
|
|
for _, name := range attachedCommands {
|
|
assert.Equal(t, []string{name}, reg.Match(name), "%s is not registered", name)
|
|
}
|
|
})
|
|
|
|
t.Run("help is available for every command", func(t *testing.T) {
|
|
for _, name := range attachedCommands {
|
|
buf := &bytes.Buffer{}
|
|
require.NoError(t, reg.DispatchArgs([]string{"help", name}, diag.NewWriter(buf)), name)
|
|
assert.Contains(t, buf.String(), name+" - ", name)
|
|
}
|
|
})
|
|
|
|
t.Run("the command list names them all", func(t *testing.T) {
|
|
buf := &bytes.Buffer{}
|
|
require.NoError(t, reg.DispatchArgs(nil, diag.NewWriter(buf)))
|
|
|
|
for _, name := range attachedCommands {
|
|
assert.Contains(t, buf.String(), name+" - ", name)
|
|
}
|
|
})
|
|
}
|