Files
bpmforge e0d82a4ed0 Kryptkeeper 1.0.0
First stable release. Notes: docs/release/RELEASE_NOTES_v1.0.0.md
Lab record: docs/release/LIVE_RESULTS_v1.0.0.md
2026-10-19 14:43:23 -04:00
..
2026-10-19 14:43:23 -04:00
2026-10-12 14:25:05 -04:00
2026-10-12 14:25:05 -04:00
2026-10-12 14:25:05 -04:00
2026-10-12 14:25:05 -04:00
2026-10-12 14:25:05 -04:00
2026-10-12 14:25:05 -04:00
2026-10-12 14:25:05 -04:00
2026-10-12 14:25:05 -04:00

kryptkeeper deployment infrastructure (Terraform)

Stands up the infrastructure a kryptkeeper Hub runs on: a VPC with public and private subnets, an RDS PostgreSQL database, and an EC2 instance running the Hub container. AWS is the reference implementation; the networking/database/compute module boundary is the swap point if you need a different cloud — each module only depends on the others' outputs (subnet IDs, security group IDs, a DB endpoint + secret ARN), not on AWS specifics leaking across the boundary.

This is not ../../terraform-provider-kryptkeeper. That is a Terraform provider (a Go plugin implementing the Terraform plugin protocol) used to manage kryptkeeper's own resources — CAs, certificates, templates — against a Hub that is already running. This directory is an ordinary root module built on the standard hashicorp/aws provider; it provisions the Hub itself, before there is anything for that other provider to talk to. Confirm the distinction from repo state, not just this paragraph: versions.tf here only requires hashicorp/aws, never the kryptkeeper provider.

What it creates

Module Resources
modules/networking VPC, 2 public + 2 private subnets across 2 AZs, internet gateway, route tables, an app security group (Hub) and a db security group (database, ingress from app only)
modules/database RDS PostgreSQL instance in the private subnets, encrypted at rest, not publicly accessible, master password managed by AWS Secrets Manager (never seen by Terraform)
modules/compute One EC2 instance (Amazon Linux 2023) running the Hub container under a systemd unit via Docker, an Elastic IP, a dedicated encrypted EBS volume for /var/kryptkeeper, a Secrets Manager secret for the bootstrap token + keystore passphrase, and an IAM role scoped to SSM (Session Manager) + read access to that secret and the database secret

No NAT gateway: the database's private subnets never need outbound internet access, so provisioning one would be pure cost with no purpose here.

No SSH: the instance's IAM role only grants AmazonSSMManagedInstanceCore, so there is no inbound port 22 to manage — use aws ssm start-session --target <instance-id> instead.

The dedicated /var/kryptkeeper EBS volume (separate from the root disk) is deliberate: D-092 calls out that disk loss today means permanent CA key loss, and a volume that survives instance replacement (AMI updates, terraform taint, etc.) is the cheapest mitigation available at the infrastructure layer.

