File tree 15 files changed +585
-281
lines changed
avd_docs/kubernetes/network
checks/kubernetes/network
15 files changed +585
-281
lines changed Original file line number Diff line number Diff line change 2
2
Remove public access except where explicitly required
3
3
4
4
``` hcl
5
- resource "kubernetes_network_policy" "good_example" {
6
- metadata {
7
- name = "terraform-example-network-policy"
8
- namespace = "default"
9
- }
10
-
11
- spec {
12
- pod_selector {
13
- match_expressions {
14
- key = "name"
15
- operator = "In"
16
- values = ["webfront", "api"]
17
- }
18
- }
19
-
20
- ingress {
21
- ports {
22
- port = "http"
23
- protocol = "TCP"
24
- }
25
- ports {
26
- port = "8125"
27
- protocol = "UDP"
28
- }
29
-
30
- from {
31
- ip_block {
32
- cidr = "10.0.0.0/16"
33
- except = [
34
- "10.0.0.0/24",
35
- "10.0.1.0/24",
36
- ]
37
- }
38
- }
39
- }
40
-
41
- egress {
42
- ports {
43
- port = "http"
44
- protocol = "TCP"
45
- }
46
- ports {
47
- port = "8125"
48
- protocol = "UDP"
49
- }
50
-
51
- to {
52
- ip_block {
53
- cidr = "0.0.0.0/0"
54
- except = [
55
- "10.0.0.0/24",
56
- "10.0.1.0/24",
57
- ]
58
- }
59
- }
60
- }
61
-
62
- policy_types = ["Ingress", "Egress"]
63
- }
64
- }
65
-
5
+ resource "kubernetes_network_policy" "good_example" {
6
+ metadata {
7
+ name = "terraform-example-network-policy"
8
+ namespace = "default"
9
+ }
10
+
11
+ spec {
12
+ pod_selector {
13
+ match_expressions {
14
+ key = "name"
15
+ operator = "In"
16
+ values = ["webfront", "api"]
17
+ }
18
+ }
19
+
20
+ ingress {
21
+ ports {
22
+ port = "http"
23
+ protocol = "TCP"
24
+ }
25
+ ports {
26
+ port = "8125"
27
+ protocol = "UDP"
28
+ }
29
+
30
+ from {
31
+ ip_block {
32
+ cidr = "10.0.0.0/16"
33
+ except = [
34
+ "10.0.0.0/24",
35
+ "10.0.1.0/24",
36
+ ]
37
+ }
38
+ }
39
+ }
40
+
41
+ egress {
42
+ ports {
43
+ port = "http"
44
+ protocol = "TCP"
45
+ }
46
+ ports {
47
+ port = "8125"
48
+ protocol = "UDP"
49
+ }
50
+
51
+ to {
52
+ ip_block {
53
+ cidr = "0.0.0.0/0"
54
+ except = [
55
+ "10.0.0.0/24",
56
+ "10.0.1.0/24",
57
+ ]
58
+ }
59
+ }
60
+ }
61
+
62
+ policy_types = ["Ingress", "Egress"]
63
+ }
64
+ }
66
65
```
67
66
68
67
#### Remediation Links
Original file line number Diff line number Diff line change 2
2
You should not expose infrastructure to the public internet except where explicitly required
3
3
4
4
### Impact
5
- Exposure of infrastructure to the public internet
5
+ <!-- Add Impact here -->
6
6
7
7
<!-- DO NOT CHANGE -->
8
8
{{ remediationActions }}
Original file line number Diff line number Diff line change 2
2
Remove public access except where explicitly required
3
3
4
4
``` hcl
5
- resource "kubernetes_network_policy" "good_example" {
6
- metadata {
7
- name = "terraform-example-network-policy"
8
- namespace = "default"
9
- }
10
-
11
- spec {
12
- pod_selector {
13
- match_expressions {
14
- key = "name"
15
- operator = "In"
16
- values = ["webfront", "api"]
17
- }
18
- }
19
-
20
- egress {
21
- ports {
22
- port = "http"
23
- protocol = "TCP"
24
- }
25
- ports {
26
- port = "8125"
27
- protocol = "UDP"
28
- }
29
-
30
- to {
31
- ip_block {
32
- cidr = "10.0.0.0/16"
33
- except = [
34
- "10.0.0.0/24",
35
- "10.0.1.0/24",
36
- ]
37
- }
38
- }
39
- }
40
-
41
- ingress {
42
- ports {
43
- port = "http"
44
- protocol = "TCP"
45
- }
46
- ports {
47
- port = "8125"
48
- protocol = "UDP"
49
- }
50
-
51
- from {
52
- ip_block {
53
- cidr = "10.0.0.0/16"
54
- except = [
55
- "10.0.0.0/24",
56
- "10.0.1.0/24",
57
- ]
58
- }
59
- }
60
- }
61
-
62
- policy_types = ["Ingress", "Egress"]
63
- }
64
- }
65
-
5
+ resource "kubernetes_network_policy" "good_example" {
6
+ metadata {
7
+ name = "terraform-example-network-policy"
8
+ namespace = "default"
9
+ }
10
+
11
+ spec {
12
+ pod_selector {
13
+ match_expressions {
14
+ key = "name"
15
+ operator = "In"
16
+ values = ["webfront", "api"]
17
+ }
18
+ }
19
+
20
+ egress {
21
+ ports {
22
+ port = "http"
23
+ protocol = "TCP"
24
+ }
25
+ ports {
26
+ port = "8125"
27
+ protocol = "UDP"
28
+ }
29
+
30
+ to {
31
+ ip_block {
32
+ cidr = "10.0.0.0/16"
33
+ except = [
34
+ "10.0.0.0/24",
35
+ "10.0.1.0/24",
36
+ ]
37
+ }
38
+ }
39
+ }
40
+
41
+ ingress {
42
+ ports {
43
+ port = "http"
44
+ protocol = "TCP"
45
+ }
46
+ ports {
47
+ port = "8125"
48
+ protocol = "UDP"
49
+ }
50
+
51
+ from {
52
+ ip_block {
53
+ cidr = "10.0.0.0/16"
54
+ except = [
55
+ "10.0.0.0/24",
56
+ "10.0.1.0/24",
57
+ ]
58
+ }
59
+ }
60
+ }
61
+
62
+ policy_types = ["Ingress", "Egress"]
63
+ }
64
+ }
66
65
```
67
66
68
67
#### Remediation Links
69
- - https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/network_policy#spec.ingress.from .ip_block.cidr
68
+ - https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/network_policy#spec.egress.to .ip_block.cidr
70
69
Original file line number Diff line number Diff line change 2
2
You should not expose infrastructure to the public internet except where explicitly required
3
3
4
4
### Impact
5
- Exfiltration of data to the public internet
5
+ <!-- Add Impact here -->
6
6
7
7
<!-- DO NOT CHANGE -->
8
8
{{ remediationActions }}
Original file line number Diff line number Diff line change @@ -26,7 +26,8 @@ var CheckNoPublicEgress = rules.Register(
26
26
Links : terraformNoPublicEgressLinks ,
27
27
RemediationMarkdown : terraformNoPublicEgressRemediationMarkdown ,
28
28
},
29
- Severity : severity .High ,
29
+ Severity : severity .High ,
30
+ Deprecated : true ,
30
31
},
31
32
func (s * state.State ) (results scan.Results ) {
32
33
for _ , policy := range s .Kubernetes .NetworkPolicies {
Original file line number Diff line number Diff line change
1
+ # METADATA
2
+ # title: Public egress should not be allowed via network policies
3
+ # description: You should not expose infrastructure to the public internet except where explicitly required
4
+ # scope: package
5
+ # schemas:
6
+ # - input: schema["cloud"]
7
+ # custom:
8
+ # id: AVD-KUBE-0002
9
+ # avd_id: AVD-KUBE-0002
10
+ # provider: kubernetes
11
+ # service: network
12
+ # severity: HIGH
13
+ # short_code: no-public-egress
14
+ # recommended_action: Remove public access except where explicitly required
15
+ # input:
16
+ # selector:
17
+ # - type: cloud
18
+ # subtypes:
19
+ # - provider: kubernetes
20
+ # service: networkpolicies
21
+ # terraform:
22
+ # good_examples: checks/kubernetes/network/no_public_egress.yaml
23
+ # links:
24
+ # - https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/network_policy#spec.egress.to.ip_block.cidr
25
+ package builtin.kube.network.kube0002
26
+
27
+ import rego.v1
28
+
29
+ deny contains res if {
30
+ some policy in input.kubernetes.networkpolicies
31
+ isManaged (policy)
32
+ some dest in policy.spec.egress.destinationcidrs
33
+ cidr.is_public (dest.value)
34
+ res := result.new (
35
+ " Network policy allows egress to the public internet." ,
36
+ dest,
37
+ )
38
+ }
You can’t perform that action at this time.
0 commit comments