Phase 2 sections 2-6 and 8 of docs/SCALE-EXPANSION.md: - pkg/telemetry + pkg/metrics: OpenTelemetry trace propagation and Prometheus metrics across every service hop (CLI -> agent -> gateway -> card-issuance/tenant-registry/auth -> ledger-core), tracing added to ledger-core itself via services/ledger-core/src/telemetry.rs. - infra/: otel-collector + Prometheus + Grafana docker-compose stack, a Terraform ECS Fargate module + dev/staging/prod envs (plan-only, no apply — real AWS spend is an owner action), and a dev-only mTLS CA (infra/dev-ca) wired through pkg/mtls + services/ledger-core/src/mtls.rs. - services/audit-log (from the prior commit) gets its async mirror writer in services/ledger-core/src/audit_mirror.rs, and services/gateway gets a per-tenant token-bucket rate limiter (internal/ratelimit). - Test depth: a Rust proptest suite proving concurrent ApplyEntry never breaches the reserve floor (tests/apply_entry_proptest.rs, passing), a Go fuzz seed corpus for the policy envelope (rules_fuzz_test.go), a libFuzzer harness for the C WAL frame parser (services/wal/fuzz, deliberately not wired into `make test` per its own Makefile comment - needs a libFuzzer-bundled clang), and a real chaos test (scripts/chaos/kill-ledger-mid-write.sh) that SIGKILLs ledger-core mid-write under concurrent load and verifies via ListEntries that nothing was lost or double-applied. - docs/formal/ledger.tla: a TLA+ spec of the ledger state machine (balance >= reserve_floor safety, HOLD-eventually-resolves liveness) plus a TLC model config - not run through TLC in this pass, that's a precise documented TODO, not faked. - docs/adr/0001-0004, docs/RUNBOOK.md, docs/SLO.md, docs/THREAT-MODEL.md. Verified: `make build && make test` clean (C WAL, Rust incl. the new proptest suite, all 10 Go modules) from a cold target. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
118 lines
2.9 KiB
HCL
118 lines
2.9 KiB
HCL
# S3 bucket for periodic ledger-core snapshot backups.
|
|
#
|
|
# docs/SCALE-EXPANSION.md section 3 is explicit about what this is NOT:
|
|
# ledger-core's write-ahead log stays on local/EBS disk at the instance —
|
|
# the WAL is the durability source of truth and S3 is not in its write
|
|
# path. This bucket exists only for periodic snapshot backups (a
|
|
# scheduled job outside Terraform's scope — see the TODO in
|
|
# envs/dev/main.tf — pushes a point-in-time snapshot of ledger-core's
|
|
# SQLite index + a WAL checkpoint here) so a full instance/EBS loss is
|
|
# recoverable from an out-of-band backup, not just from the WAL.
|
|
|
|
terraform {
|
|
required_version = ">= 1.5.0"
|
|
|
|
required_providers {
|
|
aws = {
|
|
source = "hashicorp/aws"
|
|
version = ">= 5.0"
|
|
}
|
|
random = {
|
|
source = "hashicorp/random"
|
|
version = ">= 3.0"
|
|
}
|
|
}
|
|
}
|
|
|
|
locals {
|
|
tags = merge(var.tags, {
|
|
ManagedBy = "terraform"
|
|
Purpose = "ledger-core-snapshot-backup"
|
|
})
|
|
}
|
|
|
|
# S3 bucket names are globally unique across all AWS accounts; a random
|
|
# suffix avoids a plan-time collision with another account's bucket.
|
|
resource "random_id" "suffix" {
|
|
byte_length = 4
|
|
}
|
|
|
|
resource "aws_s3_bucket" "this" {
|
|
bucket = "${var.name}-ledger-backup-${random_id.suffix.hex}"
|
|
tags = local.tags
|
|
}
|
|
|
|
resource "aws_s3_bucket_versioning" "this" {
|
|
bucket = aws_s3_bucket.this.id
|
|
versioning_configuration {
|
|
status = "Enabled"
|
|
}
|
|
}
|
|
|
|
resource "aws_s3_bucket_public_access_block" "this" {
|
|
bucket = aws_s3_bucket.this.id
|
|
block_public_acls = true
|
|
block_public_policy = true
|
|
ignore_public_acls = true
|
|
restrict_public_buckets = true
|
|
}
|
|
|
|
resource "aws_s3_bucket_server_side_encryption_configuration" "this" {
|
|
bucket = aws_s3_bucket.this.id
|
|
|
|
rule {
|
|
apply_server_side_encryption_by_default {
|
|
sse_algorithm = "aws:kms"
|
|
}
|
|
bucket_key_enabled = true
|
|
}
|
|
}
|
|
|
|
resource "aws_s3_bucket_lifecycle_configuration" "this" {
|
|
bucket = aws_s3_bucket.this.id
|
|
|
|
rule {
|
|
id = "snapshot-lifecycle"
|
|
status = "Enabled"
|
|
|
|
filter {}
|
|
|
|
transition {
|
|
days = var.transition_to_glacier_days
|
|
storage_class = "GLACIER_IR"
|
|
}
|
|
|
|
noncurrent_version_expiration {
|
|
noncurrent_days = var.noncurrent_version_expiration_days
|
|
}
|
|
}
|
|
}
|
|
|
|
# Customer-managed policy, scoped to this bucket only — pass the output
|
|
# ARN into the ledger-core service module's task_role_policy_arns so
|
|
# ledger-core's task role (and only that role) can push snapshots here.
|
|
data "aws_iam_policy_document" "access" {
|
|
statement {
|
|
sid = "ListBucket"
|
|
actions = [
|
|
"s3:ListBucket",
|
|
]
|
|
resources = [aws_s3_bucket.this.arn]
|
|
}
|
|
|
|
statement {
|
|
sid = "ReadWriteObjects"
|
|
actions = [
|
|
"s3:GetObject",
|
|
"s3:PutObject",
|
|
]
|
|
resources = ["${aws_s3_bucket.this.arn}/*"]
|
|
}
|
|
}
|
|
|
|
resource "aws_iam_policy" "access" {
|
|
name = "${var.name}-ledger-backup-access"
|
|
policy = data.aws_iam_policy_document.access.json
|
|
tags = local.tags
|
|
}
|