forked from GoogleCloudPlatform/policy-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gcp_sql_allowed_authorized_networks_v1.yaml
118 lines (102 loc) · 4.65 KB
/
gcp_sql_allowed_authorized_networks_v1.yaml
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
apiVersion: templates.gatekeeper.sh/v1alpha1
kind: ConstraintTemplate
metadata:
name: gcp-sql-allowed-authorized-networks-v1
spec:
crd:
spec:
names:
kind: GCPSQLAllowedAuthorizedNetworksConstraintV1
validation:
openAPIV3Schema:
properties:
authorized_networks:
description: "Networks CIDR that can be used as authorized
networks for Cloud SQL instances. For example, 199.27.25.0/24.
The authorized networks specified in the instance need to
match the ones specified in this constraint. If no
authorized_networks are specified in the constraint, all
connections to instances need to be mediated by the
Cloud SQL Proxy."
type: array
items:
type: string
targets:
validation.gcp.forsetisecurity.org:
rego: | #INLINE("validator/sql_allowed_authorized_networks.rego")
#
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package templates.gcp.GCPSQLAllowedAuthorizedNetworksConstraintV1
import data.validator.gcp.lib as lib
deny[{
"msg": message,
"details": metadata,
}] {
constraint := input.constraint
lib.get_constraint_params(constraint, params)
asset := input.asset
asset.asset_type == "sqladmin.googleapis.com/Instance"
check_ssl(params, asset.resource.data.settings.ipConfiguration) == false
message := sprintf("%v has networks with SSL settings in violation of policy", [asset.name])
metadata := {"resource": asset.name}
}
deny[{
"msg": message,
"details": metadata,
}] {
constraint := input.constraint
lib.get_constraint_params(constraint, params)
asset := input.asset
asset.asset_type == "sqladmin.googleapis.com/Instance"
forbidden := forbidden_networks(params, asset.resource.data.settings.ipConfiguration)
count(forbidden) > 0
message := sprintf("%v has authorized networks that are not allowed: %v", [asset.name, forbidden])
metadata := {"resource": asset.name}
}
forbidden_networks(params, ipConfiguration) = forbidden {
allowed_authorized_networks = lib.get_default(params, "authorized_networks", [])
configured_networks := {network |
network = ipConfiguration.authorizedNetworks[_].value
}
matched_networks := {network |
network = configured_networks[_]
allowed_authorized_networks[_] == network
}
forbidden := configured_networks - matched_networks
}
check_ssl(params, ipConfiguration) = result {
lib.has_field(params, "ssl_enabled") == false
result = true
}
check_ssl(params, ipConfiguration) = result {
requireSsl := lib.get_default(ipConfiguration, "requireSsl", false)
result = requireSsl == params.ssl_enabled
}
#ENDINLINE