← All projects Case study · Security · IAM

Retiring a shared AWS root account.

Ten people shared one root login, with the password passed around over Teams and Slack. I replaced it with individual, least-privilege, MFA-enforced access and an audit trail of every action, built entirely in Terraform.

ScenarioNexaCore Solutions (hypothetical)
Scope10 users · 4 teams
StackTerraform · IAM · CloudTrail
OutcomeEvery action traceable

The problem

NexaCore had around ten employees using a single AWS root account. The credentials were shared in chat, so there was no way to tell who did what, and a single leak would have handed over full control of the account, billing included.

What was wrong

  • No accountability: every action showed up as “root”.
  • No visibility: nothing recorded API activity across regions.
  • Total blast radius: every person had unrestricted access to everything.
  • Credentials lived in Teams and Slack message history.

Access design: what each team actually needs

Before writing any Terraform I mapped each team to the smallest set of permissions it needs to do its job, and wrote down what each one should not be able to do. Explicit denials matter as much as grants.

GroupUsersAllowedExplicitly not allowed
Developers4EC2 and S3 on development resources, read-only CloudWatch LogsAny production access
Operations2Broad infrastructure managementIAM write actions (blocks privilege escalation)
Finance1AWS-managed Billing + ReadOnlyAccessAny change to resources
Analysts3Read-only on one analytics bucket and RDS metadataEverything else

Architecture

Problems I solved along the way

01

CloudTrail “worked” but delivered zero logs

SymptomThe trail created successfully, but no log files ever arrived in S3. Nothing errored.

FixCloudTrail needs an explicit bucket policy that lets its service principal write. I added one scoped to exactly that permission, and a depends_on so the policy exists before the trail, so logs flow from the very first run.

02

Operations could have granted themselves admin

Risk“Broad infrastructure management” included IAM, so an ops user could attach any policy to themselves.

FixAn explicit deny on IAM write actions for the Operations group. A deny always wins over an allow, so the escalation path is closed.

03

Copy-pasted user blocks would drift

RiskOne resource block per user means typos and inconsistent group membership as the team grows.

Fixfor_each over a list of names creates each user and its membership. Adding a person is a one-word change.

In the code

The trail and its dependency on the bucket policy, from main.tf:

resource "aws_cloudtrail" "main" {
  name                          = "nexacore-audit-trail"
  s3_bucket_name                = aws_s3_bucket.cloudtrail.id
  include_global_service_events = true
  is_multi_region_trail         = true
  enable_log_file_validation    = true

  # without the bucket policy, the trail is created but no logs are delivered
  depends_on = [aws_s3_bucket_policy.cloudtrail]
}

Users created from a list instead of copy-pasted blocks, from iam-user.tf:

resource "aws_iam_user" "developers" {
  for_each = toset(["dev-1", "dev-2", "dev-3", "dev-4"])
  name     = each.key
}

resource "aws_iam_user_group_membership" "dev_membership" {
  for_each = aws_iam_user.developers
  user     = each.value.name
  groups   = [aws_iam_group.developers.name]
}

How I verified it

I tested every group against real AWS resources and the IAM Policy Simulator, checking both sides of the matrix: allowed actions succeed, and denied actions fail loudly with AccessDenied instead of failing silently.

  • Developers can manage dev EC2 and S3 but get AccessDenied on production resources.
  • Operations can manage infrastructure but cannot create or attach IAM policies.
  • Finance can see billing but cannot change anything.
  • Every test action appeared in CloudTrail under the individual user’s name.

What I learned

  • Design the access matrix, denials included, before writing any policy.
  • Least-privilege JSON policies with jsonencode() and conditions are easier to review than console clicks.
  • “Created successfully” is not “working”: check that logs actually arrive.
  • for_each keeps identity code consistent as teams grow.
Next case studyServiceHub: a three-tier platform built to stay up Read