Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions v1/providers/nebius/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -1744,14 +1744,19 @@ func generateCloudInitUserData(publicKey string, firewallRules v1.FirewallRules)
`, publicKey)
}

var commands []string
// Generate UFW firewall commands (similar to Shadeform's approach)
// UFW (Uncomplicated Firewall) is available on Ubuntu/Debian instances
ufwCommands := generateUFWCommands(firewallRules)
commands = append(commands, generateUFWCommands(firewallRules)...)

if len(ufwCommands) > 0 {
// Generate IPTables firewall commands to ensure docker ports are not made immediately
// accessible from the internet by default.
commands = append(commands, generateIPTablesCommands()...)

if len(commands) > 0 {
// Use runcmd to execute firewall setup commands
script += "\nruncmd:\n"
for _, cmd := range ufwCommands {
for _, cmd := range commands {
script += fmt.Sprintf(" - %s\n", cmd)
}
}
Expand Down Expand Up @@ -1786,6 +1791,17 @@ func generateUFWCommands(firewallRules v1.FirewallRules) []string {
return commands
}

// generateIPTablesCommands generates IPTables firewall commands to ensure docker ports are not made immediately
// accessible from the internet by default.
func generateIPTablesCommands() []string {
commands := []string{
"iptables -I DOCKER-USER -i lo -j ACCEPT",
"iptables -I DOCKER-USER -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT",
"iptables -A DOCKER-USER -j DROP",
}
return commands
}

// convertIngressRuleToUFW converts an ingress firewall rule to UFW command(s)
func convertIngressRuleToUFW(rule v1.FirewallRule) []string {
cmds := []string{}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const (
ufwDefaultAllowPort2222 = "ufw allow 2222/tcp"
ufwForceEnable = "ufw --force enable"

//
ipTablesAllowDockerUserInpboundLoopback = "iptables -I DOCKER-USER -i lo -j ACCEPT"
ipTablesAllowDockerUserOutbound = "iptables -I DOCKER-USER -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT"
ipTablesDropDockerUserInbound = "iptables -A DOCKER-USER -j DROP"
Expand Down
Loading