eleven / messenger Public

Clone
git clone https://amadan.net/eleven/messenger

Plain git — no account needed to clone.

Download

Download this file

1# 🤖 The two state buckets. Same posture for both: versioned, keep the last
2# 5 noncurrent versions (1-day linger is a lifecycle floor, not a cap), and
3# Block Public Access — the plan's "design as if public, configure as private"
4# line. Contents are client-side ciphertext either way.
5
6locals {
7 buckets = {
8 # Litestream replication targets, one prefix per instance host.
9 instances = "eleven-dev-instances-${local.account_id}"
10 # home's vault store (the s3Store backend, #550 Part 1).
11 home = "eleven-dev-home-${local.account_id}"
12 }
13}
14
15resource "aws_s3_bucket" "state" {
16 for_each = local.buckets
17 bucket = each.value
18}
19
20resource "aws_s3_bucket_versioning" "state" {
21 for_each = local.buckets
22 bucket = aws_s3_bucket.state[each.key].id
23
24 versioning_configuration {
25 status = "Enabled"
26 }
27}
28
29resource "aws_s3_bucket_lifecycle_configuration" "state" {
30 for_each = local.buckets
31 bucket = aws_s3_bucket.state[each.key].id
32
33 rule {
34 id = "keep-last-5-noncurrent"
35 status = "Enabled"
36
37 filter {}
38
39 noncurrent_version_expiration {
40 noncurrent_days = 1
41 newer_noncurrent_versions = 5
42 }
43 }
44}
45
46resource "aws_s3_bucket_public_access_block" "state" {
47 for_each = local.buckets
48 bucket = aws_s3_bucket.state[each.key].id
49
50 block_public_acls = true
51 block_public_policy = true
52 ignore_public_acls = true
53 restrict_public_buckets = true
54}
55
56# TLS-only: deny any request arriving over plain HTTP. Every client of these
57# buckets (Litestream, the AWS SDKs/CLI) already speaks HTTPS — this turns
58# that assumption into policy. A deny-only statement grants nothing public,
59# so it attaches fine under the full public-access block above.
60data "aws_iam_policy_document" "state_tls_only" {
61 for_each = local.buckets
62
63 statement {
64 sid = "DenyInsecureTransport"
65 effect = "Deny"
66 actions = ["s3:*"]
67 resources = [
68 aws_s3_bucket.state[each.key].arn,
69 "${aws_s3_bucket.state[each.key].arn}/*",
70 ]
71
72 principals {
73 type = "*"
74 identifiers = ["*"]
75 }
76
77 condition {
78 test = "Bool"
79 variable = "aws:SecureTransport"
80 values = ["false"]
81 }
82 }
83}
84
85resource "aws_s3_bucket_policy" "state_tls_only" {
86 for_each = local.buckets
87 bucket = aws_s3_bucket.state[each.key].id
88 policy = data.aws_iam_policy_document.state_tls_only[each.key].json
89}
90