Skip to content

Commit

Permalink
Install packages before airgapping
Browse files Browse the repository at this point in the history
Installing ip6tables after disrupting IPv4 traffic will fail utterly if
the machine uses IPv4 for package installations. Install both packages
in lockstep before actually disrupting any traffic.

Fixes: e6bb827 ("Whitelist local IPv6 CIDRs when airgapping nodes")
Signed-off-by: Tom Wieczorek <twieczorek@mirantis.com>
  • Loading branch information
twz123 committed Jun 14, 2024
1 parent 56ce037 commit cab0882
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions inttest/common/airgap.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ localAddrs:

func (a *Airgap) airgapMachine(ctx context.Context, name, v4CIDRs, v6CIDRs string) error {
const airgapScript = `
apk add --no-cache %s
v4Cidrs='%s'
v6Cidrs='%s'
if [ -n "$v4Cidrs" ]; then
apk add --no-cache iptables
for cidr in $v4Cidrs; do
iptables -A INPUT -s $cidr -j ACCEPT
iptables -A OUTPUT -d $cidr -j ACCEPT
Expand All @@ -168,7 +168,6 @@ func (a *Airgap) airgapMachine(ctx context.Context, name, v4CIDRs, v6CIDRs strin
fi
if [ -n "$v6Cidrs" ]; then
apk add --no-cache ip6tables
for cidr in $v6Cidrs; do
ip6tables -A INPUT -s $cidr -j ACCEPT
ip6tables -A OUTPUT -d $cidr -j ACCEPT
Expand All @@ -183,6 +182,18 @@ func (a *Airgap) airgapMachine(ctx context.Context, name, v4CIDRs, v6CIDRs strin
fi
`

var packages []string
if v4CIDRs != "" {
packages = append(packages, "iptables")
}
if v6CIDRs != "" {
packages = append(packages, "ip6tables")
}

if len(packages) < 1 {
return nil
}

a.Logf("Airgapping %s", name)

ssh, err := a.SSH(ctx, name)
Expand All @@ -192,6 +203,6 @@ func (a *Airgap) airgapMachine(ctx context.Context, name, v4CIDRs, v6CIDRs strin
defer ssh.Disconnect()

return ssh.Exec(ctx, "sh -e -", SSHStreams{
In: strings.NewReader(fmt.Sprintf(airgapScript, v4CIDRs, v6CIDRs)),
In: strings.NewReader(fmt.Sprintf(airgapScript, strings.Join(packages, " "), v4CIDRs, v6CIDRs)),
})
}

0 comments on commit cab0882

Please sign in to comment.