forked from GoogleCloudPlatform/policy-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gcp_iam_audit_log.yaml
119 lines (108 loc) · 4.64 KB
/
gcp_iam_audit_log.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
119
# Copyright 2019 Google Inc.
#
# 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.
#
# GCPIAMAuditLogConstraintV1 verifies that audig logging is enabled in the
# given services with the given log types.
apiVersion: templates.gatekeeper.sh/v1alpha1
kind: ConstraintTemplate
metadata:
name: gcp-iam-audit-log-v1
spec:
crd:
spec:
names:
kind: GCPIAMAuditLogConstraintV1
validation:
openAPIV3Schema:
properties:
services:
description: "The services that should have audit logging enabled.
Example: 'storage.googleapis.com' for Cloud Storage.
'allServices' is a special value that covers all services"
type: array
items:
type: string
log_types:
description: "The log types that should be enabled.
Valid values are ADMIN_READ, DATA_WRITE, and DATA_READ."
type: array
items:
type: string
allowed_exemptions:
description: "Allowed exemptions from the rule"
type: array
items:
type: string
targets:
validation.gcp.forsetisecurity.org:
rego: | #INLINE("validator/iam_audit_log.rego")
#
# 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.
#
package templates.gcp.GCPIAMAuditLogConstraintV1
import data.validator.gcp.lib as lib
deny[{
"msg": message,
"details": metadata,
}] {
asset_types := {
"cloudresourcemanager.googleapis.com/Organization",
"cloudresourcemanager.googleapis.com/Folder",
"cloudresourcemanager.googleapis.com/Project",
}
input.asset.asset_type == asset_types[_]
count(expected_audit_configs) == 0
lib.get_constraint_params(input.constraint, params)
message := sprintf("IAM policy for %v does not have correct audit logs enabled in service(s) %v", [input.asset.name, params.services])
metadata := {"resource": input.asset.name}
}
evaluate_allowed_exemptions(params, exempted_members) = result {
not params.allowed_exemptions
result = true
}
evaluate_allowed_exemptions(params, exempted_members) = result {
got_exemptions := {e | e = exempted_members[_]}
want_exemptions := {e | e = params.allowed_exemptions[_]}
unexpected_exemptions := got_exemptions - want_exemptions
result = count(unexpected_exemptions) == 0
}
expected_audit_configs[config] {
configs := lib.get_default(input.asset.iam_policy, "audit_configs", {})
config := configs[_]
lib.get_constraint_params(input.constraint, params)
config.service == params.services[_]
log_type_map := {
"ADMIN_READ": 1,
"DATA_WRITE": 2,
"DATA_READ": 3,
}
got_log_types := {t | t = config.audit_log_configs[_].log_type}
want_log_types := {t | t = log_type_map[params.log_types[_]]}
missing_log_types := want_log_types - got_log_types
count(missing_log_types) == 0
evaluate_allowed_exemptions(params, config.audit_log_configs[_].exempted_members)
}
#ENDINLINE