Prerequisites

  • Terraform >= 1.5.0 (or OpenTofu >= 1.6.0 — this module was written and validated against OpenTofu 1.12.5; both speak the same HCL and provider protocol)
  • An AWS account and credentials (aws configure / AWS_PROFILE / OIDC — anything the aws provider's standard credential chain picks up)
  • A ghcr.io/bpmforge/kryptkeeper image digest (sha256:...) you have verified. image_digest is required and a validation block rejects tags such as latest (IAC-004). Verify the signature before applying; the key model and verify command are in ../../packaging/SIGNING.md (for example cosign verify --key cosign.pub ghcr.io/bpmforge/kryptkeeper@sha256:<digest>).
  • The AWS CLI, to write the Hub secret after the first apply (below)

.terraform.lock.hcl is deliberately not committed here: Terraform and OpenTofu default to different provider registry hosts (registry.terraform.io vs. registry.opentofu.org) for the same hashicorp/aws source, so a lock file generated by one reads as a mismatch to the other. terraform init/tofu init generates the right one for whichever tool you're using; commit it yourself if you want to pin further.

Usage

cd deploy/terraform
cp terraform.tfvars.example terraform.tfvars
# edit terraform.tfvars: set allowed_app_ingress_cidr_blocks and image_digest

terraform init
terraform plan
terraform apply

Immediately after apply (the instance polls for up to ~30 minutes), write the Hub secret. Terraform creates only the empty secret container; it never sees the values, so they never enter state (IAC-002). The bootstrap token and the keystore passphrase must be two independent values (IAC-003); the instance refuses to start if they are equal or empty:

aws secretsmanager put-secret-value \
  --secret-id "$(terraform output -raw app_secret_arn)" \
  --secret-string "$(jq -n \
      --arg t "$(openssl rand -hex 24)" \
      --arg p "$(openssl rand -hex 32)" \
      '{app_bootstrap_token:$t, keystore_passphrase:$p}')"

Record both values in your secret manager: the passphrase is the only way to decrypt the CA keystore on the data volume. Then, once it is up:

terraform output app_url

TLS (IAC-001)

The Hub serves HTTPS on app_port; the module sets APP_CERTIFICATE_PROVIDER=ca and KRYPTKEEPER_TLS_SELF_ISSUE=true, so the Hub issues its listener certificate from its own CA (created on first boot). The certificate covers the Elastic IP, localhost, 127.0.0.1 and anything in tls_extra_sans. Clients must trust the Hub CA: fetch it from the instance (aws ssm start-session, then read /var/kryptkeeper/data/tls/ca.pem) and add it to your trust store, or use curl --cacert ca.pem.

To bring your own certificate instead, create a Secrets Manager secret outside Terraform with JSON keys certificate_pem (full chain) and private_key_pem, and set tls_cert_secret_arn to its ARN. The instance role is granted read on that one ARN, the files are written root-owned with group 65532 mode 0640 under /etc/kryptkeeper/tls, mounted read-only, and the Hub is started with KRYPTKEEPER_TLS_CERT_FILE / KRYPTKEEPER_TLS_KEY_FILE instead of self-issuing. Put the DNS name clients dial in your certificate.

State is sensitive (IAC-002)

State contains resource IDs and ARNs (not the Hub secrets, which are written out of band, and not the RDS password, which RDS manages in Secrets Manager). Even so, treat it as sensitive: use an encrypted remote backend rather than a local terraform.tfstate, and never commit it. A commented S3 backend (SSE-KMS, DynamoDB locking) is in versions.tf; versioning and a public-access block on the bucket are up to you. .gitignore already excludes state and terraform.tfvars.

Hardening notes

The container runs with --read-only, --tmpfs /tmp, --cap-drop ALL and no-new-privileges (IAC-009), IMDSv2 is required with a hop limit of 1, and the DB password is URL-encoded into DATABASE_URL. Secrets are still passed to the container as environment variables, so root on the host can read them via docker inspect.

Neither secret is templated into user_data (EC2 user data is readable in plaintext by any IAM principal with ec2:DescribeInstanceAttribute); that script only contains secret ARNs and reads the values at boot via the instance role. The container runs under kryptkeeper.service, whose RequiresMountsFor=/var/kryptkeeper (and an /etc/fstab entry without nofail) stops the Hub starting against an empty directory if the data volume is late, so a reattach delay fails loudly instead of minting a fresh CA state (D-092).

Tearing down

db_deletion_protection defaults to true and db_skip_final_snapshot defaults to false — both on purpose, so a terraform destroy doesn't silently take the database (and every issued certificate's record) with it. To actually tear down: set both explicitly before destroying, or destroy everything else first and delete the database by hand once you've confirmed you have what you need.

Validating without an AWS account

terraform fmt -check -recursive
terraform init -backend=false
terraform validate

validate type-checks the whole module graph (including the two child modules) against the real hashicorp/aws provider schema without calling any AWS API — it does not require credentials. plan/apply do require a real account; this repo's sandbox has none, so neither was run against this module.