Add a local control socket and nebula ctl (#1975)

Add support for accessing the previously ssh-only debug commands via
`nebula ctl <command>.`

- unix socket (named pipe on windows) for communication
- sockets scoped to the user + an optional group
- in cmd/nebula and cmd/nebula-service, but not nebula.Main

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Matt RichardsonandClaude Fable 5.1 authored and GitHub committed 2026-10-21 11:16:00 -04:00
1 parent 9a5bdb508e
commit 0f767ce529
54 files changed
+7581 -925

No files matched your search

+13
View File
@@ -8,6 +8,7 @@ import (
"github.com/kardianos/service"
"github.com/slackhq/nebula"
"github.com/slackhq/nebula/config"
"github.com/slackhq/nebula/localapi"
"github.com/slackhq/nebula/logging"
)
@@ -17,6 +18,7 @@ type program struct {
configPath *string
build string
control *nebula.Control
ctl *localapi.Server
}
func (p *program) Start(s service.Service) error {
@@ -50,10 +52,16 @@ func (p *program) Start(s service.Service) error {
return err
}
// Now that we're started, stand up the local control socket.
p.ctl = localapi.Wire(p.control.Context(), l, c, p.control.Commands())
// Nebula can stop itself on a fatal packet reader error, make sure to log it if it happens.
go func() {
if err := p.control.Wait(); err != nil {
logger.Error(fmt.Sprintf("Nebula stopped due to fatal error: %v", err))
// os.Exit skips deferred calls and races the socket's own context watcher,
// so the socket is removed here, as cmd/nebula does.
p.ctl.Stop()
os.Exit(2)
}
}()
@@ -63,6 +71,11 @@ func (p *program) Start(s service.Service) error {
func (p *program) Stop(s service.Service) error {
logger.Info("Nebula service stopping.")
if p.ctl != nil {
p.ctl.Stop()
}
if p.control == nil {
return nil
}