Keep llmgw's internal ports to the cluster's networks with an nftables table of its own
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
7e57863edd
commit
7b6276901a
17 files changed
+800
-10
No files matched your search
@@ -20,6 +20,7 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"gitea.mynodes.xyz/ilker/llmgw/internal/config"
|
||||
"gitea.mynodes.xyz/ilker/llmgw/internal/firewall"
|
||||
"gitea.mynodes.xyz/ilker/llmgw/internal/onboard"
|
||||
"gitea.mynodes.xyz/ilker/llmgw/internal/pgha"
|
||||
"gitea.mynodes.xyz/ilker/llmgw/internal/store"
|
||||
@@ -38,6 +39,8 @@ type serverAdd struct {
|
||||
vip string
|
||||
|
||||
remote onboard.Remote
|
||||
// noFirewall leaves the new control plane's firewall as it is.
|
||||
noFirewall bool
|
||||
// addr is the machine's address as given; ip what the others reach it at.
|
||||
addr, ip, name string
|
||||
out io.Writer
|
||||
@@ -78,6 +81,8 @@ func newServerAddCmd() *cobra.Command {
|
||||
f.StringArrayVar(&sa.hosts, "host", nil, "another name for the new control plane's certificate; repeatable")
|
||||
f.StringVar(&sa.vip, "vip", "", "a floating address for whichever control plane leads, as 10.0.0.160/24")
|
||||
f.StringVar(&sa.pkiDir, "pki", sa.pkiDir, "directory holding the certificate authority")
|
||||
f.BoolVar(&sa.noFirewall, "no-firewall", false,
|
||||
"leave its firewall alone, instead of keeping llmgw's internal ports to the cluster's networks")
|
||||
return cmd
|
||||
}
|
||||
|
||||
@@ -121,6 +126,12 @@ func (sa *serverAdd) run(ctx context.Context) error {
|
||||
{"store", sa.storeAccess},
|
||||
{"service", sa.service},
|
||||
}
|
||||
if !sa.noFirewall {
|
||||
steps = append(steps, struct {
|
||||
name string
|
||||
fn func(context.Context) error
|
||||
}{"firewall", sa.firewall})
|
||||
}
|
||||
if sa.vip != "" {
|
||||
steps = append(steps, struct {
|
||||
name string
|
||||
@@ -136,6 +147,36 @@ func (sa *serverAdd) run(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// firewall keeps the new control plane's internal ports to the networks it
|
||||
// reaches this one on. Not fatal: it serves without one.
|
||||
func (sa *serverAdd) firewall(ctx context.Context) error {
|
||||
cfg, err := config.Load(filepath.Join(sa.etcDir, "server.yaml"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
self, err := sourceIPToward(sa.ip)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
nets, err := firewall.Networks(ctx, sa.remote, []string{self})
|
||||
if err == nil {
|
||||
extra, _ := cfg.FirewallAllow()
|
||||
nets = append(nets, extra...)
|
||||
var changed bool
|
||||
if changed, err = firewall.Install(ctx, sa.remote,
|
||||
firewall.Spec{Ports: controlPlanePorts(cfg), Allow: nets}); err == nil {
|
||||
if changed {
|
||||
sa.done("firewall: llmgw's internal ports answer the cluster's networks only")
|
||||
} else {
|
||||
sa.kept("firewall")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
fmt.Fprintf(sa.out, " !! firewall: %v\n", err)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (sa *serverAdd) connect(ctx context.Context) error {
|
||||
out, err := sa.sh(ctx, "hostname; sudo -n true && echo sudo-ok", nil)
|
||||
if err != nil {
|
||||
|
||||
Reference in new issue
Block a user