Skip to content

Commit 1fbbb2b

Browse files
committed
review feedback
1 parent 590764d commit 1fbbb2b

3 files changed

Lines changed: 35 additions & 8 deletions

File tree

v1/providers/nebius/instance.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1657,6 +1657,12 @@ const (
16571657
// Keep these generated paths stable: cloud-init, systemd, and validation
16581658
// tests all depend on this Docker firewall handoff.
16591659
dockerFirewallScriptPath = "/usr/local/sbin/brev-apply-docker-firewall.sh"
1660+
1661+
// This is a docker.service drop-in because the firewall rules must be
1662+
// re-applied immediately after Docker initializes or resets DOCKER-USER. If
1663+
// we need a separately inspectable status surface later, this can move to a
1664+
// named oneshot unit such as brev-docker-firewall.service; for now the
1665+
// execution is visible through docker.service journal/status output.
16601666
dockerServiceDropInDir = "/etc/systemd/system/docker.service.d"
16611667
dockerFirewallDropInPath = dockerServiceDropInDir + "/10-brev-firewall.conf"
16621668
)
@@ -1670,20 +1676,17 @@ func generateDockerFirewallWriteFiles() string {
16701676
// NAT/FORWARD rules that can make `docker run -p host:container` reachable
16711677
// from the public internet even when UFW says incoming traffic is denied.
16721678
//
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
1679+
// DOCKER-USER is Docker's documented filter hook for this traffic. The script
1680+
// ensures the chain exists before configuring it. If Docker already created
1681+
// the chain, the create command fails harmlessly and the script continues.
16791682
//
16801683
// The generated script exits successfully even if an iptables command fails
16811684
// because failing Docker startup would be worse operationally. Validation
16821685
// tests assert that the rule set is actually present and blocks published
16831686
// ports.
16841687
//
1685-
// UFW persists its own rules in /etc/ufw; only DOCKER-USER needed a Docker
1686-
// startup hook after removing netfilter-persistent.
1688+
// UFW persists its own rules in /etc/ufw; Docker firewall rules are applied
1689+
// through cloud-init and the docker.service post-start hook.
16871690
return fmt.Sprintf(`
16881691
write_files:
16891692
- path: %s

v1/providers/shadeform/firewall.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff 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

8488
func (c *ShadeformClient) getIPTablesCommands() []string {
8589
commands := []string{
90+
ipTablesCreateDockerUserChain,
8691
ipTablesResetDockerUserChain,
8792
ipTablesAllowDockerUserOutbound,
8893
ipTablesAllowDockerUserOutboundInit0,
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
}

0 commit comments

Comments
 (0)