Skip to content

Commit 8044b6d

Browse files
feat(ingestion): Deny non-HTTPS traffic to S3 buckets (#8411)
Signed-off-by: germangarces <german.garces@flagsmith.com> Co-authored-by: flagsmith-engineering[bot] <flagsmith-engineering[bot]@users.noreply.github.com>
1 parent 07dbfd9 commit 8044b6d

3 files changed

Lines changed: 41 additions & 3 deletions

File tree

api/experimentation/ingestion_infra_service.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import json
34
import typing
45
from functools import lru_cache
56

@@ -121,6 +122,27 @@ def _create_events_bucket(bucket_name: str, *, organisation_id: int) -> None:
121122
"RestrictPublicBuckets": True,
122123
},
123124
)
125+
s3.put_bucket_policy(
126+
Bucket=bucket_name,
127+
Policy=json.dumps(
128+
{
129+
"Version": "2012-10-17",
130+
"Statement": [
131+
{
132+
"Sid": "AllowSSLRequestsOnly",
133+
"Effect": "Deny",
134+
"Principal": "*",
135+
"Action": "s3:*",
136+
"Resource": [
137+
f"arn:aws:s3:::{bucket_name}",
138+
f"arn:aws:s3:::{bucket_name}/*",
139+
],
140+
"Condition": {"Bool": {"aws:SecureTransport": "false"}},
141+
}
142+
],
143+
}
144+
),
145+
)
124146
s3.put_bucket_lifecycle_configuration(
125147
Bucket=bucket_name,
126148
LifecycleConfiguration={

api/tests/unit/experimentation/test_ingestion_infra_service.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import json
12
from collections.abc import Iterator
23
from typing import Any
34

@@ -92,6 +93,21 @@ def test_provision_ingestion_infrastructure__fresh_account__creates_bucket_and_s
9293
tagging = s3.get_bucket_tagging(Bucket=result.bucket_name)
9394
assert tagging["TagSet"] == [{"Key": "organisation_id", "Value": "42"}]
9495

96+
policy = json.loads(s3.get_bucket_policy(Bucket=result.bucket_name)["Policy"])
97+
assert policy["Statement"] == [
98+
{
99+
"Sid": "AllowSSLRequestsOnly",
100+
"Effect": "Deny",
101+
"Principal": "*",
102+
"Action": "s3:*",
103+
"Resource": [
104+
f"arn:aws:s3:::{result.bucket_name}",
105+
f"arn:aws:s3:::{result.bucket_name}/*",
106+
],
107+
"Condition": {"Bool": {"aws:SecureTransport": "false"}},
108+
}
109+
]
110+
95111
firehose = boto3.client("firehose", region_name="eu-west-2")
96112
stream = firehose.describe_delivery_stream(DeliveryStreamName=result.stream_name)[
97113
"DeliveryStreamDescription"

docs/docs/deployment-self-hosting/observability/_events-catalogue.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ Attributes:
207207
### `experimentation.ingestion_infra.bucket_created`
208208

209209
Logged at `info` from:
210-
- `api/experimentation/ingestion_infra_service.py:110`
210+
- `api/experimentation/ingestion_infra_service.py:111`
211211

212212
Attributes:
213213
- `bucket.name`
@@ -216,7 +216,7 @@ Attributes:
216216
### `experimentation.ingestion_infra.deprovisioned`
217217

218218
Logged at `info` from:
219-
- `api/experimentation/ingestion_infra_service.py:267`
219+
- `api/experimentation/ingestion_infra_service.py:289`
220220

221221
Attributes:
222222
- `bucket.name`
@@ -245,7 +245,7 @@ Attributes:
245245
### `experimentation.ingestion_infra.stream_created`
246246

247247
Logged at `info` from:
248-
- `api/experimentation/ingestion_infra_service.py:221`
248+
- `api/experimentation/ingestion_infra_service.py:243`
249249

250250
Attributes:
251251
- `bucket.name`

0 commit comments

Comments
 (0)