Blast Radius: Why I Moved My Blog to Its Own AWS Account


I set out to automate deploys with GitHub Actions and ended up restructuring my entire AWS setup. This is the story of why, plus the one CloudFront constraint that took my site down for an hour.

TL;DR

  • OIDC removes stored credentials, but it makes your GitHub account a credential for your AWS account
  • The CDK bootstrap grants AdministratorAccess by default, so “what can CI do” really means “what is in this account”
  • My answer was eight registered domains, which are the one thing here that is hard to recover
  • Separate accounts beat clever IAM policies
  • CloudFront alternate domain names are globally unique, which broke my migration

The question I should have asked first

I had just automated deploys so that npx cdk deploy did everything in one step. The obvious next move was GitHub Actions, so I could publish without a laptop.

The modern way to connect GitHub to AWS is OIDC federation. GitHub mints a short-lived signed token per workflow run, AWS exchanges it for STS credentials that expire within the hour, and nothing long-lived is ever stored in GitHub. It is genuinely better than an access key in a repo secret.

I wrote the trust policy carefully. Exact branch ref, StringEquals rather than a wildcard, audience verified:

"Condition": { "StringEquals": {
  "token.actions.githubusercontent.com:aud": "sts.amazonaws.com",
  "token.actions.githubusercontent.com:sub": "repo:owner/repo:ref:refs/heads/main"
}}

The role itself holds no deploy permissions. It can only assume the CDK bootstrap roles, which is what cdk deploy actually uses. That felt tight.

Then I checked what those bootstrap roles could do:

cdk-hnb659fds-cfn-exec-role-...  →  AdministratorAccess

That is the CDK default, not a mistake. But it means the ceiling on my carefully scoped role was “anything in the account.” Which raised the question I had skipped: what is in this account?

Eight domains

The infrastructure was trivial. Two CloudFormation stacks, two S3 buckets, three Lambda functions, all belonging to the blog. No databases, no servers.

But the account also held eight registered domains.

That reframed everything. Losing a blog is an afternoon of rebuilding from a git repo. Losing a domain is a dispute process with a registrar. route53domains:TransferDomainToAnotherAwsAccount and route53domains:UpdateDomainNameservers are the genuinely irreversible actions in that account, and my deploy role could reach both.

Why I did not write a tighter policy

My first instinct was to scope the execution role: enumerate S3, CloudFront, ACM, Route 53, Lambda, IAM, and deny the rest.

Two problems.

The stack creates IAM roles. Four of them, for custom resource handlers and the GitHub role itself. So the execution role needs iam:CreateRole and iam:AttachRolePolicy. With those unrestricted, a compromised deploy creates a role, attaches AdministratorAccess, assumes it, and walks straight through the policy I just spent an afternoon writing. Scoping the service permissions without also constraining IAM is theater.

It is a standing tax. Every future change that touches a new service means a failed deploy and a policy edit. For a blog costing under a dollar a month, that is a bad trade.

The fix for the first problem is a permissions boundary, and at that point you are building real machinery. Which prompted a better question: why is the blog in the same account as the domains at all?

Account separation

The structural answer is simpler than any policy. Put the blog in its own account. Give CI full admin there. Leave the domains somewhere CI cannot reach.

management account       domains, billing, Organizations
└── Workloads OU         SCP guardrail attached
    └── website account  the blog, CDK bootstrap, OIDC role

The guardrail is a Service Control Policy on the OU:

{
  "Version": "2012-10-17",
  "Statement": [
    { "Sid": "DenyRegistrar", "Effect": "Deny",
      "Action": "route53domains:*", "Resource": "*" },
    { "Sid": "DenyOrgAndAccountChanges", "Effect": "Deny",
      "Action": ["organizations:*", "account:*"], "Resource": "*" },
    { "Sid": "DenyLongLivedCredentials", "Effect": "Deny",
      "Action": ["iam:CreateUser", "iam:CreateAccessKey",
                 "iam:CreateLoginProfile", "iam:CreateSAMLProvider"],
      "Resource": "*" }
  ]
}

An SCP is stronger than a policy on a role in a way that matters here. A role policy can be detached by anyone with admin on that role. An SCP applies to every principal in the account, including its root user, and nothing inside the account can remove it.

I tested it with the most privileged principal available, the OrganizationAccountAccessRole session:

$ aws route53domains list-domains --profile website-admin
AccessDeniedException: ... with an explicit deny in a
service control policy: p-tte7r2oe

$ aws iam create-user --user-name scp-test --profile website-admin
AccessDenied: ... with an explicit deny in a
service control policy: p-tte7r2oe

Full admin in that account, and it still cannot reach the registrar. That is the property I wanted, and it holds regardless of how carefully I write the deploy role’s policy.

Note what is not denied: route53. The hosted zone has to live where the stack lives, so CI can still manage DNS records for the blog’s own domain. A compromised deploy could serve a fake site. It cannot steal the registration or touch the other seven domains. That is the line this actually draws, and it is worth being clear-eyed that it is a line rather than a wall.

