Skip to content

Commit 965eda3

Browse files
committed
libnet/d/overlay: insert the input-drop rule
FirewallD creates the root INPUT chain with a default-accept policy and a terminal rule which rejects all packets not accepted by any prior rule. Any subsequent rules appended to the chain are therefore inert. The administrator would have to open the VXLAN UDP port to make overlay networks work at all, which would result in all VXLAN traffic being accepted and defeating our attempts to enforce encryption on encrypted overlay networks. Insert the rule to drop unencrypted VXLAN packets tagged for encrypted overlay networks at the top of the INPUT chain so that enforcement of mandatory encryption takes precedence over any accept rules configured by the administrator. Continue to append the accept rule to the bottom of the chain so as not to override any administrator-configured drop rules. Signed-off-by: Cory Snider <[email protected]>
1 parent 105b983 commit 965eda3

1 file changed

Lines changed: 18 additions & 7 deletions

File tree

libnetwork/drivers/overlay/encryption.go

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -277,29 +277,40 @@ var programMangle = programVXLANRuleFunc(func(matchVXLAN matchVXLANFunc, vni uin
277277
var programInput = programVXLANRuleFunc(func(matchVXLAN matchVXLANFunc, vni uint32, add bool) error {
278278
var (
279279
plainVxlan = matchVXLAN(overlayutils.VXLANUDPPort(), vni)
280-
ipsecVxlan = append([]string{"-m", "policy", "--dir", "in", "--pol", "ipsec"}, plainVxlan...)
281-
block = append(plainVxlan, "-j", "DROP")
282-
accept = append(ipsecVxlan, "-j", "ACCEPT")
283280
chain = "INPUT"
284-
action = iptables.Append
285281
msg = "add"
286282
)
287283

284+
rule := func(policy, jump string) []string {
285+
args := append([]string{"-m", "policy", "--dir", "in", "--pol", policy}, plainVxlan...)
286+
return append(args, "-j", jump)
287+
}
288+
288289
// TODO IPv6 support
289290
iptable := iptables.GetIptable(iptables.IPv4)
290291

291292
if !add {
292-
action = iptables.Delete
293293
msg = "remove"
294294
}
295295

296+
action := func(a iptables.Action) iptables.Action {
297+
if !add {
298+
return iptables.Delete
299+
}
300+
return a
301+
}
302+
296303
// Accept incoming VXLAN datagrams for the VNI which were subjected to IPSec processing.
297-
if err := iptable.ProgramRule(iptables.Filter, chain, action, accept); err != nil {
304+
// Append to the bottom of the chain to give administrator-configured rules precedence.
305+
if err := iptable.ProgramRule(iptables.Filter, chain, action(iptables.Append), rule("ipsec", "ACCEPT")); err != nil {
298306
return fmt.Errorf("could not %s input accept rule: %w", msg, err)
299307
}
300308

301309
// Drop incoming VXLAN datagrams for the VNI which were received in cleartext.
302-
if err := iptable.ProgramRule(iptables.Filter, chain, action, block); err != nil {
310+
// Insert at the top of the chain so the packets are dropped even if an
311+
// administrator-configured rule exists which would otherwise unconditionally
312+
// accept incoming VXLAN traffic.
313+
if err := iptable.ProgramRule(iptables.Filter, chain, action(iptables.Insert), rule("none", "DROP")); err != nil {
303314
return fmt.Errorf("could not %s input drop rule: %w", msg, err)
304315
}
305316

0 commit comments

Comments
 (0)