# 🤖 The fleet-backup bucket: Litestream on the router box streams every # instance DB (plus home/push/cloud/registry) here, one prefix per database. # Versioning is the ransomware posture — an overwrite or delete with the # box's credentials leaves noncurrent versions recoverable for 14 days, and # the box's IAM user (below) cannot touch versioning, lifecycle, or the # bucket itself. resource "aws_s3_bucket" "fleet_backup" { bucket = "eleven-prod-fleet-backup-${local.account_id}" } resource "aws_s3_bucket_versioning" "fleet_backup" { bucket = aws_s3_bucket.fleet_backup.id versioning_configuration { status = "Enabled" } } resource "aws_s3_bucket_lifecycle_configuration" "fleet_backup" { bucket = aws_s3_bucket.fleet_backup.id rule { id = "expire-noncurrent-14d" status = "Enabled" filter {} noncurrent_version_expiration { noncurrent_days = 14 } } } resource "aws_s3_bucket_public_access_block" "fleet_backup" { bucket = aws_s3_bucket.fleet_backup.id block_public_acls = true block_public_policy = true ignore_public_acls = true restrict_public_buckets = true } # TLS-only: deny any request arriving over plain HTTP. Litestream and the # vault sync both speak HTTPS already — this turns that assumption into # policy. A deny-only statement grants nothing public, so it attaches fine # under the full access block above. data "aws_iam_policy_document" "fleet_backup_tls_only" { statement { sid = "DenyInsecureTransport" effect = "Deny" actions = ["s3:*"] resources = [ aws_s3_bucket.fleet_backup.arn, "${aws_s3_bucket.fleet_backup.arn}/*", ] principals { type = "*" identifiers = ["*"] } condition { test = "Bool" variable = "aws:SecureTransport" values = ["false"] } } } resource "aws_s3_bucket_policy" "fleet_backup" { bucket = aws_s3_bucket.fleet_backup.id policy = data.aws_iam_policy_document.fleet_backup_tls_only.json } # The router box's credentials: object read/write/delete + list on the fleet # bucket, nothing else in the account. Mint the access key by hand # (aws iam create-access-key --user-name litestream-fleet) — keys never land # in tofu state. resource "aws_iam_user" "litestream_fleet" { name = "litestream-fleet" } data "aws_iam_policy_document" "litestream_fleet" { statement { sid = "ListFleetBucket" actions = ["s3:ListBucket"] resources = [aws_s3_bucket.fleet_backup.arn] } statement { sid = "ReadWriteFleetObjects" actions = [ "s3:GetObject", "s3:PutObject", "s3:DeleteObject", ] resources = ["${aws_s3_bucket.fleet_backup.arn}/*"] } } resource "aws_iam_user_policy" "litestream_fleet" { name = "litestream-fleet-bucket" user = aws_iam_user.litestream_fleet.name policy = data.aws_iam_policy_document.litestream_fleet.json }