Refuse to serve when a configured socket restriction cannot be applied

This commit is contained in:
Viktor Liu
2026-09-09 06:15:38 +02:00
parent 72bf5adad7
commit 1db3c7bf13
3 changed files with 63 additions and 9 deletions
+30
View File
@@ -100,6 +100,36 @@ func TestDaemonSocketPrincipals(t *testing.T) {
})
}
// A TCP listener can express neither a socket mode nor a security descriptor,
// so a restriction configured against one must stop the daemon rather than be
// dropped while it goes on serving every caller that can reach the port.
func TestTCPListenerRefusesARestriction(t *testing.T) {
t.Run("listenOnAddress refuses before binding", func(t *testing.T) {
listener, err := listenOnAddress("tcp://127.0.0.1:0", []string{testAllowGroupPrincipal})
require.Error(t, err)
require.Nil(t, listener)
assert.Contains(t, err.Error(), "tcp")
})
t.Run("listenOnAddress still serves tcp when nothing is configured", func(t *testing.T) {
listener, err := listenOnAddress("tcp://127.0.0.1:0", nil)
require.NoError(t, err)
t.Cleanup(func() { assert.NoError(t, listener.Close()) })
assert.NoError(t, listener.restrict("daemon", nil))
})
t.Run("restrict refuses a listener that cannot carry the restriction", func(t *testing.T) {
listener := &socketListener{network: "tcp", address: "127.0.0.1:41731"}
require.Error(t, listener.restrict("daemon", []string{testAllowGroupPrincipal}))
assert.NoError(t, listener.restrict("daemon", nil))
})
t.Run("a disabled json socket is not an error", func(t *testing.T) {
var listener *socketListener
assert.NoError(t, listener.restrict("daemon JSON", []string{testAllowGroupPrincipal}))
})
}
func TestCutKind(t *testing.T) {
tests := []struct {
value string