eleven / ocho Public

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

Plain git — no account needed to clone.

Download

Download this file

1# 🤖 The fleet-backup bucket: Litestream on the router box streams every
2# instance DB (plus home/push/cloud/registry) here, one prefix per database.
3# Versioning is the ransomware posture — an overwrite or delete with the
4# box's credentials leaves noncurrent versions recoverable for 14 days, and
5# the box's IAM user (below) cannot touch versioning, lifecycle, or the
6# bucket itself.
7
8resource "aws_s3_bucket" "fleet_backup" {
9 bucket = "eleven-prod-fleet-backup-${local.account_id}"
10}
11
12resource "aws_s3_bucket_versioning" "fleet_backup" {
13 bucket = aws_s3_bucket.fleet_backup.id
14
15 versioning_configuration {
16 status = "Enabled"
17 }
18}
19
20resource "aws_s3_bucket_lifecycle_configuration" "fleet_backup" {
21 bucket = aws_s3_bucket.fleet_backup.id
22
23 rule {
24 id = "expire-noncurrent-14d"
25 status = "Enabled"
26
27 filter {}
28
29 noncurrent_version_expiration {
30 noncurrent_days = 14
31 }
32 }
33}
34
35resource "aws_s3_bucket_public_access_block" "fleet_backup" {
36 bucket = aws_s3_bucket.fleet_backup.id
37
38 block_public_acls = true
39 block_public_policy = true
40 ignore_public_acls = true
41 restrict_public_buckets = true
42}
43
44# TLS-only: deny any request arriving over plain HTTP. Litestream and the
45# vault sync both speak HTTPS already — this turns that assumption into
46# policy. A deny-only statement grants nothing public, so it attaches fine
47# under the full access block above.
48data "aws_iam_policy_document" "fleet_backup_tls_only" {
49 statement {
50 sid = "DenyInsecureTransport"
51 effect = "Deny"
52 actions = ["s3:*"]
53 resources = [
54 aws_s3_bucket.fleet_backup.arn,
55 "${aws_s3_bucket.fleet_backup.arn}/*",
56 ]
57
58 principals {
59 type = "*"
60 identifiers = ["*"]
61 }
62
63 condition {
64 test = "Bool"
65 variable = "aws:SecureTransport"
66 values = ["false"]
67 }
68 }
69}
70
71resource "aws_s3_bucket_policy" "fleet_backup" {
72 bucket = aws_s3_bucket.fleet_backup.id
73 policy = data.aws_iam_policy_document.fleet_backup_tls_only.json
74}
75
76# The router box's credentials: object read/write/delete + list on the fleet
77# bucket, nothing else in the account. Mint the access key by hand
78# (aws iam create-access-key --user-name litestream-fleet) — keys never land
79# in tofu state.
80resource "aws_iam_user" "litestream_fleet" {
81 name = "litestream-fleet"
82}
83
84data "aws_iam_policy_document" "litestream_fleet" {
85 statement {
86 sid = "ListFleetBucket"
87 actions = ["s3:ListBucket"]
88 resources = [aws_s3_bucket.fleet_backup.arn]
89 }
90
91 statement {
92 sid = "ReadWriteFleetObjects"
93 actions = [
94 "s3:GetObject",
95 "s3:PutObject",
96 "s3:DeleteObject",
97 ]
98 resources = ["${aws_s3_bucket.fleet_backup.arn}/*"]
99 }
100}
101
102resource "aws_iam_user_policy" "litestream_fleet" {
103 name = "litestream-fleet-bucket"
104 user = aws_iam_user.litestream_fleet.name
105 policy = data.aws_iam_policy_document.litestream_fleet.json
106}
107