Skip to content

Commit

Permalink
CFE-853: e2e test case for DNSNameResolver and EgressFirewall integra…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
bharath-b-rh committed May 15, 2024
1 parent 5f629ff commit 215dccb
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 10 deletions.
50 changes: 42 additions & 8 deletions test/extended/networking/egress_firewall.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ import (
const (
egressFWTestPod = "egressfirewall"
egressFWE2E = "egress-firewall-e2e"
wcEgressFWE2E = "wildcard-egress-firewall-e2e"
noEgressFWE2E = "no-egress-firewall-e2e"
egressFWTestImage = "registry.k8s.io/e2e-test-images/agnhost:2.47"
oVNKManifest = "ovnk-egressfirewall-test.yaml"
oVNKWCManifest = "ovnk-egressfirewall-wildcard-test.yaml"
openShiftSDNManifest = "sdn-egressnetworkpolicy-test.yaml"
)

Expand All @@ -37,18 +39,38 @@ var _ = g.Describe("[sig-network][Feature:EgressFirewall]", func() {
InOVNKubernetesContext(
func() {
g.It("should ensure egressfirewall is created", func() {
doEgressFwTest(egFwf, egFwoc, oVNKManifest, true)
doEgressFwTest(egFwf, egFwoc, oVNKManifest, true, false)
})
},
)
// For Openshift SDN its supports EgressNetworkPolicy objects
InOpenShiftSDNContext(
func() {
g.It("should ensure egressnetworkpolicy is created [apigroup:network.openshift.io]", func() {
doEgressFwTest(egFwf, egFwoc, openShiftSDNManifest, false)
doEgressFwTest(egFwf, egFwoc, openShiftSDNManifest, false, false)
})
},
)

// When OVNKubernetes subnet and coredns-ocp-dnsnameresolver plugins are enabled.
// coredns-ocp-dnsnameresolver plugin is a TechPreview feature.
// TODO:
// - Remove TechPreview check when feature is GA.
// - Merge oVNKManifest & oVNKWCManifest contents.
// - Update doEgressFwTest and sendEgressFwTraffic functions.
wcEgFwOc := exutil.NewCLIWithPodSecurityLevel(wcEgressFWE2E, admissionapi.LevelPrivileged)
wcEgFwF := wcEgFwOc.KubeFramework()
InOVNKubernetesContext(
func() {
g.It("should ensure egressfirewall with wildcard dns rules is created", func() {
if !exutil.IsTechPreviewNoUpgrade(wcEgFwOc) {
g.Skip("the test is not expected to work within Tech Preview disabled clusters")
}
doEgressFwTest(wcEgFwF, wcEgFwOc, oVNKWCManifest, true, true)
})
},
)

noegFwoc := exutil.NewCLIWithPodSecurityLevel(noEgressFWE2E, admissionapi.LevelBaseline)
noegFwf := noegFwoc.KubeFramework()
g.It("egressFirewall should have no impact outside its namespace", func() {
Expand Down Expand Up @@ -81,7 +103,7 @@ var _ = g.Describe("[sig-network][Feature:EgressFirewall]", func() {
})
})

func doEgressFwTest(f *e2e.Framework, oc *exutil.CLI, manifest string, nodeSelectorSupport bool) error {
func doEgressFwTest(f *e2e.Framework, oc *exutil.CLI, manifest string, nodeSelectorSupport, checkWildcard bool) error {
g.By("creating test pod")
o.Expect(createTestEgressFw(f, egressFWTestPod)).To(o.Succeed())

Expand All @@ -98,14 +120,14 @@ func doEgressFwTest(f *e2e.Framework, oc *exutil.CLI, manifest string, nodeSelec
err := oc.AsAdmin().Run("create").Args("-f", egFwYaml).Execute()
o.Expect(err).NotTo(o.HaveOccurred(), "created egress-firewall object")

o.Expect(sendEgressFwTraffic(f, oc, egressFWTestPod, nodeSelectorSupport)).To(o.Succeed())
o.Expect(sendEgressFwTraffic(f, oc, egressFWTestPod, nodeSelectorSupport, checkWildcard)).To(o.Succeed())

g.By("deleting test pod")
deleteTestEgressFw(f)
return err
}

func sendEgressFwTraffic(f *e2e.Framework, oc *exutil.CLI, pod string, nodeSelectorSupport bool) error {
func sendEgressFwTraffic(f *e2e.Framework, oc *exutil.CLI, pod string, nodeSelectorSupport, checkWildcard bool) error {
infra, err := oc.AdminConfigClient().ConfigV1().Infrastructures().Get(context.Background(), "cluster", metav1.GetOptions{})
o.Expect(err).NotTo(o.HaveOccurred(), "failed to get cluster-wide infrastructure")

Expand All @@ -128,10 +150,22 @@ func sendEgressFwTraffic(f *e2e.Framework, oc *exutil.CLI, pod string, nodeSelec
_, err = oc.Run("exec").Args(pod, "--", "curl", "-q", "-s", "-I", "-m3", "https://docs.openshift.com").Output()
expectNoError(err)

// Test curl to www.google.com:80 should fail
// because we don't have allow dns rule for www.google.com:80
if checkWildcard {
// Test curl to `www.google.com` and `translate.google.com` should pass
// because we have allow dns rule for `*.google.com`.
g.By("sending traffic to `www.google.com` that matches allow dns rule for `*.google.com`")
_, err = oc.Run("exec").Args(pod, "--", "curl", "-q", "-s", "-I", "-m3", "https://www.google.com").Output()
expectNoError(err)

g.By("sending traffic to `translate.google.com` that matches allow dns rule for `*.google.com`")
_, err = oc.Run("exec").Args(pod, "--", "curl", "-q", "-s", "-I", "-m3", "https://translate.google.com").Output()
expectNoError(err)
}

// Test curl to www.redhat.com should fail
// because we don't have allow dns rule for www.redhat.com
g.By("sending traffic that does not match allow dns rule")
_, err = oc.Run("exec").Args(pod, "--", "curl", "-q", "-s", "-I", "-m3", "http://www.google.com:80").Output()
_, err = oc.Run("exec").Args(pod, "--", "curl", "-q", "-s", "-I", "-m3", "http://www.redhat.com").Output()
expectError(err)

if nodeSelectorSupport {
Expand Down
47 changes: 45 additions & 2 deletions test/extended/testdata/bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: k8s.ovn.org/v1
kind: EgressFirewall
metadata:
name: default
spec:
egress:
- type: Allow
to:
dnsName: docs.openshift.com
- type: Allow
to:
dnsName: "*.google.com"
- type: Allow
to:
cidrSelector: 8.8.8.8/32
- type: Allow
to:
nodeSelector:
matchLabels:
node-role.kubernetes.io/control-plane: ''
- type: Deny
to:
cidrSelector: 0.0.0.0/0

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 215dccb

Please sign in to comment.