File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1670,20 +1670,17 @@ func generateDockerFirewallWriteFiles() string {
16701670 // NAT/FORWARD rules that can make `docker run -p host:container` reachable
16711671 // from the public internet even when UFW says incoming traffic is denied.
16721672 //
1673- // DOCKER-USER is Docker's documented filter hook for this traffic. The
1674- // ordering is important: some Nebius images run cloud-init before Docker has
1675- // created DOCKER-USER, and Docker may create/reset the chain during daemon
1676- // startup. We therefore install both:
1677- // - an immediate cloud-init run for images where Docker is already active
1678- // - a docker.service ExecStartPost hook for images where Docker starts later
1673+ // DOCKER-USER is Docker's documented filter hook for this traffic. The script
1674+ // ensures the chain exists before configuring it. If Docker already created
1675+ // the chain, the create command fails harmlessly and the script continues.
16791676 //
16801677 // The generated script exits successfully even if an iptables command fails
16811678 // because failing Docker startup would be worse operationally. Validation
16821679 // tests assert that the rule set is actually present and blocks published
16831680 // ports.
16841681 //
1685- // UFW persists its own rules in /etc/ufw; only DOCKER-USER needed a Docker
1686- // startup hook after removing netfilter-persistent .
1682+ // UFW persists its own rules in /etc/ufw; Docker firewall rules are applied
1683+ // through cloud-init and the docker.service post-start hook .
16871684 return fmt .Sprintf (`
16881685write_files:
16891686 - path: %s
Original file line number Diff line number Diff line change @@ -15,6 +15,10 @@ const (
1515 ufwDefaultAllowPort2222 = "ufw allow 2222/tcp"
1616 ufwForceEnable = "ufw --force enable"
1717
18+ // Ensure DOCKER-USER exists before clearing it. Docker normally creates this
19+ // chain, but firewall setup can run before Docker has initialized iptables.
20+ ipTablesCreateDockerUserChain = "iptables -N DOCKER-USER || true"
21+
1822 // Clear DOCKER-USER policy.
1923 ipTablesResetDockerUserChain = "iptables -F DOCKER-USER"
2024
@@ -83,6 +87,7 @@ func (c *ShadeformClient) getUFWCommands(firewallRules v1.FirewallRules) []strin
8387
8488func (c * ShadeformClient ) getIPTablesCommands () []string {
8589 commands := []string {
90+ ipTablesCreateDockerUserChain ,
8691 ipTablesResetDockerUserChain ,
8792 ipTablesAllowDockerUserOutbound ,
8893 ipTablesAllowDockerUserOutboundInit0 ,
Original file line number Diff line number Diff line change 1+ package v1
2+
3+ import (
4+ "strings"
5+ "testing"
6+
7+ "github.com/stretchr/testify/assert"
8+ )
9+
10+ func TestShadeformIPTablesCommandsCreateDockerUserChainBeforeFlush (t * testing.T ) {
11+ client := & ShadeformClient {}
12+ commands := strings .Join (client .getIPTablesCommands (), "\n " )
13+
14+ createChainIndex := strings .Index (commands , "iptables -N DOCKER-USER" )
15+ flushChainIndex := strings .Index (commands , "iptables -F DOCKER-USER" )
16+
17+ assert .Greater (t , createChainIndex , - 1 )
18+ assert .Greater (t , flushChainIndex , createChainIndex )
19+ }
You can’t perform that action at this time.
0 commit comments