Skip to content

feat: org-wide S3-lister role, created by CI#33

Merged
nbrieussel merged 4 commits into
mainfrom
feat/s3-lister-role-via-ci
Jun 15, 2026
Merged

feat: org-wide S3-lister role, created by CI#33
nbrieussel merged 4 commits into
mainfrom
feat/s3-lister-role-via-ci

Conversation

@nbrieussel

Copy link
Copy Markdown
Contributor

Context

First IAM role created by the CI (the aws-github-oidc role from #32) instead of by a human — exercising the privilege-escalation-safe role-creation flow end to end. Triggered from the remote: apply on push to main.

What it creates

s3-lister-role/ — a read-only S3 lister (AmazonS3ReadOnlyAccess, same access the original GitHub Action had), assumable by anyone in the AWS Organization:

trust_policy_permissions = {
  OrgWideAssume = {
    actions    = ["sts:AssumeRole"]
    principals = [{ type = "AWS", identifiers = ["*"] }]
    condition  = [{ test = "StringEquals", variable = "aws:PrincipalOrgID", values = [var.org_id] }]
  }
}

No account IDs hardcoded — the aws:PrincipalOrgID condition admits every (and only) caller whose creds belong to org o-f9lb1e5es9.

Honours the boundary contract

The role sits under the managed path and carries the permissions_boundary — the two conditions the CI grant requires, or the apply is denied. role_path is fed in CI from ${{ github.repository }}.

GitOps workflow

.github/workflows/s3-lister-role.yml assumes the CI role via OIDC (no static keys) and:

  • PRterraform plan (this PR will show the role to be created)
  • push to mainterraform apply

Also

Wired s3-lister-role into the lock-check matrix, the mise lock task, and CLAUDE.md — and added aws-github-oidc, which was missing from the docs/lock list.

How to assume it (once applied)

aws sts assume-role \
  --role-arn "$(terraform -chdir=s3-lister-role output -raw role_arn)" \
  --role-session-name demo

🤖 Generated with Claude Code

Nicolas Brieussel and others added 2 commits June 13, 2026 16:44
First IAM role created BY the CI (aws-github-oidc role) rather than by a human,
demonstrating the privilege-escalation-safe role-creation flow end to end.

- s3-lister-role/ root (terraform-aws-modules/iam): a read-only S3 lister
  (AmazonS3ReadOnlyAccess) assumable by ANY principal in the AWS Organization
  via an aws:PrincipalOrgID trust condition (no account IDs hardcoded).
- Honours the repo-wide contract: role sits under the managed path and carries
  the tf-managed permissions boundary, so the CI grant permits its creation.
  role_path is fed in CI from ${{ github.repository }}.
- .github/workflows/s3-lister-role.yml: Terraform GitOps — `plan` on PR, `apply`
  on push to main, assuming the CI role via OIDC (no static AWS keys).
- Wire the new root into the lock-check matrix, mise `lock` task, and CLAUDE.md
  (also adding aws-github-oidc, which was missing from the docs/lock list).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…ision

The s3-lister-role plan ran in the `default` workspace in CI, where the S3
backend ignores workspace_key_prefix — so its key resolved to `terraform.tfstate`
and collided with terraform-state-bucket's state (the plan wanted to destroy the
bucket's versioning!). The `infrastructure` workspace only existed locally via a
gitignored .terraform/environment, invisible to CI.

Make workspace selection declarative and version-controlled:

- .github/actions/terraform: a reusable composite action that, for a root, loops
  over workspace/<name>.tfvars files — filename = terraform workspace name,
  contents = that workspace's variables — running `workspace select -or-create`
  + plan/apply -var-file per workspace.
- s3-lister-role/workspace/infrastructure.tfvars: declares the `infrastructure`
  workspace and its vars (region, role_name, role_path, permissions_boundary_arn,
  org_id). State now lands at s3-lister-role/infrastructure/terraform.tfstate.
- s3-lister-role.yml: use the composite action instead of bare init/plan/apply;
  drop the TF_VAR_role_path env (now in the tfvars).
- Document the workspaces convention in CLAUDE.md.

Verified locally: with the workspace selected, `plan` is `2 to add, 0 to change,
0 to destroy` (only the role) — no more cross-root state collision.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Comment thread .github/actions/terraform/action.yml Outdated
Nicolas Brieussel and others added 2 commits June 13, 2026 21:39
Drop the multi-workspace loop, nullglob array, group logging and verbose guard —
one workspace/<name>.tfvars per root is the real case. Derive the workspace from
the single file and plan/apply with its var-file.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The point of this PR is to watch the CI role create the role via OIDC, so run
`apply` on every trigger instead of plan-on-PR / apply-on-main.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@nbrieussel
nbrieussel marked this pull request as ready for review June 15, 2026 13:44
@nbrieussel
nbrieussel merged commit 0b42803 into main Jun 15, 2026
10 checks passed
@nbrieussel
nbrieussel deleted the feat/s3-lister-role-via-ci branch June 15, 2026 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant