Keep an allowance with no interface off the outward links
An allowance of the default set opened every link but the tunnel, so a node's internet-facing link took it too. It now negates the tunnel and every outward link, the same links the derived rules count as outside; an outward link opens only when an allowance names it. Builds: design 08 control-verbs §2, §8; design 47 H lead answer H-A-324
This commit is contained in:
@@ -201,7 +201,8 @@ type Allowing struct {
|
||||
// AsNftablesAllowing is AsNftablesWithLocal with the allowances the holder answered (design 08 control-verbs §2): one accept
|
||||
// rule per allowance in the input chain, after the derived ports' rules and before the chain's drop policy, each with the
|
||||
// comment `allowance <key> <at>`. Its interface by name, or for the default set a negated match on the private network's
|
||||
// interface (tunnel), so an interface that comes up later is covered and the tunnel never is; its source when it has one,
|
||||
// interface (tunnel) and the outward links (H-A-324), so an interface that comes up later is covered and neither the tunnel
|
||||
// nor an outward link ever is; an outward link is opened only when named; its source when it has one,
|
||||
// for the family of its CIDR. An allowance with an until matches its port as the one element of a set of the table with
|
||||
// the timeout flag, the element's timeout the time left to its until at allowing.At, at least 1 s, so the kernel closes the
|
||||
// port at its until even while the holder is away (H-A-315 (4)). The forward chain takes none: an allowance opens the input
|
||||
@@ -419,8 +420,10 @@ func AsNftablesAllowing(rules []mcat.Rule, mesh []string, outward bool, foundati
|
||||
switch {
|
||||
case a.Interface != "":
|
||||
match = append(match, fmt.Sprintf("iifname %q", a.Interface))
|
||||
case tunnel != "":
|
||||
match = append(match, fmt.Sprintf("iifname != %q", tunnel))
|
||||
case inward != "":
|
||||
// No interface: every input interface that is neither the private network's tunnel nor an outward link, the
|
||||
// links the derived rules count as outside (H-A-324); an outward link is opened only when named.
|
||||
match = append(match, fmt.Sprintf("iifname != { %s }", inward))
|
||||
}
|
||||
if a.Source != "" {
|
||||
family := "ip"
|
||||
|
||||
@@ -133,14 +133,23 @@ func TestTheModuleAskingForTheRuleSetGetsEveryModulesPorts(t *testing.T) {
|
||||
if none, today := render(), AsNftablesWithLocal(derived, []string{"10.10.0.1"}, false, nil, []string{"eth0"}, "mesh0", nil); none != today {
|
||||
t.Errorf("no allowance changed the file:\n%s\nwant\n%s", none, today)
|
||||
}
|
||||
// 08 control-verbs §8: one of the default set, a negated match on the private network's interface and no positive one.
|
||||
// 08 control-verbs §8, H-A-324: one of the default set, a negated match on the private network's interface and the outward
|
||||
// links, and no positive one.
|
||||
one := render(nodepacketfilter.Allowance{Key: "allow.tcp.8000", Port: 8000, Protocol: "tcp", At: "2026-11-21T19:00:00Z"})
|
||||
if want := "\t\tiifname != \"mesh0\" tcp dport 8000 accept comment \"allowance allow.tcp.8000 2026-11-21T19:00:00Z\"\n"; !strings.Contains(inputOf(one), want) {
|
||||
if want := "\t\tiifname != { \"eth0\", \"mesh0\" } tcp dport 8000 accept comment \"allowance allow.tcp.8000 2026-11-21T19:00:00Z\"\n"; !strings.Contains(inputOf(one), want) {
|
||||
t.Errorf("the default set's allowance is not rendered as %q:\n%s", want, one)
|
||||
}
|
||||
if strings.Contains(one, "iifname \"mesh0\" tcp dport 8000") || strings.Contains(one, "proto-dst 8000") {
|
||||
t.Errorf("the allowance opens the tunnel or the forward path:\n%s", one)
|
||||
}
|
||||
// H-A-324: an allowance with no interface never opens an outward link; one named in interfaces does.
|
||||
if strings.Contains(inputOf(one), "iifname \"eth0\" tcp dport 8000") {
|
||||
t.Errorf("the default set's allowance opens the outward link:\n%s", one)
|
||||
}
|
||||
named := render(nodepacketfilter.Allowance{Key: "allow.tcp.8000.eth0", Port: 8000, Protocol: "tcp", Interface: "eth0", At: "a1"})
|
||||
if want := "\t\tiifname \"eth0\" tcp dport 8000 accept comment \"allowance allow.tcp.8000.eth0 a1\"\n"; !strings.Contains(inputOf(named), want) {
|
||||
t.Errorf("the named outward link's allowance is not rendered as %q:\n%s", want, named)
|
||||
}
|
||||
// 08 control-verbs §8: three, one interface named, one with an IPv4 source, one udp, after the derived ones.
|
||||
three := inputOf(render(
|
||||
nodepacketfilter.Allowance{Key: "allow.udp.5353", Port: 5353, Protocol: "udp", At: "a3"},
|
||||
@@ -151,8 +160,8 @@ func TestTheModuleAskingForTheRuleSetGetsEveryModulesPorts(t *testing.T) {
|
||||
last := derivedAt
|
||||
for _, want := range []string{
|
||||
"\t\tiifname \"enp3s0\" tcp dport 8000 accept comment \"allowance allow.tcp.8000.enp3s0 a1\"\n",
|
||||
"\t\tiifname != \"mesh0\" ip saddr 192.168.1.0/24 tcp dport 9000 accept comment \"allowance allow.tcp.9000 a2\"\n",
|
||||
"\t\tiifname != \"mesh0\" udp dport 5353 accept comment \"allowance allow.udp.5353 a3\"\n",
|
||||
"\t\tiifname != { \"eth0\", \"mesh0\" } ip saddr 192.168.1.0/24 tcp dport 9000 accept comment \"allowance allow.tcp.9000 a2\"\n",
|
||||
"\t\tiifname != { \"eth0\", \"mesh0\" } udp dport 5353 accept comment \"allowance allow.udp.5353 a3\"\n",
|
||||
} {
|
||||
at := strings.Index(three, want)
|
||||
if at < 0 || at < last {
|
||||
@@ -170,9 +179,9 @@ func TestTheModuleAskingForTheRuleSetGetsEveryModulesPorts(t *testing.T) {
|
||||
for _, want := range []string{
|
||||
"\tset allowance_1 {\n\t\ttype inet_service\n\t\tflags timeout\n\t\telements = { 8000 timeout 3600s }\n\t}\n",
|
||||
"\tset allowance_2 {\n\t\ttype inet_service\n\t\tflags timeout\n\t\telements = { 8001 timeout 1s }\n\t}\n",
|
||||
"\t\tiifname != \"mesh0\" tcp dport @allowance_1 accept comment \"allowance allow.tcp.8000 a1\"\n",
|
||||
"\t\tiifname != \"mesh0\" tcp dport @allowance_2 accept comment \"allowance allow.tcp.8001 a2\"\n",
|
||||
"\t\tiifname != \"mesh0\" ip6 saddr 2001:db8::/32 tcp dport 8002 accept comment \"allowance allow.tcp.8002 a3\"\n",
|
||||
"\t\tiifname != { \"eth0\", \"mesh0\" } tcp dport @allowance_1 accept comment \"allowance allow.tcp.8000 a1\"\n",
|
||||
"\t\tiifname != { \"eth0\", \"mesh0\" } tcp dport @allowance_2 accept comment \"allowance allow.tcp.8001 a2\"\n",
|
||||
"\t\tiifname != { \"eth0\", \"mesh0\" } ip6 saddr 2001:db8::/32 tcp dport 8002 accept comment \"allowance allow.tcp.8002 a3\"\n",
|
||||
} {
|
||||
if !strings.Contains(until, want) {
|
||||
t.Errorf("the rule set lacks %q:\n%s", want, until)
|
||||
|
||||
Reference in New Issue
Block a user