Skip to content

Commit d844c45

Browse files
authored
(e2e) fix default-deny-all in list of allowed policies for test (#2039)
Follow up to (2034)[#2034] When there is a dual namespace deployment, the default-deny-all policy is duplicated in both namespaces. This PR updates the list of `allowedPolicies` to include both policies if a dual namespace deployment is detected.
1 parent dffa0f6 commit d844c45

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

test/e2e/network_policy_test.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@ type allowedPolicyDefinition struct {
5656
denyAllEgressJustification string // Justification if Egress is in PolicyTypes and EgressRules is empty
5757
}
5858

59+
var denyAllPolicySpec = allowedPolicyDefinition{
60+
selector: metav1.LabelSelector{}, // Empty selector, matches all pods
61+
policyTypes: []networkingv1.PolicyType{networkingv1.PolicyTypeIngress, networkingv1.PolicyTypeEgress},
62+
// No IngressRules means deny all ingress if PolicyTypeIngress is present
63+
// No EgressRules means deny all egress if PolicyTypeEgress is present
64+
denyAllIngressJustification: "Denies all ingress traffic to pods selected by this policy by default, unless explicitly allowed by other policy rules, ensuring a baseline secure posture.",
65+
denyAllEgressJustification: "Denies all egress traffic from pods selected by this policy by default, unless explicitly allowed by other policy rules, minimizing potential exfiltration paths.",
66+
}
67+
5968
// Ref: https://docs.google.com/document/d/1bHEEWzA65u-kjJFQRUY1iBuMIIM1HbPy4MeDLX4NI3o/edit?usp=sharing
6069
var allowedNetworkPolicies = map[string]allowedPolicyDefinition{
6170
"catalogd-controller-manager": {
@@ -106,14 +115,6 @@ var allowedNetworkPolicies = map[string]allowedPolicyDefinition{
106115
},
107116
},
108117
},
109-
"default-deny-all-traffic": {
110-
selector: metav1.LabelSelector{}, // Empty selector, matches all pods
111-
policyTypes: []networkingv1.PolicyType{networkingv1.PolicyTypeIngress, networkingv1.PolicyTypeEgress},
112-
// No IngressRules means deny all ingress if PolicyTypeIngress is present
113-
// No EgressRules means deny all egress if PolicyTypeEgress is present
114-
denyAllIngressJustification: "Denies all ingress traffic to pods selected by this policy by default, unless explicitly allowed by other policy rules, ensuring a baseline secure posture.",
115-
denyAllEgressJustification: "Denies all egress traffic from pods selected by this policy by default, unless explicitly allowed by other policy rules, minimizing potential exfiltration paths.",
116-
},
117118
}
118119

119120
func TestNetworkPolicyJustifications(t *testing.T) {
@@ -155,6 +156,13 @@ func TestNetworkPolicyJustifications(t *testing.T) {
155156
err := c.List(ctx, policies, client.InNamespace(catalogDNamespace))
156157
require.NoError(t, err, "Failed to list NetworkPolicies in namespace %q", catalogDNamespace)
157158
clusterPolicies = append(clusterPolicies, policies.Items...)
159+
160+
t.Log("Detected dual-namespace configuration, expecting two prefixed 'default-deny-all-traffic' policies.")
161+
allowedNetworkPolicies["catalogd-default-deny-all-traffic"] = denyAllPolicySpec
162+
allowedNetworkPolicies["operator-controller-default-deny-all-traffic"] = denyAllPolicySpec
163+
} else {
164+
t.Log("Detected single-namespace configuration, expecting one 'default-deny-all-traffic' policy.")
165+
allowedNetworkPolicies["default-deny-all-traffic"] = denyAllPolicySpec
158166
}
159167

160168
validatedRegistryPolicies := make(map[string]bool)

0 commit comments

Comments
 (0)