forked from elastic/csp-security-policies
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
250 additions
and
4 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,118 @@ | ||
metadata: | ||
id: a4b61e0e-b0ca-53c5-a744-4587c57e0f2d | ||
name: Ensure That Cloud Audit Logging Is Configured Properly | ||
profile_applicability: '* Level 1' | ||
description: |- | ||
It is recommended that Cloud Audit Logging is configured to track all admin activities and read, write access to user data. | ||
rationale: |- | ||
Cloud Audit Logging maintains two audit logs for each project, folder, and organization: Admin Activity and Data Access. | ||
1. Admin Activity logs contain log entries for API calls or other administrative actions that modify the configuration or metadata of resources. Admin Activity audit logs are enabled for all services and cannot be configured. | ||
2. Data Access audit logs record API calls that create, modify, or read user-provided data. These are disabled by default and should be enabled. | ||
There are three kinds of Data Access audit log information: | ||
- Admin read: Records operations that read metadata or configuration information. | ||
Admin Activity audit logs record writes of metadata and configuration information that cannot be disabled. | ||
- Data read: Records operations that read user-provided data. | ||
- Data write: Records operations that write user-provided data. | ||
It is recommended to have an effective default audit config configured in such a way that: | ||
3. logtype is set to DATA_READ (to log user activity tracking) and DATA_WRITES (to log changes/tampering to user data). | ||
4. audit config is enabled for all the services supported by the Data Access audit logs feature. | ||
5. Logs should be captured for all users, i.e., there are no exempted users in any of the audit config sections. This will ensure overriding the audit config will not contradict the requirement. | ||
audit: |- | ||
**From Google Cloud Console** | ||
1. Go to `Audit Logs` by visiting [https://console.cloud.google.com/iam-admin/audit](https://console.cloud.google.com/iam-admin/audit). | ||
2. Ensure that Admin Read, Data Write, and Data Read are enabled for all Google Cloud services and that no exemptions are allowed. | ||
**From Google Cloud CLI** | ||
3. List the Identity and Access Management (IAM) policies for the project, folder, or organization: | ||
``` | ||
gcloud organizations get-iam-policy ORGANIZATION_ID | ||
gcloud resource-manager folders get-iam-policy FOLDER_ID | ||
gcloud projects get-iam-policy PROJECT_ID | ||
``` | ||
4. Policy should have a default auditConfigs section which has the logtype set to DATA_WRITES and DATA_READ for all services. Note that projects inherit settings from folders, which in turn inherit settings from the organization. When called, projects get-iam-policy, the result shows only the policies set in the project, not the policies inherited from the parent folder or organization. Nevertheless, if the parent folder has Cloud Audit Logging enabled, the project does as well. | ||
Sample output for default audit configs may look like this: | ||
``` | ||
auditConfigs: | ||
- auditLogConfigs: | ||
- logType: ADMIN_READ | ||
- logType: DATA_WRITE | ||
- logType: DATA_READ | ||
service: allServices | ||
``` | ||
5. Any of the auditConfigs sections should not have parameter "exemptedMembers:" set, which will ensure that Logging is enabled for all users and no user is exempted. | ||
remediation: |- | ||
**From Google Cloud Console** | ||
1. Go to `Audit Logs` by visiting [https://console.cloud.google.com/iam-admin/audit](https://console.cloud.google.com/iam-admin/audit). | ||
2. Follow the steps at [https://cloud.google.com/logging/docs/audit/configure-data-access](https://cloud.google.com/logging/docs/audit/configure-data-access) to enable audit logs for all Google Cloud services. Ensure that no exemptions are allowed. | ||
**From Google Cloud CLI** | ||
3. To read the project's IAM policy and store it in a file run a command: | ||
``` | ||
gcloud projects get-iam-policy PROJECT_ID > /tmp/project_policy.yaml | ||
``` | ||
Alternatively, the policy can be set at the organization or folder level. | ||
If setting the policy at the organization level, it is not necessary to also set it for each folder or project. | ||
``` | ||
gcloud organizations get-iam-policy ORGANIZATION_ID > /tmp/org_policy.yaml | ||
gcloud resource-manager folders get-iam-policy FOLDER_ID > /tmp/folder_policy.yaml | ||
``` | ||
4. Edit policy in /tmp/policy.yaml, adding or changing only the audit logs configuration to: | ||
**Note: Admin Activity Logs are enabled by default, and cannot be disabled. | ||
So they are not listed in these configuration changes.** | ||
``` | ||
auditConfigs: | ||
- auditLogConfigs: | ||
- logType: DATA_WRITE | ||
- logType: DATA_READ | ||
service: allServices | ||
``` | ||
**Note:** `exemptedMembers:` is not set as audit logging should be enabled for all the users | ||
5. To write new IAM policy run command: | ||
``` | ||
gcloud organizations set-iam-policy ORGANIZATION_ID /tmp/org_policy.yaml | ||
gcloud resource-manager folders set-iam-policy FOLDER_ID /tmp/folder_policy.yaml | ||
gcloud projects set-iam-policy PROJECT_ID /tmp/project_policy.yaml | ||
``` | ||
If the preceding command reports a conflict with another change, then repeat these steps, starting with the first step. | ||
impact: |- | ||
There is no charge for Admin Activity audit logs. | ||
Enabling the Data Access audit logs might result in your project being charged for the additional logs usage. | ||
default_value: '' | ||
references: |- | ||
1. https://cloud.google.com/logging/docs/audit/ | ||
2. https://cloud.google.com/logging/docs/audit/configure-data-access | ||
section: Logging and Monitoring | ||
version: '1.0' | ||
tags: | ||
- CIS | ||
- GCP | ||
- CIS 2.1 | ||
- Logging and Monitoring | ||
benchmark: | ||
name: CIS Google Cloud Platform Foundation | ||
version: v2.0.0 | ||
id: cis_gcp | ||
rule_number: '2.1' | ||
posture_type: cspm |
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 @@ | ||
package compliance.cis_gcp.rules.cis_2_1 | ||
|
||
import data.compliance.lib.common | ||
import data.compliance.policy.gcp.data_adapter | ||
import future.keywords.if | ||
import future.keywords.in | ||
|
||
finding = result if { | ||
data_adapter.is_policies_resource | ||
|
||
result := common.generate_result_without_expected( | ||
common.calculate_result(cloud_logging_is_configured), | ||
input.resource, | ||
) | ||
} | ||
|
||
cloud_logging_is_configured if { | ||
policy := input.resource[_].iam_policy | ||
has_read_write_logs(policy) | ||
not has_exempted_members(policy) | ||
} else = false | ||
|
||
has_read_write_logs(policy) if { | ||
log_types := {t | t = policy.audit_configs[i].audit_log_configs[j].log_type} | ||
1 in log_types # "ADMIN_READ" | ||
2 in log_types # "DATA_WRITE" | ||
3 in log_types # "DATA_READ" | ||
policy.audit_configs[_].service == "allServices" | ||
} else = false | ||
|
||
has_exempted_members(policy) if { | ||
configs := policy.audit_configs[_].audit_log_configs[_] | ||
count(configs.exempted_members) > 0 | ||
} else = false |
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,84 @@ | ||
package compliance.cis_gcp.rules.cis_2_1 | ||
|
||
import data.cis_gcp.test_data | ||
import data.compliance.policy.gcp.data_adapter | ||
import data.lib.test | ||
|
||
test_violation { | ||
# fail when no read/write logs are set for project/folder/org level | ||
eval_fail with input as test_data.generate_policies_asset([{}]) | ||
|
||
# fail when DATA_WRITE is missing from project | ||
eval_fail with input as test_data.generate_policies_asset([{"iam_policy": {"audit_configs": [{ | ||
"audit_log_configs": [{"log_type": 2}, {"log_type": 1}], | ||
"service": "allServices", | ||
}]}}]) | ||
|
||
# fail when DATA_READ is missing from project | ||
eval_fail with input as test_data.generate_policies_asset([{"iam_policy": {"audit_configs": [{ | ||
"audit_log_configs": [{"log_type": 3}, {"log_type": 1}], | ||
"service": "allServices", | ||
}]}}]) | ||
|
||
# fail when ADMIN_READ is missing from project | ||
eval_fail with input as test_data.generate_policies_asset([{"iam_policy": {"audit_configs": [{ | ||
"audit_log_configs": [{"log_type": 3}, {"log_type": 2}], | ||
"service": "allServices", | ||
}]}}]) | ||
|
||
# fail when extempted members is not empty | ||
eval_fail with input as test_data.generate_policies_asset([{"iam_policy": {"audit_configs": [{ | ||
"audit_log_configs": [ | ||
{ | ||
"log_type": 3, | ||
"exempted_members": ["user:a"], | ||
}, | ||
{"log_type": 2}, {"log_type": 1}, | ||
], | ||
"service": "allServices", | ||
}]}}]) | ||
|
||
# fail when "service": "allServices" is missing from project | ||
eval_fail with input as test_data.generate_policies_asset([{"iam_policy": {"audit_configs": [{"audit_log_configs": [{"log_type": 3}, {"log_type": 2}, {"log_type": 1}]}]}}]) | ||
|
||
# fail when DATA_READ and DATA_WRITE aren't set on the same policy | ||
eval_fail with input as test_data.generate_policies_asset([ | ||
{"iam_policy": {"audit_configs": [{ | ||
"audit_log_configs": [{"log_type": 3}, {"log_type": 1}], | ||
"service": "allServices", | ||
}]}}, | ||
{"iam_policy": {"audit_configs": [{ | ||
"audit_log_configs": [{"log_type": 2}, {"log_type": 1}], | ||
"service": "allServices", | ||
}]}}, | ||
]) | ||
} | ||
|
||
test_pass { | ||
# passes when project has DATA_READ/DATA_WRITE/ADMIN_READ | ||
# for all services, and with no exempted members | ||
eval_pass with input as test_data.generate_policies_asset([{"iam_policy": {"audit_configs": [{ | ||
"audit_log_configs": [ | ||
{"log_type": 1}, | ||
{"log_type": 2}, | ||
{"log_type": 3}, | ||
], | ||
"service": "allServices", | ||
}]}}]) | ||
} | ||
|
||
test_not_evaluated { | ||
not_eval with input as test_data.not_eval_resource | ||
} | ||
|
||
eval_fail { | ||
test.assert_fail(finding) with data.benchmark_data_adapter as data_adapter | ||
} | ||
|
||
eval_pass { | ||
test.assert_pass(finding) with data.benchmark_data_adapter as data_adapter | ||
} | ||
|
||
not_eval { | ||
not finding with data.benchmark_data_adapter as data_adapter | ||
} |
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