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

+36
View File
@@ -317,3 +317,39 @@ func Present(ctx context.Context, r Runner) bool {
_, err := r.Run(ctx, "sudo -n /usr/sbin/nft list table inet "+Table+" >/dev/null 2>&1", nil)
return err == nil
}
// Admit lets addresses through a machine's ruleset when it has one: each
// one's network, as Networks finds it, unless a network already there holds
// it. A machine without llmgw's rules is left without them. What was added
// is returned, nothing when every address was already let in.
func Admit(ctx context.Context, r Runner, addrs []string) ([]netip.Prefix, error) {
old, err := r.Run(ctx, "sudo cat "+RulesFile+" 2>/dev/null || true", nil)
if err != nil {
return nil, err
}
prev := parse(string(old))
if len(prev.Ports) == 0 {
return nil, nil
}
var missing []string
for _, s := range addrs {
a, err := netip.ParseAddr(s)
if err != nil {
continue
}
if !slices.ContainsFunc(prev.Allow, func(p netip.Prefix) bool { return p.Contains(a) }) {
missing = append(missing, s)
}
}
if len(missing) == 0 {
return nil, nil
}
nets, err := Networks(ctx, r, missing)
if err != nil {
return nil, err
}
if _, err := Install(ctx, r, Spec{Allow: nets}); err != nil {
return nil, err
}
return nets, nil
}