Skip to content

Commit e706d90

Browse files
authored
fix: Solve PCI.S3.5 and PCI.S3.4 (#149)
Fixes the following PCI issues: - [PCI.S3.5] This AWS control checks whether S3 buckets have policies that require requests to use Secure Socket Layer (SSL). - [PCI.S3.4] This AWS control checks that your Amazon S3 bucket either has Amazon S3 default encryption enabled or that the S3 bucket policy explicitly denies put-object requests without server side encryption.
1 parent e9f8d5a commit e706d90

File tree

5 files changed

+36
-8
lines changed

5 files changed

+36
-8
lines changed

.github/workflows/ci-pull-request.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ jobs:
7171
- name: Install pre-commit dependencies
7272
run: |
7373
pip install pre-commit
74-
go install github.com/hashicorp/terraform-config-inspect@latest
7574
make deps
7675
7776
- name: Execute generate-terraform-providers for organizational

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
deps:
22
go install github.com/terraform-docs/[email protected]
33
go install github.com/hashicorp/terraform-config-inspect@latest
4-
curl -L "`curl -s https://api.github.com/repos/terraform-linters/tflint/releases/latest | grep -o -E "https://.+?_linux_amd64.zip"`" -o tflint.zip && \
4+
curl -L https://github.com/terraform-linters/tflint/releases/download/v0.43.0/tflint_linux_amd64.zip -o tflint.zip && \
55
unzip tflint.zip && \
66
rm tflint.zip && \
77
mv tflint "`go env GOPATH`/bin"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ A: For Organizational Setup for cloudbench (deployed through management account
340340

341341
### Q-RuntimeThreat Detection: Getting error 403 `"could not load rule set from Sysdig Secure: ruleprovider#newPartialRuleSet | error loading default-rules: error from Sysdig Secure API: 403`
342342

343-
A: The Sysdig User that deployed the components is a standard user within the Sysdig Platform. Only administrator users are given permissions to read falco rule sets. Once this permission is changed, you should no longer get this error and CSPM Cloud events should start populating.
343+
A: The Sysdig User that deployed the components is a standard user within the Sysdig Platform. Only administrator users are given permissions to read falco rule sets. Once this permission is changed, you should no longer get this error and CSPM Cloud events should start populating.
344344

345345
<br/><br/>
346346

modules/infrastructure/cloudtrail/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ No modules.
3030
| [aws_s3_bucket_lifecycle_configuration.cloudtrail](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_lifecycle_configuration) | resource |
3131
| [aws_s3_bucket_policy.cloudtrail_s3](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_policy) | resource |
3232
| [aws_s3_bucket_public_access_block.cloudtrail](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_public_access_block) | resource |
33+
| [aws_s3_bucket_server_side_encryption_configuration.cloudtrail](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_server_side_encryption_configuration) | resource |
3334
| [aws_sns_topic.cloudtrail](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/sns_topic) | resource |
3435
| [aws_sns_topic_policy.allow_cloudtrail_publish](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/sns_topic_policy) | resource |
3536
| [aws_caller_identity.me](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |

modules/infrastructure/cloudtrail/s3.tf

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,17 @@ resource "aws_s3_bucket" "cloudtrail" {
1010
tags = var.tags
1111
}
1212

13+
resource "aws_s3_bucket_server_side_encryption_configuration" "cloudtrail" {
14+
bucket = aws_s3_bucket.cloudtrail.id
15+
rule {
16+
17+
apply_server_side_encryption_by_default {
18+
sse_algorithm = var.cloudtrail_kms_enable ? "aws:kms" : "AES256"
19+
kms_master_key_id = var.cloudtrail_kms_enable ? aws_kms_key.cloudtrail_kms[0].id : null
20+
}
21+
}
22+
}
23+
1324
resource "aws_s3_bucket_lifecycle_configuration" "cloudtrail" {
1425
bucket = aws_s3_bucket.cloudtrail.id
1526

@@ -39,18 +50,16 @@ resource "aws_s3_bucket_public_access_block" "cloudtrail" {
3950
block_public_policy = true
4051
ignore_public_acls = true
4152
restrict_public_buckets = true
42-
depends_on = [aws_s3_bucket_policy.cloudtrail_s3] # https://github.com/hashicorp/terraform-provider-aws/issues/7628
53+
depends_on = [aws_s3_bucket_policy.cloudtrail_s3]
54+
# https://github.com/hashicorp/terraform-provider-aws/issues/7628
4355
}
4456

4557

46-
4758
resource "aws_s3_bucket_policy" "cloudtrail_s3" {
4859
bucket = aws_s3_bucket.cloudtrail.id
4960
policy = data.aws_iam_policy_document.cloudtrail_s3.json
5061
}
5162
data "aws_iam_policy_document" "cloudtrail_s3" {
52-
53-
# begin. required policies as requested in aws_cloudtrail resource documentation
5463
statement {
5564
sid = "AWSCloudTrailAclCheck"
5665
effect = "Allow"
@@ -77,5 +86,24 @@ data "aws_iam_policy_document" "cloudtrail_s3" {
7786
}
7887
resources = ["${aws_s3_bucket.cloudtrail.arn}/AWSLogs/*"]
7988
}
80-
# end
89+
90+
# S3 buckets should require requests to use Secure Socket Layer
91+
# [PCI.S3.5] This AWS control checks whether S3 buckets have policies that require requests to use Secure Socket Layer (SSL).
92+
statement {
93+
principals {
94+
identifiers = ["*"]
95+
type = "AWS"
96+
}
97+
actions = ["s3:*"]
98+
resources = [
99+
aws_s3_bucket.cloudtrail.arn,
100+
"${aws_s3_bucket.cloudtrail.arn}/*"
101+
]
102+
effect = "Deny"
103+
condition {
104+
test = "Bool"
105+
variable = "aws:SecureTransport"
106+
values = ["false"]
107+
}
108+
}
81109
}

0 commit comments

Comments
 (0)