Skip to content

Commit

Permalink
adding changes for ccc_os_c3
Browse files Browse the repository at this point in the history
  • Loading branch information
damienjburks committed Apr 11, 2024
1 parent 9a92f7b commit 76402e4
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 5 deletions.
Empty file.
3 changes: 3 additions & 0 deletions src/control-catalog/behave_tests/behave.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[behave]
stderr_capture=False
stdout_capture=False
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Feature: (CCC.OS.C3) - Prevent the granting of direct public access to the object storage bucket you own

Scenario: Test Control CCC.OS.C3 - AWS
Scenario: Test Control CCC.OS.C3
GIVEN you own the object storage bucket in AWS
AND you own the object storage bucket in GCP
WHEN the access controls on the bucket are updated to grant public access to the AWS bucket
AND the access controls on the bucket are updated to grant public access to the GCP bucket
THEN the request should be denied
34 changes: 30 additions & 4 deletions src/control-catalog/behave_tests/ccc.os.c3/steps/ccc_os_c3.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import logging
import boto3
import time

from botocore.exceptions import ClientError
from google.api_core.exceptions import PreconditionFailed
from google.cloud import storage
from behave import given, then, when

Expand All @@ -12,15 +12,22 @@


@given("you own the object storage bucket in AWS")
def verify_aws_bucket_exists(context):
def aws_verify_bucket_exists(context):
context.s3_client = boto3.client("s3")
context.s3_client.get_bucket_acl(Bucket=STORAGE_BUCKET_NAME)


@given("you own the object storage bucket in GCP")
def gcp_verify_bucket_exists(context):
context.storage_client = storage.Client()
context.bucket = context.storage_client.bucket(STORAGE_BUCKET_NAME)
context.bucket.get_iam_policy()


@when(
"the access controls on the bucket are updated to grant public access to the AWS bucket"
)
def update_acls_on_bucket_to_allow_public_access(context):
def aws_update_acls_on_bucket_to_allow_public_access(context):
try:
context.s3_client.put_bucket_acl(
ACL="public-read-write", Bucket=STORAGE_BUCKET_NAME
Expand All @@ -29,9 +36,28 @@ def update_acls_on_bucket_to_allow_public_access(context):
context.s3_publish_error = str(err)


@when(
"the access controls on the bucket are updated to grant public access to the GCP bucket"
)
def gcp_update_acls_on_bucket_to_allow_public_access(context):
acl = storage.Bucket(context.storage_client, STORAGE_BUCKET_NAME).acl

# Attempting to modify ACL to allow all users public access
acl.all().grant_read()
acl.all().grant_write()

try:
acl.save()
except PreconditionFailed as err:
context.gcp_publish_error = str(err)


@then("the request should be denied")
def validate_request_denied(context):
if "AccessDenied" in context.s3_publish_error:
if (
"AccessDenied" in context.s3_publish_error
and "412 PATCH" in context.gcp_publish_error
):
assert True
else:
assert False
5 changes: 5 additions & 0 deletions src/control-catalog/terraform_modules/storage/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@ module "aws_storage_object_ccc_os_c2" {
module "aws_storage_object_ccc_os_c3" {
source = "./object/ccc.os.c3/aws"
bucket_name = var.bucket_name
}

module "gcp_storage_object_ccc_os_c3" {
source = "./object/ccc.os.c3/gcp"
bucket_name = var.bucket_name
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
resource "google_storage_bucket" "auto-expire" {
name = "${var.bucket_name}-ccc-os-c3"
location = "US"
force_destroy = true

public_access_prevention = "enforced" # Enabling public access

lifecycle {
ignore_changes = [ # Disabling public access to this
uniform_bucket_level_access
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
variable "bucket_name" {
type = string
description = "Bucket Name"
}

0 comments on commit 76402e4

Please sign in to comment.