node add lets the node through the control plane's firewall

The control plane's firewall answered only the networks it was installed
with, so a node on another subnet was set up, could not reach 7443 and
showed as lost. node add now admits the node's network (or its address,
when routed) into the local ruleset, keeping everything already there.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ilker ManapandClaude Opus 5.5 committed 2026-10-05 13:27:57 +02:00
1 parent 4ff62c5dd2
commit cbbfce235e
5 files changed
+138 -3

No files matched your search

+52
View File
@@ -1,6 +1,7 @@
package firewall
import (
"context"
"net/netip"
"strings"
"testing"
@@ -58,3 +59,54 @@ func TestARulesetReadsBackAsItsSpec(t *testing.T) {
t.Errorf("read back as\n%s\nfrom\n%s", Script(got), Script(in))
}
}
// fakeMachine answers the scripts Admit runs: the ruleset file, the route,
// and an install, which it records.
type fakeMachine struct {
rules string
route string
installed []byte
}
func (f *fakeMachine) Run(_ context.Context, script string, stdin []byte) ([]byte, error) {
switch {
case strings.HasPrefix(script, "sudo cat "):
return []byte(f.rules), nil
case strings.HasPrefix(script, "ip -o route get"):
return []byte(f.route), nil
default:
f.installed = stdin
return []byte("changed\n"), nil
}
}
func TestANodeOnAnotherNetworkIsLetIn(t *testing.T) {
rules := Script(Spec{Ports: []Port{AgentPort, MirrorFiles},
Allow: []netip.Prefix{netip.MustParsePrefix("10.104.130.128/25")}})
m := &fakeMachine{rules: rules,
route: "10.20.0.5 via 10.104.130.129 dev eth0 src 10.104.130.140 uid 0\n" +
"2: eth0 inet 10.104.130.140/25 brd 10.104.130.255 scope global eth0\n"}
added, err := Admit(context.Background(), m, []string{"10.104.130.200"})
if err != nil || len(added) != 0 || m.installed != nil {
t.Fatalf("an address the rules hold: added %v, err %v, installed %v", added, err, m.installed != nil)
}
added, err = Admit(context.Background(), m, []string{"10.20.0.5", "gpu01"})
if err != nil {
t.Fatal(err)
}
if len(added) != 1 || added[0].String() != "10.20.0.5/32" {
t.Errorf("added %v, want the routed node's address alone", added)
}
got := parse(strings.Split(string(m.installed), "\x00")[0])
if len(got.Ports) != 2 || len(got.Allow) != 2 {
t.Errorf("installed %+v, want both ports kept and both networks", got)
}
// No llmgw rules on the machine: none are made.
bare := &fakeMachine{}
if added, err := Admit(context.Background(), bare, []string{"10.20.0.5"}); err != nil || added != nil || bare.installed != nil {
t.Errorf("a machine without rules: added %v, err %v", added, err)
}
}