Skip to content

Commit 2c731bd

Browse files
bradjcloudpossebot
andauthored
Adds flag and policy to require all buckets requests to be over SSL (#67)
* Adds flag and policy to require all buckets requests to be over SSL * Auto Format * Update policy SID to match feature flag Co-authored-by: cloudpossebot <[email protected]>
1 parent 6c6ad0f commit 2c731bd

File tree

4 files changed

+37
-1
lines changed

4 files changed

+37
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,14 @@ Available targets:
181181
| [aws_iam_policy_document.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
182182
| [aws_iam_policy_document.deployment](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
183183
| [aws_iam_policy_document.replication](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
184+
| [aws_partition.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/partition) | data source |
184185

185186
## Inputs
186187

187188
| Name | Description | Type | Default | Required |
188189
|------|-------------|------|---------|:--------:|
189190
| <a name="input_additional_tag_map"></a> [additional\_tag\_map](#input\_additional\_tag\_map) | Additional tags for appending to tags\_as\_list\_of\_maps. Not added to `tags`. | `map(string)` | `{}` | no |
191+
| <a name="input_allow_ssl_requests_only"></a> [allow\_ssl\_requests\_only](#input\_allow\_ssl\_requests\_only) | Set to `true` to require requests to use Secure Socket Layer (HTTPS/SSL). This will explicitly deny access to HTTP requests | `bool` | `false` | no |
190192
| <a name="input_attributes"></a> [attributes](#input\_attributes) | Additional attributes (e.g. `1`) | `list(string)` | `[]` | no |
191193
| <a name="input_context"></a> [context](#input\_context) | Single object for setting entire context at once.<br>See description of individual variables for details.<br>Leave string and numeric variables as `null` to use default value.<br>Individual variable settings (non-null) override settings in context object,<br>except for attributes, tags, and additional\_tag\_map, which are merged. | `any` | <pre>{<br> "additional_tag_map": {},<br> "attributes": [],<br> "delimiter": null,<br> "enabled": true,<br> "environment": null,<br> "id_length_limit": null,<br> "label_key_case": null,<br> "label_order": [],<br> "label_value_case": null,<br> "name": null,<br> "namespace": null,<br> "regex_replace_chars": null,<br> "stage": null,<br> "tags": {}<br>}</pre> | no |
192194
| <a name="input_cors_allowed_headers"></a> [cors\_allowed\_headers](#input\_cors\_allowed\_headers) | List of allowed headers | `list(string)` | <pre>[<br> "*"<br>]</pre> | no |

docs/terraform.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@
3131
| [aws_iam_policy_document.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
3232
| [aws_iam_policy_document.deployment](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
3333
| [aws_iam_policy_document.replication](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
34+
| [aws_partition.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/partition) | data source |
3435

3536
## Inputs
3637

3738
| Name | Description | Type | Default | Required |
3839
|------|-------------|------|---------|:--------:|
3940
| <a name="input_additional_tag_map"></a> [additional\_tag\_map](#input\_additional\_tag\_map) | Additional tags for appending to tags\_as\_list\_of\_maps. Not added to `tags`. | `map(string)` | `{}` | no |
41+
| <a name="input_allow_ssl_requests_only"></a> [allow\_ssl\_requests\_only](#input\_allow\_ssl\_requests\_only) | Set to `true` to require requests to use Secure Socket Layer (HTTPS/SSL). This will explicitly deny access to HTTP requests | `bool` | `false` | no |
4042
| <a name="input_attributes"></a> [attributes](#input\_attributes) | Additional attributes (e.g. `1`) | `list(string)` | `[]` | no |
4143
| <a name="input_context"></a> [context](#input\_context) | Single object for setting entire context at once.<br>See description of individual variables for details.<br>Leave string and numeric variables as `null` to use default value.<br>Individual variable settings (non-null) override settings in context object,<br>except for attributes, tags, and additional\_tag\_map, which are merged. | `any` | <pre>{<br> "additional_tag_map": {},<br> "attributes": [],<br> "delimiter": null,<br> "enabled": true,<br> "environment": null,<br> "id_length_limit": null,<br> "label_key_case": null,<br> "label_order": [],<br> "label_value_case": null,<br> "name": null,<br> "namespace": null,<br> "regex_replace_chars": null,<br> "stage": null,<br> "tags": {}<br>}</pre> | no |
4244
| <a name="input_cors_allowed_headers"></a> [cors\_allowed\_headers](#input\_cors\_allowed\_headers) | List of allowed headers | `list(string)` | <pre>[<br> "*"<br>]</pre> | no |

main.tf

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
locals {
2-
enabled = module.this.enabled
2+
enabled = module.this.enabled
3+
bucket_arn = "arn:${data.aws_partition.current.partition}:s3:::${join("", aws_s3_bucket.default.*.id)}"
4+
35
website_config = {
46
redirect_all = [
57
{
@@ -129,6 +131,28 @@ data "aws_iam_policy_document" "default" {
129131
}
130132
}
131133

134+
dynamic "statement" {
135+
for_each = var.allow_ssl_requests_only ? [1] : []
136+
137+
content {
138+
sid = "AllowSSLRequestsOnly"
139+
effect = "Deny"
140+
actions = ["s3:*"]
141+
resources = [local.bucket_arn, "${local.bucket_arn}/*"]
142+
143+
principals {
144+
identifiers = ["*"]
145+
type = "*"
146+
}
147+
148+
condition {
149+
test = "Bool"
150+
values = ["false"]
151+
variable = "aws:SecureTransport"
152+
}
153+
}
154+
}
155+
132156
# Support replication ARNs
133157
dynamic "statement" {
134158
for_each = flatten(data.aws_iam_policy_document.replication.*.statement)
@@ -253,6 +277,8 @@ data "aws_iam_policy_document" "deployment" {
253277
}
254278
}
255279

280+
data "aws_partition" "current" {}
281+
256282
module "dns" {
257283
source = "cloudposse/route53-alias/aws"
258284
version = "0.12.0"

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,10 @@ variable "encryption_enabled" {
151151
type = bool
152152
default = false
153153
description = "When set to 'true' the resource will have AES256 encryption enabled by default"
154+
}
155+
156+
variable "allow_ssl_requests_only" {
157+
type = bool
158+
default = false
159+
description = "Set to `true` to require requests to use Secure Socket Layer (HTTPS/SSL). This will explicitly deny access to HTTP requests"
154160
}

0 commit comments

Comments
 (0)