|
|
|
|
@ -865,6 +865,81 @@ func TestUserFirewallReplacesOnlyPlatformPassRulesAndKeepsAntiSpoof(t *testing.T
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestFirewallLegacyIngressDefaultIsRejectedAndRebuilt(t *testing.T) {
|
|
|
|
|
const name = "virt-test"
|
|
|
|
|
platformPolicy := testPlatformPolicy()
|
|
|
|
|
base, err := BuildPlatformFilterXML(name, dualStackPublicNetwork(), platformPolicy)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
policy, err := validateFirewallPolicy(FirewallPolicy{
|
|
|
|
|
Revision: 1, DefaultIn: "drop", DefaultOut: "accept",
|
|
|
|
|
Rules: []FirewallRule{{
|
|
|
|
|
Direction: "ingress", Action: "accept", Protocol: "tcp",
|
|
|
|
|
CIDR: "203.0.113.0/24", PortFrom: 22, PortTo: 22,
|
|
|
|
|
}},
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
document, err := buildUserFirewallXML(base, policy)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
if !managedFilterSemanticsValid(document, name, platformPolicy) {
|
|
|
|
|
t.Fatal("valid split-default firewall was rejected")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var mixed libvirtxml.NWFilter
|
|
|
|
|
if err := mixed.Unmarshal(document); err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
for _, entry := range mixed.Entries {
|
|
|
|
|
if nwfilterRuleComment(entry.Rule) == "virt-default:in:ipv6" {
|
|
|
|
|
entry.Rule.Action = "accept"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
mixedDocument, err := mixed.Marshal()
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
if managedFilterSemanticsValid(mixedDocument, name, platformPolicy) {
|
|
|
|
|
t.Fatal("mixed IPv4/IPv6 ingress defaults were accepted")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var legacy libvirtxml.NWFilter
|
|
|
|
|
if err := legacy.Unmarshal(document); err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
entries := make([]libvirtxml.NWFilterEntry, 0, len(legacy.Entries)-1)
|
|
|
|
|
for _, entry := range legacy.Entries {
|
|
|
|
|
comment := nwfilterRuleComment(entry.Rule)
|
|
|
|
|
if comment == "virt-default:in:ipv4" || comment == "virt-default:in:ipv6" {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
entries = append(entries, entry)
|
|
|
|
|
}
|
|
|
|
|
entries = append(entries, libvirtxml.NWFilterEntry{Rule: &libvirtxml.NWFilterRule{
|
|
|
|
|
Action: "drop", Direction: "in", Priority: 800,
|
|
|
|
|
All: &libvirtxml.NWFilterRuleAll{Comment: "virt-default:in"},
|
|
|
|
|
}})
|
|
|
|
|
legacy.Entries = entries
|
|
|
|
|
legacyDocument, err := legacy.Marshal()
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
if managedFilterSemanticsValid(legacyDocument, name, platformPolicy) {
|
|
|
|
|
t.Fatal("legacy family-ambiguous ingress default was accepted")
|
|
|
|
|
}
|
|
|
|
|
rebuilt, err := buildUserFirewallXML(legacyDocument, policy)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
if rebuilt == legacyDocument || !managedFilterSemanticsValid(rebuilt, name, platformPolicy) {
|
|
|
|
|
t.Fatal("reapplying the stored policy did not rebuild the legacy firewall")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestRemoteImportAddressPolicyBlocksLocalNetworks(t *testing.T) {
|
|
|
|
|
for _, raw := range []string{
|
|
|
|
|
"127.0.0.1", "10.0.0.1", "169.254.1.1", "100.64.0.1",
|
|
|
|
|
|