-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(checks): migrate Kubernetes network to Rego
Signed-off-by: Nikita Pivkin <[email protected]>
- Loading branch information
Showing
15 changed files
with
585 additions
and
281 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
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,38 @@ | ||
# METADATA | ||
# title: Public egress should not be allowed via network policies | ||
# description: You should not expose infrastructure to the public internet except where explicitly required | ||
# scope: package | ||
# schemas: | ||
# - input: schema["cloud"] | ||
# custom: | ||
# id: AVD-KUBE-0002 | ||
# avd_id: AVD-KUBE-0002 | ||
# provider: kubernetes | ||
# service: network | ||
# severity: HIGH | ||
# short_code: no-public-egress | ||
# recommended_action: Remove public access except where explicitly required | ||
# input: | ||
# selector: | ||
# - type: cloud | ||
# subtypes: | ||
# - provider: kubernetes | ||
# service: networkpolicies | ||
# terraform: | ||
# good_examples: checks/kubernetes/network/no_public_egress.yaml | ||
# links: | ||
# - https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/network_policy#spec.egress.to.ip_block.cidr | ||
package builtin.kube.network.kube0002 | ||
|
||
import rego.v1 | ||
|
||
deny contains res if { | ||
some policy in input.kubernetes.networkpolicies | ||
isManaged(policy) | ||
some dest in policy.spec.egress.destinationcidrs | ||
cidr.is_public(dest.value) | ||
res := result.new( | ||
"Network policy allows egress to the public internet.", | ||
dest, | ||
) | ||
} |
Oops, something went wrong.