mirror of
https://github.com/slackhq/nebula.git
synced 2026-11-15 09:26:52 +01:00
Report ssh command failures to the surface (#1959)
smoke-extra / freebsd-amd64 (push) Failing after 14s
smoke-extra / linux-amd64-ipv6disable (push) Failing after 13s
smoke-extra / netbsd-amd64 (push) Failing after 14s
smoke-extra / openbsd-amd64 (push) Failing after 15s
smoke-extra / linux-386 (push) Failing after 14s
smoke / Run multi node smoke test (push) Failing after 1m46s
Build and test / Static checks (push) Successful in 2m38s
Build and test / Test linux (push) Failing after 1m12s
Build and test / Test linux-pkcs11 (push) Failing after 2m6s
Build and test / Test linux-boringcrypto (push) Failing after 3m0s
Build and test / Test linux-fips140 (push) Failing after 2m56s
Build and test / Cross-build linux-arm (push) Successful in 3m10s
Build and test / Cross-build linux-mips (push) Successful in 3m55s
Build and test / Cross-build linux-other (push) Successful in 3m15s
Build and test / Cross-build windows (push) Successful in 1m5s
Build and test / Cross-build freebsd (push) Successful in 1m37s
Build and test / Cross-build netbsd (push) Successful in 1m36s
Build and test / Cross-build openbsd (push) Successful in 1m35s
Build and test / Cross-build mobile (push) Successful in 3m32s
smoke-extra / Run windows smoke test (push) Canceled after 0s
smoke / Run self traffic smoke test on macOS (push) Canceled after 0s
Build and test / Test macos (push) Canceled after 0s
Build and test / Test windows (push) Canceled after 0s
Build and test / CI status (push) Canceled after 0s
smoke-extra / freebsd-amd64 (push) Failing after 14s
smoke-extra / linux-amd64-ipv6disable (push) Failing after 13s
smoke-extra / netbsd-amd64 (push) Failing after 14s
smoke-extra / openbsd-amd64 (push) Failing after 15s
smoke-extra / linux-386 (push) Failing after 14s
smoke / Run multi node smoke test (push) Failing after 1m46s
Build and test / Static checks (push) Successful in 2m38s
Build and test / Test linux (push) Failing after 1m12s
Build and test / Test linux-pkcs11 (push) Failing after 2m6s
Build and test / Test linux-boringcrypto (push) Failing after 3m0s
Build and test / Test linux-fips140 (push) Failing after 2m56s
Build and test / Cross-build linux-arm (push) Successful in 3m10s
Build and test / Cross-build linux-mips (push) Successful in 3m55s
Build and test / Cross-build linux-other (push) Successful in 3m15s
Build and test / Cross-build windows (push) Successful in 1m5s
Build and test / Cross-build freebsd (push) Successful in 1m37s
Build and test / Cross-build netbsd (push) Successful in 1m36s
Build and test / Cross-build openbsd (push) Successful in 1m35s
Build and test / Cross-build mobile (push) Successful in 3m32s
smoke-extra / Run windows smoke test (push) Canceled after 0s
smoke / Run self traffic smoke test on macOS (push) Canceled after 0s
Build and test / Test macos (push) Canceled after 0s
Build and test / Test windows (push) Canceled after 0s
Build and test / CI status (push) Canceled after 0s
Report ssh command failures to the surface (#1959) The ssh debug commands told the user when something went wrong but never told the surface that ran them, so `ssh host cmd` always exited 0 and a few failures were not reported at all. A failed command now returns its error, a failure the user has already heard about is a commands.Failure, and the ssh exec path exits 1 for either. The command bodies also lose their ssh prefixes and the duplication they carried over from ssh.go; both goldens pin that nothing else changed. - Dispatch returns the callback's error, or shlex's; the ssh session logs it at debug, and not at all for a Failure the user already saw - commands.Fail writes a message and returns it as a Failure in one step; an unknown command, `help` for a command that is not there, a failed reload and an unbalanced quote are failures - ssh exec exit-status is 1 for a command, flag or failure error, 0 otherwise; the e2e golden records the exit status for every case - Clone rebinds help to the copy, so an ssh session's help lists logout and `help logout` and `logout -h` answer; sshd.LogoutCommand is the session's logout, exported for tests - "did not understand" names the first word only, the one looked up; DispatchArgs takes just the tokens - log-format writes its refusal to the user, as log-level does - print-relays emits the relay error as a string and omits the key when there is none, where it printed {} or "Error":null - list-hostmap and list-lighthouse-addrmap -json return the encode error; print-cert reports a certificate that will not marshal - a flags type that is not the one registered is an internal error, not a silent success - command functions and flag types are <name>Command and <name>Flags; parseVpnAddr and listHostMapFlagSet replace the repeated parse block and flag set; close-tunnel sends through sendCloseTunnel Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
1 parent
b426843f88
commit
8a4bd8b10f
11 files changed
+641
-246
No files matched your search
+20
-9
@@ -7,6 +7,7 @@ import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/slackhq/nebula/commands"
|
||||
"github.com/slackhq/nebula/config"
|
||||
"github.com/slackhq/nebula/test"
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -26,7 +27,7 @@ func (w *lineWriter) Write(s string) error { return w.WriteLine(s) }
|
||||
func (w *lineWriter) WriteBytes(b []byte) error { return w.WriteLine(string(b)) }
|
||||
func (w *lineWriter) GetWriter() io.Writer { return io.Discard }
|
||||
|
||||
func TestSSHReloadReportsTheResult(t *testing.T) {
|
||||
func TestReloadCommandReportsTheResult(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
write := func(body string) {
|
||||
require.NoError(t, os.WriteFile(filepath.Join(dir, "config.yml"), []byte(body), 0o600))
|
||||
@@ -43,32 +44,42 @@ func TestSSHReloadReportsTheResult(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
reload := func() []string {
|
||||
// reload returns what the client was told. A reload that failed is a commands.Failure
|
||||
// to the surface, exit 1 over ssh, with the result line as its message; one that
|
||||
// merely needs a restart is not.
|
||||
reload := func(failed bool) []string {
|
||||
w := &lineWriter{}
|
||||
require.NoError(t, sshReload(l, c, w))
|
||||
err := reloadCommand(l, c, w)
|
||||
if failed {
|
||||
var f *commands.Failure
|
||||
require.ErrorAs(t, err, &f)
|
||||
assert.Equal(t, w.lines[len(w.lines)-1], f.Msg)
|
||||
} else {
|
||||
require.NoError(t, err)
|
||||
}
|
||||
return w.lines
|
||||
}
|
||||
|
||||
write("a: 2\nb: 1")
|
||||
assert.Equal(t, []string{"Reloading config", "Config reload complete"}, reload())
|
||||
assert.Equal(t, []string{"Reloading config", "Config reload complete"}, reload(false))
|
||||
|
||||
fail = true
|
||||
write("a: 3\nb: 1")
|
||||
assert.Equal(t, []string{"Reloading config", "Config reload completed with errors, review the logs"}, reload())
|
||||
assert.Equal(t, []string{"Reloading config", "Config reload completed with errors, review the logs"}, reload(true))
|
||||
|
||||
fail = false
|
||||
write("a: 3\nb: 2")
|
||||
assert.Equal(t, []string{"Reloading config", "Config reload was completed but requires a restart to fully apply, keys [b]"}, reload())
|
||||
assert.Equal(t, []string{"Reloading config", "Config reload was completed but requires a restart to fully apply, keys [b]"}, reload(false))
|
||||
|
||||
write("a: [")
|
||||
lines := reload()
|
||||
lines := reload(true)
|
||||
require.Len(t, lines, 2)
|
||||
assert.Contains(t, lines[1], "Config reload failed, the new config did not load")
|
||||
assert.Contains(t, lines[1], dir, "names the config that did not load")
|
||||
}
|
||||
|
||||
// A client that went away still gets the reload it asked for
|
||||
func TestSSHReloadReloadsWhenTheClientIsGone(t *testing.T) {
|
||||
func TestReloadCommandReloadsWhenTheClientIsGone(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
require.NoError(t, os.WriteFile(filepath.Join(dir, "config.yml"), []byte("a: 1"), 0o600))
|
||||
l := test.NewLogger()
|
||||
@@ -78,6 +89,6 @@ func TestSSHReloadReloadsWhenTheClientIsGone(t *testing.T) {
|
||||
c.RegisterReloadCallback(func(*config.C, *config.Reload) { reloaded = true })
|
||||
|
||||
gone := errors.New("client is gone")
|
||||
require.ErrorIs(t, sshReload(l, c, &lineWriter{err: gone}), gone)
|
||||
require.ErrorIs(t, reloadCommand(l, c, &lineWriter{err: gone}), gone)
|
||||
assert.True(t, reloaded)
|
||||
}
|
||||
Reference in new issue
Block a user