-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Connectivity test factory component.
Signed-off-by: viktor-kurchenko <[email protected]>
- Loading branch information
1 parent
bd9ac69
commit 1e7938f
Showing
139 changed files
with
2,780 additions
and
1,255 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright Authors of Cilium | ||
|
||
package factory | ||
|
||
import ( | ||
_ "embed" | ||
|
||
"github.com/cilium/cilium-cli/connectivity/check" | ||
"github.com/cilium/cilium-cli/connectivity/tests" | ||
) | ||
|
||
var ( | ||
//go:embed manifests/deny-all-egress.yaml | ||
denyAllEgressPolicyYAML string | ||
|
||
allEgressDeny = factory{ | ||
name: "all-egress-deny", | ||
build: func(name string, ct *check.ConnectivityTest, _ map[string]string) { | ||
// This policy denies all egresses by default | ||
test := check.NewTest(name, ct.Params().Verbose, ct.Params().Debug) | ||
ct.AddTest(test). | ||
WithCiliumPolicy(denyAllEgressPolicyYAML). | ||
WithScenarios( | ||
tests.PodToPod(), | ||
tests.PodToPodWithEndpoints(), | ||
). | ||
WithExpectations(func(_ *check.Action) (egress, ingress check.Result) { | ||
return check.ResultDefaultDenyEgressDrop, check.ResultNone | ||
}) | ||
}, | ||
condition: runAlways, | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright Authors of Cilium | ||
|
||
package factory | ||
|
||
import ( | ||
_ "embed" | ||
|
||
"github.com/cilium/cilium-cli/connectivity/check" | ||
"github.com/cilium/cilium-cli/connectivity/tests" | ||
) | ||
|
||
var ( | ||
//go:embed manifests/deny-all-egress-knp.yaml | ||
denyAllEgressPolicyKNPYAML string | ||
|
||
allEgressDenyKnp = factory{ | ||
name: "all-egress-deny-knp", | ||
build: func(name string, ct *check.ConnectivityTest, _ map[string]string) { | ||
// This policy denies all egresses by default using KNP. | ||
test := check.NewTest(name, ct.Params().Verbose, ct.Params().Debug) | ||
ct.AddTest(test). | ||
WithK8SPolicy(denyAllEgressPolicyKNPYAML). | ||
WithScenarios( | ||
tests.PodToPod(), | ||
tests.PodToPodWithEndpoints(), | ||
). | ||
WithExpectations(func(_ *check.Action) (egress, ingress check.Result) { | ||
return check.ResultDefaultDenyEgressDrop, check.ResultNone | ||
}) | ||
}, | ||
condition: runAlways, | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright Authors of Cilium | ||
|
||
package factory | ||
|
||
import ( | ||
_ "embed" | ||
|
||
"github.com/cilium/cilium-cli/connectivity/check" | ||
"github.com/cilium/cilium-cli/connectivity/tests" | ||
) | ||
|
||
var ( | ||
//go:embed manifests/deny-all-entities.yaml | ||
denyAllEntitiesPolicyYAML string | ||
|
||
allEntitiesDeny = factory{ | ||
name: "all-entities-deny", | ||
build: func(name string, ct *check.ConnectivityTest, _ map[string]string) { | ||
// This policy denies all entities by default | ||
test := check.NewTest(name, ct.Params().Verbose, ct.Params().Debug) | ||
ct.AddTest(test). | ||
WithCiliumPolicy(denyAllEntitiesPolicyYAML). | ||
WithScenarios( | ||
tests.PodToPod(), | ||
tests.PodToCIDR(), | ||
). | ||
WithExpectations(func(_ *check.Action) (egress, ingress check.Result) { | ||
return check.ResultPolicyDenyEgressDrop, check.ResultNone | ||
}) | ||
}, | ||
condition: runAlways, | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright Authors of Cilium | ||
|
||
package factory | ||
|
||
import ( | ||
"github.com/cilium/cilium-cli/connectivity/check" | ||
"github.com/cilium/cilium-cli/connectivity/tests" | ||
"github.com/cilium/cilium-cli/utils/features" | ||
) | ||
|
||
var allIngressDeny = factory{ | ||
name: "all-ingress-deny", | ||
build: func(name string, ct *check.ConnectivityTest, _ map[string]string) { | ||
// This policy denies all ingresses by default. | ||
// | ||
// 1. Pod to Pod fails because there is no egress policy (so egress traffic originating from a pod is allowed), | ||
// but then at the destination there is ingress policy that denies the traffic. | ||
// 2. Egress to world works because there is no egress policy (so egress traffic originating from a pod is allowed), | ||
// then when replies come back, they are considered as "replies" to the outbound connection. | ||
// so they are not subject to ingress policy. | ||
test := check.NewTest(name, ct.Params().Verbose, ct.Params().Debug) | ||
ct.AddTest(test). | ||
WithCiliumPolicy(denyAllIngressPolicyYAML). | ||
WithScenarios(tests.PodToPod(), tests.PodToCIDR(tests.WithRetryAll())). | ||
WithExpectations(func(a *check.Action) (egress, ingress check.Result) { | ||
if a.Destination().Address(features.GetIPFamily(ct.Params().ExternalOtherIP)) == ct.Params().ExternalOtherIP || | ||
a.Destination().Address(features.GetIPFamily(ct.Params().ExternalIP)) == ct.Params().ExternalIP { | ||
return check.ResultOK, check.ResultNone | ||
} | ||
return check.ResultDrop, check.ResultDefaultDenyIngressDrop | ||
}) | ||
}, | ||
condition: runAlways, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright Authors of Cilium | ||
|
||
package factory | ||
|
||
import ( | ||
"github.com/blang/semver/v4" | ||
|
||
"github.com/cilium/cilium-cli/connectivity/check" | ||
"github.com/cilium/cilium-cli/connectivity/tests" | ||
"github.com/cilium/cilium-cli/utils/features" | ||
) | ||
|
||
var allIngressDenyFromOutside = factory{ | ||
name: "all-ingress-deny-from-outside", | ||
build: func(name string, ct *check.ConnectivityTest, _ map[string]string) { | ||
test := check.NewTest(name, ct.Params().Verbose, ct.Params().Debug) | ||
ct.AddTest(test). | ||
WithCiliumPolicy(denyAllIngressPolicyYAML). | ||
WithFeatureRequirements(features.RequireEnabled(features.NodeWithoutCilium)). | ||
WithIPRoutesFromOutsideToPodCIDRs(). | ||
WithScenarios(tests.FromCIDRToPod()). | ||
WithExpectations(func(a *check.Action) (egress, ingress check.Result) { | ||
if a.Destination().Address(features.GetIPFamily(ct.Params().ExternalOtherIP)) == ct.Params().ExternalOtherIP || | ||
a.Destination().Address(features.GetIPFamily(ct.Params().ExternalIP)) == ct.Params().ExternalIP { | ||
return check.ResultOK, check.ResultNone | ||
} | ||
return check.ResultDrop, check.ResultDefaultDenyIngressDrop | ||
}) | ||
}, | ||
condition: func(_ semver.Version, params check.Parameters) bool { return params.IncludeUnsafeTests }, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright Authors of Cilium | ||
|
||
package factory | ||
|
||
import ( | ||
_ "embed" | ||
|
||
"github.com/cilium/cilium-cli/connectivity/check" | ||
"github.com/cilium/cilium-cli/connectivity/tests" | ||
"github.com/cilium/cilium-cli/utils/features" | ||
) | ||
|
||
var ( | ||
//go:embed manifests/deny-all-ingress-knp.yaml | ||
denyAllIngressPolicyKNPYAML string | ||
|
||
allIngressDenyKnp = factory{ | ||
name: "all-ingress-deny-knp", | ||
build: func(name string, ct *check.ConnectivityTest, _ map[string]string) { | ||
// This policy denies all ingresses by default | ||
test := check.NewTest(name, ct.Params().Verbose, ct.Params().Debug) | ||
ct.AddTest(test). | ||
WithK8SPolicy(denyAllIngressPolicyKNPYAML). | ||
WithScenarios( | ||
// Pod to Pod fails because there is no egress policy (so egress traffic originating from a pod is allowed), | ||
// but then at the destination there is ingress policy that denies the traffic. | ||
tests.PodToPod(), | ||
// Egress to world works because there is no egress policy (so egress traffic originating from a pod is allowed), | ||
// then when replies come back, they are considered as "replies" to the outbound connection. | ||
// so they are not subject to ingress policy. | ||
tests.PodToCIDR(tests.WithRetryAll()), | ||
). | ||
WithExpectations(func(a *check.Action) (egress, ingress check.Result) { | ||
if a.Destination().Address(features.GetIPFamily(ct.Params().ExternalOtherIP)) == ct.Params().ExternalOtherIP || | ||
a.Destination().Address(features.GetIPFamily(ct.Params().ExternalIP)) == ct.Params().ExternalIP { | ||
return check.ResultOK, check.ResultNone | ||
} | ||
return check.ResultDrop, check.ResultDefaultDenyIngressDrop | ||
}) | ||
}, | ||
condition: runAlways, | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright Authors of Cilium | ||
|
||
package factory | ||
|
||
import ( | ||
_ "embed" | ||
|
||
"github.com/cilium/cilium-cli/connectivity/check" | ||
"github.com/cilium/cilium-cli/connectivity/tests" | ||
) | ||
|
||
var ( | ||
//go:embed manifests/allow-all-except-world.yaml | ||
allowAllExceptWorldPolicyYAML string | ||
|
||
allowAllExceptWorld = factory{ | ||
name: "allow-all-except-world", | ||
build: func(name string, ct *check.ConnectivityTest, _ map[string]string) { | ||
// Test with an allow-all-except-world (and unmanaged) policy. | ||
test := check.NewTest(name, ct.Params().Verbose, ct.Params().Debug) | ||
ct.AddTest(test). | ||
WithCiliumPolicy(allowAllExceptWorldPolicyYAML). | ||
WithScenarios( | ||
tests.PodToPod(), | ||
tests.ClientToClient(), | ||
tests.PodToService(), | ||
// We are skipping the following checks because NodePort is | ||
// intended to be used for N-S traffic, which conflicts with | ||
// policies. See GH-17144. | ||
// tests.PodToRemoteNodePort(), | ||
// tests.PodToLocalNodePort(), | ||
tests.PodToHost(), | ||
tests.PodToExternalWorkload(), | ||
) | ||
}, | ||
condition: runAlways, | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright Authors of Cilium | ||
|
||
package factory | ||
|
||
import ( | ||
"github.com/cilium/cilium-cli/connectivity/check" | ||
"github.com/cilium/cilium-cli/connectivity/tests" | ||
) | ||
|
||
var allowAllWithMetricsCheck = factory{ | ||
name: "allow-all-with-metrics-check", | ||
build: func(name string, ct *check.ConnectivityTest, _ map[string]string) { | ||
// This policy allows traffic pod to pod and checks if the metric cilium_forward_count_total increases on cilium agent. | ||
test := check.NewTest(name, ct.Params().Verbose, ct.Params().Debug) | ||
ct.AddTest(test). | ||
WithScenarios(tests.PodToPod()). | ||
WithExpectations(func(_ *check.Action) (egress, ingress check.Result) { | ||
return check.ResultOK.ExpectMetricsIncrease(ct.CiliumAgentMetrics(), "cilium_forward_count_total"), | ||
check.ResultOK.ExpectMetricsIncrease(ct.CiliumAgentMetrics(), "cilium_forward_count_total") | ||
}) | ||
}, | ||
condition: runAlways, | ||
} |
Oops, something went wrong.