generated from finos/standards-project-blueprint
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
finalizing auto responsive control for behave testing
- Loading branch information
1 parent
6c78958
commit 01c34d3
Showing
6 changed files
with
118 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,27 +11,42 @@ resource "google_storage_bucket" "malicious_storage_bucket" { | |
} | ||
|
||
uniform_bucket_level_access = true | ||
} | ||
|
||
data "google_iam_policy" "policy" { | ||
binding { | ||
role = "roles/storage.objectCreator" | ||
members = ["user:*"] | ||
condition { | ||
title = "Deny unencrypted uploads" | ||
description = "Only allow objects to be uploaded with a specific KMS key" | ||
expression = "resource.name.startsWith(\"projects/common-cloud-controls-testing/buckets/${google_storage_bucket.malicious_storage_bucket.name}/objects\") && !request.resource.labels.kms_key_name.startsWith(\"projects/common-cloud-controls-testing/locations/us-central1/keyRings/${google_kms_key_ring.keyring.id}/cryptoKeys/${google_kms_crypto_key.trusted_cmek.name}\")" | ||
} | ||
} | ||
depends_on = [ google_kms_crypto_key_iam_binding.trusted_kms_key_binding ] | ||
} | ||
|
||
resource "google_storage_bucket_iam_policy" "name" { | ||
data "archive_file" "my_function_src" { | ||
type = "zip" | ||
source_dir = "${path.module}/src" | ||
output_file_mode = "0666" | ||
output_path = "${path.module}/example_src.zip" | ||
} | ||
resource "google_storage_bucket_object" "src" { | ||
name = "example_src_${data.archive_file.my_function_src.output_md5}.zip" | ||
bucket = google_storage_bucket.malicious_storage_bucket.name | ||
policy_data = data.google_iam_policy.policy.policy_data | ||
source = data.archive_file.my_function_src.output_path | ||
} | ||
resource "google_cloudfunctions_function" "untrusted_enc_obj_deleter" { | ||
name = "${var.bucket_name}-ccc-os-c2-autorem-control" | ||
runtime = "python39" | ||
entry_point = "delete_object" | ||
source_archive_bucket = google_storage_bucket_object.src.bucket | ||
source_archive_object = google_storage_bucket_object.src.name | ||
|
||
event_trigger { | ||
event_type = "google.storage.object.finalize" | ||
resource = google_storage_bucket.malicious_storage_bucket.name | ||
} | ||
|
||
https_trigger_security_level = "SECURE_ALWAYS" | ||
} | ||
|
||
resource "random_string" "random" { | ||
length = 5 | ||
special = false | ||
} | ||
resource "google_kms_key_ring" "keyring" { | ||
name = "${var.bucket_name}-ccc-os-c2-keyring" | ||
name = "${var.bucket_name}-ccc-os-c2-kr-${random_string.random.id}" | ||
location = "us-central1" | ||
} | ||
|
||
|
@@ -45,6 +60,23 @@ resource "google_kms_crypto_key" "trusted_cmek" { | |
} | ||
} | ||
|
||
resource "google_kms_crypto_key_iam_binding" "trusted_kms_key_binding" { | ||
crypto_key_id = google_kms_crypto_key.trusted_cmek.id | ||
role = "roles/cloudkms.cryptoKeyEncrypterDecrypter" | ||
members = [ | ||
"serviceAccount:[email protected]" # Cloud Storage service account | ||
] | ||
} | ||
|
||
# Malicious Threat Actor adds a key binding for the untrusted CMEK to the Default Service Account | ||
resource "google_kms_crypto_key_iam_binding" "untrusted_kms_key_binding" { | ||
crypto_key_id = google_kms_crypto_key.untrusted_cmek.id | ||
role = "roles/cloudkms.cryptoKeyEncrypterDecrypter" | ||
members = [ | ||
"serviceAccount:[email protected]" # Cloud Storage service account | ||
] | ||
} | ||
|
||
resource "google_kms_crypto_key" "untrusted_cmek" { | ||
name = "${var.bucket_name}-untrusted-ccc-os-c2" | ||
key_ring = google_kms_key_ring.keyring.id | ||
|
33 changes: 33 additions & 0 deletions
33
src/control-catalog/terraform_modules/storage/object/ccc.os.c2/gcp/src/main.py
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,33 @@ | ||
import logging | ||
import functions_framework | ||
from google.cloud import storage | ||
|
||
logging.basicConfig(level=logging.INFO) | ||
|
||
@functions_framework.cloud_event | ||
def delete_object(event): | ||
logging.info("Function triggered: %s", event.data) | ||
|
||
bucket_name = event.data['bucket'] | ||
object_name = event.data['name'] | ||
kms_key_name = event.data['kmsKeyName'] | ||
|
||
# Initialize the client | ||
client = storage.Client() | ||
|
||
# Get the bucket | ||
bucket = client.get_bucket(bucket_name) | ||
|
||
# Get the object | ||
blob = bucket.blob(object_name) | ||
|
||
# Check if the object is not encrypted with the default CMEK | ||
# or if the object is not encrypted with a CMEK | ||
if bucket.default_kms_key_name not in kms_key_name: | ||
blob.delete() | ||
logging.info("Object %s deleted successfully.", object_name) | ||
return f"Object {object_name} deleted successfully.", 200 | ||
else: | ||
logging.info("Object %s is already encrypted with the default CMEK.", object_name) | ||
return f"Object {object_name} is already encrypted with the default CMEK.", 200 | ||
|
1 change: 1 addition & 0 deletions
1
src/control-catalog/terraform_modules/storage/object/ccc.os.c2/gcp/src/requirements.txt
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 @@ | ||
google-cloud-storage |