-
Notifications
You must be signed in to change notification settings - Fork 192
/
client_egress_to_cidr_deny.go
31 lines (27 loc) · 1.23 KB
/
client_egress_to_cidr_deny.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// SPDX-License-Identifier: Apache-2.0
// Copyright Authors of Cilium
package builder
import (
"github.com/cilium/cilium-cli/connectivity/check"
"github.com/cilium/cilium-cli/connectivity/tests"
"github.com/cilium/cilium-cli/utils/features"
)
type clientEgressToCidrDeny struct{}
func (t clientEgressToCidrDeny) build(ct *check.ConnectivityTest, templates map[string]string) {
// This policy denies L3 traffic to ExternalCIDR except ExternalIP/32
newTest("client-egress-to-cidr-deny", ct).
WithCiliumPolicy(allowAllEgressPolicyYAML). // Allow all egress traffic
WithCiliumPolicy(templates["clientEgressToCIDRExternalDenyPolicyYAML"]).
WithScenarios(
tests.PodToCIDR(tests.WithRetryDestIP(ct.Params().ExternalIP)), // Denies all traffic to ExternalOtherIP, but allow ExternalIP
).
WithExpectations(func(a *check.Action) (egress, ingress check.Result) {
if a.Destination().Address(features.GetIPFamily(ct.Params().ExternalOtherIP)) == ct.Params().ExternalOtherIP {
return check.ResultPolicyDenyEgressDrop, check.ResultNone
}
if a.Destination().Address(features.GetIPFamily(ct.Params().ExternalIP)) == ct.Params().ExternalIP {
return check.ResultOK, check.ResultNone
}
return check.ResultDrop, check.ResultDrop
})
}