The constraint that broke the migration

Moving the site meant a DNS cutover. I planned it carefully: bootstrap CDK in the new account first, create the hosted zone, flip the registrar’s nameservers, then deploy immediately so the outage window was just the deploy time rather than the whole setup.

I even started the deploy before flipping, so CloudFormation would build everything that did not depend on DNS and park waiting on certificate validation. When the nameservers propagated, ACM validated and the rest would proceed.

It worked exactly as designed, right up until CloudFront:

AWS::CloudFront::Distribution: One or more of the CNAMEs you provided
are already associated with a different resource. (409)

CloudFront enforces alternate domain names as globally unique across all AWS accounts. The old distribution still claimed example.com and www.example.com, so the new one could not have them. Two distributions cannot serve the same custom domain, even in different accounts, even mid-migration.

I had sequenced DNS in detail and never checked this. It would have broken either cutover approach, and it broke this one after the nameservers had already flipped, which is the worst moment to discover it.

The stack rolled back. The site was down.

Getting out of it

The fix is that the old distribution has to release the names before the new one can claim them. Two ways: update the old distribution to drop its aliases, or delete it outright.

I reached for the update, since it preserved a rollback path. That was the wrong instinct, and it took a nudge to see why: a distribution without its custom domain cannot serve the site either. The rollback it preserved was imaginary. Deleting was simpler, removed the old OIDC provider from the management account as a side effect, and was where the migration was headed anyway.

cdk destroy   # old account, releases the domain names
cdk deploy    # new account, claims them

The second deploy took 339 seconds and came up clean.

The setup, end to end

Here is the whole thing, for anyone wanting to copy it.

The role, in CDK. The trust policy above, plus permission to assume only the three bootstrap roles cdk deploy actually uses:

const provider = new iam.OpenIdConnectProvider(this, 'Provider', {
  url: 'https://token.actions.githubusercontent.com',
  clientIds: ['sts.amazonaws.com'],
});

const role = new iam.Role(this, 'Role', {
  maxSessionDuration: cdk.Duration.hours(1),
  assumedBy: new iam.WebIdentityPrincipal(provider.openIdConnectProviderArn, {
    StringEquals: {
      'token.actions.githubusercontent.com:aud': 'sts.amazonaws.com',
      'token.actions.githubusercontent.com:sub':
        `repo:${repository}:ref:refs/heads/${branch}`,
    },
  }),
});

const qualifier = cdk.DefaultStackSynthesizer.DEFAULT_QUALIFIER;
role.addToPolicy(new iam.PolicyStatement({
  actions: ['sts:AssumeRole'],
  resources: ['deploy', 'file-publishing', 'lookup'].map(
    (name) =>
      `arn:aws:iam::${stack.account}:role/cdk-${qualifier}-${name}-role-${stack.account}-${stack.region}`,
  ),
}));

lookup is needed because cdk.context.json is gitignored here, so CI re-resolves the hosted zone on every run. image-publishing is omitted since there are no container assets.

The workflow. id-token: write is what lets the runner request the OIDC token:

on:
  push:
    branches: [main]
  workflow_dispatch:

permissions:
  contents: read
  id-token: write

concurrency:
  group: deploy-main
  cancel-in-progress: false

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - uses: actions/setup-node@v7
        with:
          node-version: 24
      - run: npm ci
      - uses: aws-actions/configure-aws-credentials@v6
        with:
          role-to-assume: ${{ vars.AWS_DEPLOY_ROLE_ARN }}
          aws-region: us-east-1
      - run: npx cdk deploy --require-approval never

The concurrency group matters because the deployment prunes the bucket to match its source, so two overlapping runs would fight over the same objects. Queue rather than cancel: a half-finished CloudFormation update is worse than a slow one.

The role ARN lives in a repo variable, not the workflow file, which keeps the account id out of a public repo.

The chicken and egg. The role has to exist before any workflow run can authenticate, and the role is created by the stack the workflow deploys. So the first deploy comes from a laptop, and you set the variable from its output afterward.

What I would do differently

Check resource-level uniqueness before planning a cutover. CloudFront alternate domain names, S3 bucket names, and ACM certificates all have global or account-level constraints that do not show up when you are reasoning about DNS propagation. A five minute check would have saved an hour of downtime.

Ask what is in the account before designing the permissions. I spent real effort on a trust policy before establishing what it was protecting. The domains changed the entire calculus, and I found them almost by accident.

Prefer structure over policy. The SCP is four lines of intent. The equivalent IAM policy would have been hundreds of lines, brittle, and would still have had the escalation hole. When you can solve something with a boundary instead of a rule, take the boundary.

The result

Publishing is now git push. CI authenticates with a token that expires in an hour, deploys into an account that contains nothing but the blog, and cannot reach anything worth taking if it is ever compromised.

The blast radius is the blog. That was the entire point.