Shiva Sai Case study · P1
P1 Case study · static.ju25.uk

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-2 with 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
01 Problem and goal

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.

02 Architecture

Two flows: visitors read, the pipeline writes

Visitor to CloudFront over HTTPS; CloudFront to the private S3 bucket through Origin Access Control and SigV4; a direct request to S3 is denied; GitHub Actions exchanges an OIDC token for IAM roles that apply infrastructure, upload files and invalidate the cache.
Request path (solid) and delivery path. The ten steps are explained one at a time in the interactive lifecycle.

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.

03 Design decisions

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.

Read the ADRs

04 Infrastructure provisioning

Two layers with a clear owner each

LayerTool and frequencyCreates
BootstrapCloudFormation, once, by a personState bucket (private, versioned, encrypted, TLS only) and the plan, apply and deploy roles. It reuses the account's existing OIDC provider.
PlatformTerraform, on every approved mergeSite 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
}
05 Delivery pipeline

Six workflows, two approvals

WorkflowTriggerRoleWhat it guarantees
validateEvery pull requestnoneFormat, validate, mocked tests, TFLint, Checkov, cfn-lint, gitleaks, actionlint, ShellCheck, unit tests, HTML, accessibility and link checks
terraform-planPull request, manualplanReviewers see exactly what will change
terraform-applyMerge touching infra/apply (infra)Only approved changes reach AWS
deploy-siteMerge touching site/, or rollback inputdeploy (production)Only commits on main are published
verify-deploymentAfter each publishplanPublic behaviour and AWS settings match the design
terraform-destroyManual, typed confirmationapply (infra)Teardown is deliberate
06 IAM and security

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 explicit self sources, 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.
07 Testing

Tests that need no AWS account, then checks that do

Before merge

  • Mocked terraform test security 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 commit
  • verify_aws_config.py: Block Public Access, policy not public, single distribution, OAC with SigV4, HTTPS redirect, headers policy, TLS minimum
08 Operating it

Observability, failure modes and recovery

FailureHow it showsResponse
Bad content publishedVisible on the site; version.json names the commitRun deploy-site with an earlier commit (drilled: rollback and roll-forward)
Origin access brokenEvery uncached page returns the 404 pageCloudFront and S3 access runbook
Pipeline cannot assume a roleSTS AssumeRoleWithWebIdentity errorOIDC runbook
Certificate or DNS problemBrowser TLS error, name not resolvingCertificate and DNS runbook
State lock left behindTerraform cannot acquire the lockTerraform 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.

09 Evidence

Recorded on 4 December 2026

  1. 06:05First apply #4727860084212 added, 0 changed, 0 destroyed
  2. 06:16First publish and verification #47280027636all checks passed
  3. 06:19Rollback, then roll forward at 06:21 #47280411395the live commit changed both times
  4. 07:37Apply failed on a missing tag permission #47290690014fixed narrowly in the bootstrap, applied at 07:42
  5. 17:25Live checks re-run for this case studyfive public checks passed, TLS 1.1 refused
10 Trade-offs and limits

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.
11 Future work

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.