firewall: validate that conntrack timeouts are strictly positive (#1984)
smoke-extra / freebsd-amd64 (push) Failing after 46s
smoke-extra / linux-amd64-ipv6disable (push) Failing after 45s
smoke-extra / netbsd-amd64 (push) Failing after 41s
smoke-extra / openbsd-amd64 (push) Failing after 1m25s
smoke-extra / linux-386 (push) Failing after 1m47s
smoke / Run multi node smoke test (push) Failing after 1m43s
Build and test / Static checks (push) Successful in 2m21s
Build and test / Test linux (push) Failing after 1m13s
Build and test / Test linux-pkcs11 (push) Failing after 2m7s
Build and test / Test linux-boringcrypto (push) Failing after 3m0s
Build and test / Test linux-fips140 (push) Failing after 3m9s
Build and test / Cross-build linux-arm (push) Successful in 3m11s
Build and test / Cross-build linux-mips (push) Successful in 3m49s
Build and test / Cross-build linux-other (push) Successful in 3m12s
Build and test / Cross-build windows (push) Successful in 1m4s
Build and test / Cross-build freebsd (push) Successful in 1m35s
Build and test / Cross-build netbsd (push) Successful in 1m34s
Build and test / Cross-build openbsd (push) Successful in 1m35s
Build and test / Cross-build mobile (push) Successful in 3m28s
smoke-extra / Run windows smoke test (push) Canceled after 0s
smoke / Run self traffic smoke test on macOS (push) Canceled after 0s
Build and test / Test macos (push) Canceled after 0s
Build and test / Test windows (push) Canceled after 0s
Build and test / CI status (push) Canceled after 0s

This commit is contained in:
Aryan Patil authored and GitHub committed 2026-10-21 10:23:10 -05:00
1 parent 0f767ce529
commit 92c67a52b2
2 files changed
+42 -3

No files matched your search

+17 -3
View File
@@ -206,11 +206,25 @@ func NewFirewallFromConfig(l *slog.Logger, cs *CertState, c *config.C) (*Firewal
panic("No certificate available to reconfigure the firewall")
}
tcpTimeout := c.GetDuration("firewall.conntrack.tcp_timeout", time.Minute*12)
udpTimeout := c.GetDuration("firewall.conntrack.udp_timeout", time.Minute*3)
defaultTimeout := c.GetDuration("firewall.conntrack.default_timeout", time.Minute*10)
if tcpTimeout <= 0 {
return nil, fmt.Errorf("firewall.conntrack.tcp_timeout must be greater than 0, got: %s", tcpTimeout)
}
if udpTimeout <= 0 {
return nil, fmt.Errorf("firewall.conntrack.udp_timeout must be greater than 0, got: %s", udpTimeout)
}
if defaultTimeout <= 0 {
return nil, fmt.Errorf("firewall.conntrack.default_timeout must be greater than 0, got: %s", defaultTimeout)
}
fw := NewFirewall(
l,
c.GetDuration("firewall.conntrack.tcp_timeout", time.Minute*12),
c.GetDuration("firewall.conntrack.udp_timeout", time.Minute*3),
c.GetDuration("firewall.conntrack.default_timeout", time.Minute*10),
tcpTimeout,
udpTimeout,
defaultTimeout,
certificate,
//TODO: max_connections
)
+25
View File
@@ -58,6 +58,31 @@ func TestNewFirewall(t *testing.T) {
assert.Equal(t, 3602, conntrack.TimerWheel.wheelLen)
}
func TestNewFirewall_ZeroOrNegativeTimeout(t *testing.T) {
l := test.NewLogger()
c := &dummyCert{}
cs := &CertState{v2Cert: c, initiatingVersion: cert.Version2}
cases := map[string]string{
"tcp_timeout zero": "firewall:\n conntrack:\n tcp_timeout: 0s\n",
"tcp_timeout negative": "firewall:\n conntrack:\n tcp_timeout: -5s\n",
"udp_timeout zero": "firewall:\n conntrack:\n udp_timeout: 0s\n",
"udp_timeout negative": "firewall:\n conntrack:\n udp_timeout: -5s\n",
"default_timeout zero": "firewall:\n conntrack:\n default_timeout: 0s\n",
"default_timeout negative": "firewall:\n conntrack:\n default_timeout: -5s\n",
}
for name, cfgStr := range cases {
t.Run(name, func(t *testing.T) {
cfg := config.NewC(l)
require.NoError(t, cfg.LoadString(cfgStr))
_, err := NewFirewallFromConfig(l, cs, cfg)
require.Error(t, err, "expected error for non-positive timeout duration")
assert.ErrorContains(t, err, "must be greater than 0")
})
}
}
func TestFirewall_AddRule(t *testing.T) {
ob := &bytes.Buffer{}
l := test.NewLoggerWithOutput(ob)