Secure Edge Delivery Platform
A static website delivered by CloudFront from an S3 bucket that has no public access, built only with code, deployed without stored credentials, and verified from outside after every change.
- Role
- Sole engineer: design, infrastructure, pipeline, testing, operation
- Built
- Deployed and verified on 4 December 2026, in
ap-south-2with global edge delivery - Stack
- Terraform 1.16, CloudFormation, S3, CloudFront, ACM, IAM with OIDC, GitHub Actions, Cloudflare DNS, Python, Bash
- Links
- Live platform tour · Repository · Evidence
Static hosting is where shortcuts hide
The quickest ways to host a few files are a public S3 website endpoint (no HTTPS on a custom name, and a bucket open to the world), an access key pasted into CI secrets, or a console setup that nobody can reproduce or review.
Engineering objective
One path to the content, enforced in two independent places. No long-lived credentials anywhere. Every resource in code, every change reviewed as a plan, and every deployment proven from outside.
Out of scope, on purpose
Dynamic content, a WAF and multi-region failover. These are listed as limitations rather than half-built.
Two flows: visitors read, the pipeline writes
Request flow
Cloudflare resolves the name to CloudFront (DNS only). CloudFront ends TLS with an ACM certificate, redirects HTTP, serves from cache or signs an origin request with SigV4 through OAC. The bucket policy admits only this distribution's ARN. Security headers are added at the edge.
Delivery flow
A job exchanges a GitHub OIDC token for one of three roles. Plans are read-only. Applies need the infra approval and publishes need production. The publish uploads in a safe order, invalidates, waits, and then the live site is tested.
Decisions, with the alternative that lost
Each is written up as an Architecture Decision Record with context, options and consequences.
- ADR 0001Private S3 behind CloudFront
One path to content; HTTPS and headers in one place.
Lost: S3 website hosting, which needs a public bucket and offers no HTTPS on a custom name.
- ADR 0002Origin Access Control
SigV4 on every request; the current mechanism; works with SSE and all S3 operations.
Lost: Origin Access Identity, the legacy mechanism.
- ADR 0003GitHub OIDC, not access keys
Credentials that last about an hour, bound to repository ID and environment.
Cost: trust conditions must be exact, and a typo fails closed with a vague error.
- ADR 0004CloudFormation bootstrap, three roles
No state file is needed to create the state bucket, and the pipeline never holds
iam:*.Cost: two tools to know, and the bootstrap is applied by a human once.
- ADR 0005S3 lock files for state
Native since Terraform 1.10; no DynamoDB table to run or pay for.
Needs Terraform 1.10 or later everywhere.
- ADR 0006No framework or build step
Nothing to compile, patch or audit; the strict CSP stays simple.
More hand-written HTML as pages grow.
- ADR 0007One distribution, two hostnames
A CloudFront Function rewrites only
/on the projects host and/projects; everything else passes through.Both hostnames share one content policy, including the projects page's two exceptions.
Two layers with a clear owner each
| Layer | Tool and frequency | Creates |
|---|---|---|
| Bootstrap | CloudFormation, once, by a person | State bucket (private, versioned, encrypted, TLS only) and the plan, apply and deploy roles. It reuses the account's existing OIDC provider. |
| Platform | Terraform, on every approved merge | Site bucket and its guard rails, bucket policy, OAC, headers policy, routing function, distribution, ACM certificate and validation. |
# infra/terraform/backend.tf
backend "s3" {
key = "secure-static-platform/terraform.tfstate"
encrypt = true
use_lockfile = true # S3-native locking, no DynamoDB
}
Six workflows, two approvals
| Workflow | Trigger | Role | What it guarantees |
|---|---|---|---|
validate | Every pull request | none | Format, validate, mocked tests, TFLint, Checkov, cfn-lint, gitleaks, actionlint, ShellCheck, unit tests, HTML, accessibility and link checks |
terraform-plan | Pull request, manual | plan | Reviewers see exactly what will change |
terraform-apply | Merge touching infra/ | apply (infra) | Only approved changes reach AWS |
deploy-site | Merge touching site/, or rollback input | deploy (production) | Only commits on main are published |
verify-deployment | After each publish | plan | Public behaviour and AWS settings match the design |
terraform-destroy | Manual, typed confirmation | apply (infra) | Teardown is deliberate |
Least privilege by stage, defence in depth at the origin
# Deploy role trust (CloudFormation), numeric IDs shown as placeholders
token.actions.githubusercontent.com:aud: sts.amazonaws.com
token.actions.githubusercontent.com:sub:
repo:ShivaSai06@<owner-id>/secure-static-platform@<repo-id>:environment:production
- Two independent locks on the origin. Block Public Access stops a mistaken policy, and the bucket policy admits only one distribution.
- Strict headers.
default-src 'none'with explicitselfsources, HSTS, nosniff, DENY framing, Permissions-Policy. The pages contain no inline script or style, and a test enforces it. - Supply chain. Every action is pinned to a commit SHA, the default token is read-only, and the downloaded scanners are checksum-verified.
- Documented wildcards. The few unavoidable
*resources (CloudFront list calls, for example) are listed and explained in security.
Tests that need no AWS account, then checks that do
Before merge
- Mocked
terraform testsecurity suite - Python tests for scripts, workflows, IAM design, site semantics and links, and the CloudFront Function run in Node
- Tests assert there is no account ID, ARN or e-mail address in the site
- pa11y (WCAG 2 AA) and html-validate
After deploy
verify_deployment.py: 200, 301, headers, direct S3 403, unknown 404, expected commitverify_aws_config.py: Block Public Access, policy not public, single distribution, OAC with SigV4, HTTPS redirect, headers policy, TLS minimum
Observability, failure modes and recovery
| Failure | How it shows | Response |
|---|---|---|
| Bad content published | Visible on the site; version.json names the commit | Run deploy-site with an earlier commit (drilled: rollback and roll-forward) |
| Origin access broken | Every uncached page returns the 404 page | CloudFront and S3 access runbook |
| Pipeline cannot assume a role | STS AssumeRoleWithWebIdentity error | OIDC runbook |
| Certificate or DNS problem | Browser TLS error, name not resolving | Certificate and DNS runbook |
| State lock left behind | Terraform cannot acquire the lock | Terraform state runbook |
Observability is deliberately thin: the CloudFront console metrics and the post-deploy checks. Access logs and alarms are not enabled, which is a known limitation.
Recorded on 4 December 2026
- 06:05First apply #4727860084212 added, 0 changed, 0 destroyed
- 06:16First publish and verification #47280027636all checks passed
- 06:19Rollback, then roll forward at 06:21 #47280411395the live commit changed both times
- 07:37Apply failed on a missing tag permission #47290690014fixed narrowly in the bootstrap, applied at 07:42
- 17:25Live checks re-run for this case studyfive public checks passed, TLS 1.1 refused
What I would say in a design review
- DNS is outside Terraform. A Cloudflare provider would close the loop but needs another credential in CI.
- Missing and refused objects both look like 404. That is safer, but harder to debug, so the runbook covers it.
- A single region origin is fine for static content that is rebuilt from Git, but it is not a disaster recovery design.
- Self-approval satisfies the mechanism but not the intent of review. A second approver would.
How it would grow
- CloudFront standard logging to a log bucket, and a CloudWatch alarm on the 5xx error rate.
- AWS WAF with managed rules once there is anything worth attacking.
- Cloudflare records in Terraform, with a scoped API token in a protected environment.
- A failover origin group with a replicated bucket in a second region.
The steps are in docs/extending.md.