Four Days After I Open Sourced It, a PR Comment Stole My Production AWS Credentials

Brian Carpio•
AWSSecurityGitHub ActionsOIDCGuardDutyIncident ResponseOutcomeOps

On November 19 I open sourced OutcomeOps and published Early Again: Why I Open Sourced OutcomeOps. Four days later a GuardDuty alert landed in the support inbox: Impact:IAMUser/AnomalousBehavior, severity 8, in my production account.

A comment on one of my pull requests had run shell commands on a GitHub Actions runner and taken the AWS credentials that workflow had just been handed. Those credentials belonged to a role that was, for practical purposes, admin in production. Within four minutes they were being used from a VPS in France to try to launch GPU instances.

Nothing launched, nothing was left behind, and as far as the logs can show, no data was read. I'd like to say my controls stopped it. They didn't. Two things I never designed for this did, and this post is about the difference between those.

What actually mattered

  • ${{ github.event.comment.body }} inside run: is shell injection. It was harmless while the repo was private. It became exploitable the day I made it public.
  • GitHub's secret masking only hides the exact string. The payload printed the key reversed, hex encoded and base64 encoded, and none of those were masked.
  • The real hole was my OIDC trust, not the workflow. A wildcard subject chained into a role with PowerUserAccess plus IAM role management, in every account.
  • Luck stopped it. An SCP I wrote to enforce IMDSv2 and a GPU quota of zero blocked every launch. Neither was there to stop an attacker.
  • GuardDuty is the only reason I know. Nothing else I run would have noticed.

Short on time? The checklist at the end is the part to act on.

What happened, minute by minute

Everything below comes from CloudTrail, the GitHub API and the GuardDuty finding. Times are UTC, on November 23.

TimeWhat happened
20:08:05A comment starting with outcomeops: is posted on an open pull request.
20:08:17The PR Commands workflow trades its GitHub OIDC token for the CI hub role, then chains into the production CI role.
20:08:21The injected code calls GetCallerIdentity from the runner and prints the credentials into the job log.
20:12:37First call from outside GitHub: GetCallerIdentity, user agent Python-urllib/3.12.
20:12:47From a Contabo VPS in France: DescribeRegions, DescribeVpcs, then RunInstances with a placeholder AMI in three regions, as a probe.
20:13:11Seven dry-run RunInstances calls for GPU instance types, using an Amazon Linux 2023 AMI. Every one returns "Request would have succeeded."
20:13:55The real launches, now with an Ubuntu 22.04 AMI. Every one is denied by a service control policy.
20:14:36A spot request fails on MaxSpotInstanceCountExceeded.
20:14:49A launch template for p3.2xlarge, then CreateFleet. The call "succeeds" and launches nothing: the fleet's error set carries the same SCP deny.
20:15:13The script deletes its launch template, checks for instances and spot requests, finds none, and stops. 60 API calls from outside GitHub in under three minutes.
20:26:04GuardDuty raises the finding and emails the support inbox.
21:08:17The stolen credentials expire. They were never used after 20:15.

Two things in that table matter more than the rest. GuardDuty needed about 14 minutes to flag activity that was already over. And nothing contained the attack. The attacker gave up and the credentials expired on their own. Detection worked. Response was not needed, and that is not the same as response working.

I can't prove what the instances were for, because I never saw the script that would have run on them. An automated tool going for the biggest GPU it could get, and probing regions and quotas to find one, is almost certainly crypto mining. GPU capacity also gets stolen for resale and for training, so I'll leave it at almost.

CloudTrail will not show you an attacker's startup script

EC2 user data is the script an instance runs on first boot. It's where a miner gets installed. CloudTrail logs the field but not its contents. In every one of the attacker's CreateLaunchTemplate, RunInstances and RequestSpotInstances calls, the value is the literal string <sensitiveDataRemoved>. The only place the script still existed was the launch template itself, and the attacker deleted that on the way out.

AWS doesn't call this out for user data specifically. The CloudTrail log file examples show the same marker replacing a new key pair's private key. If you ever need to see what an attacker meant to run, read it from the source before it's gone: aws ec2 describe-launch-template-versions for a launch template, or aws ec2 describe-instance-attribute --attribute userData for an instance. In my case there was no time to: the attacker deleted the template 19 seconds after creating it, eleven minutes before GuardDuty said anything.

How a comment becomes a shell

OutcomeOps has a PR Commands workflow. You comment outcomeops: help on a pull request, a Lambda in my AWS account handles the command, and it replies on the PR. To invoke the Lambda, the job assumes an AWS role through GitHub's OIDC federation. This was the line that read the comment:

- name: Invoke Handle Command Lambda
  run: |
    COMMAND=$(echo '${{ github.event.comment.body }}' | head -1)

It looks like it quotes the comment. It doesn't. The ${{ }} syntax is template substitution, and Actions does it before bash ever sees the script. Whatever the comment says is pasted into the program text. A single quote in the comment closes the quote in the script, and everything after it is shell.

The comment had this shape. I've replaced the working parts with comments:

outcomeops:'; {
  # print the runner's identity
  # print each AWS credential reversed, hex encoded and base64 encoded,
  #   so none of them matches the string GitHub masks
  # print the whole environment, compressed and base64 encoded
} >&2; echo '

It starts with outcomeops: because that was the workflow's only gate. The leading ' closes my quote, the block runs, and the trailing echo ' reopens a quote so the rest of my line still parses. The job finished green.

Three things made it work:

  • The credentials were in the environment. aws-actions/configure-aws-credentials exports them as environment variables for every later step in the job, and the vulnerable step ran after it.
  • Masking matched only the literal value. GitHub replaces a known secret with *** wherever that exact string appears in a log. A reversed or encoded copy is a different string.
  • The log was public. In a public repository anyone can read a workflow run's log. The attacker didn't need a callback server. They read their payload's output like everyone else.

The payload also gzipped and printed the step's whole environment. Apart from the AWS session credentials, the only thing of value in it was the CI role's ARN, which gives away an account ID and a role name. It held no GITHUB_TOKEN and no repository secrets. Anything else in it was tied to the job, which finished at 20:08:26, four minutes before the first call from outside GitHub. The run's log has since been deleted.

The same file had a second injection point I hadn't noticed: the pull request's branch name, also interpolated into run:. Branch names are chosen by whoever opens the PR.

This workflow was written while the repo was private. In a private repo only collaborators can comment, so the comment came from someone already trusted, and the bug had no way in. Making the repo public changed who could comment, and nothing else had to change. I reviewed the code before open sourcing it. I didn't review it as something strangers could now trigger.

It wasn't aimed at me in particular. The account that posted it, picxbed, commented on about ten other repositories in the two hours before, almost all of them copies of a Microsoft Learn MLOps course whose workflows hold cloud credentials. It was created in 2024 and looks like a student's account, so it may itself be compromised. I've reported it to GitHub.

The part that was my fault

The injection is a well-known bug, and GitHub's own security guidance for Actions warns about it. What turned it into a production incident was what the stolen credentials could do, and that part I designed.

My CI uses a hub and spoke. GitHub's OIDC token is exchanged for a hub role in a shared services account, and the hub can assume a github-actions-ci role in every other account. This was the hub's trust, exactly as it shipped:

locals {
  # PLACEHOLDER — the operator MUST scope this per org/repo/branch/environment
  # before apply. ...
  github_subjects = [
    "repo:bcarpio/*:*",
    "repo:outcomeops/*:*",
  ]
}

Any workflow, in any of my repositories, on any branch or trigger, could get in. The comment above it says to change it before applying. I applied it anyway and never came back.

The spoke it led to had PowerUserAccess plus an inline policy so Terraform could manage roles: iam:CreateRole, AttachRolePolicy, UpdateAssumeRolePolicy and PassRole, on *. A role that can create a role and attach any policy to it is an admin role with extra steps.

So the workflow that answered strangers' comments held the same role my deployment pipelines were set up to use, in every account. All it needed was lambda:InvokeFunction on one function.

The worst part: OutcomeOps already ships the right answer. The open source stack includes an optional CI role that trusts GitHub OIDC directly, is scoped to one repository and environment, and can invoke only the two PR Lambdas. It's the path the docs tell customers to use. My own deployment wasn't using it.

Think about what a human attacker could have done with that hour instead of a mining script. Create a role with AdministratorAccess trusting their own AWS account, which outlives the stolen session. Read Secrets Manager. Read S3 and DynamoDB. Replace a Lambda's code and wait. Nothing I had in place would have stopped any of it.

Why it failed anyway

Here is every layer the attacker went through, and whether the layer held because I designed it to.

LayerWhat happenedDesign or luck
WorkflowInjection worked. A stranger got credentials.Failed
IAMAdmin-equivalent role reachable from a PR commentFailed
SCPReal launches denied by the IMDSv2 policyLuck
QuotasGPU on-demand vCPU quota of 0; spot limit hitLuck
Session lengthCredentials expired after one hourDesign
GuardDutyFlagged it 14 minutes after it startedDesign, detection only

The SCP row is the one that keeps me up. My organization's baseline includes an SCP that denies RunInstances unless the request requires IMDSv2. I added it so any instance anyone launched would be safer to run. I decoded the authorization failure message on the failed fleet to be sure. The matched statement is DenyEC2IMDSv1Launch, the request's ec2:MetadataHttpTokens was optional, and the role's own policy evaluated to allow everything.

The dry runs show how close it was. They passed the same SCP, and the reason is the AMI. The dry runs used Amazon Linux 2023, which is registered with ImdsSupport: v2.0, so an instance launched from it requires IMDSv2 by default and satisfies the condition without the request asking for it. For the real launches the script switched to Ubuntu 22.04, which has no such default, and the request fell back to IMDSv1. Had it launched the AMI it had just dry-run, the SCP would not have said no; the only thing left in the way of a GPU instance was the quota. The SCP that saved me was beaten by the attacker's own dry run and rescued by their choice of operating system.

I didn't want to leave that as an inference, so I reproduced it. With the new EC2 deny in place every launch fails, and a failed dry run returns an authorization message that records the ec2:MetadataHttpTokens value EC2 computed for the request. I dry-ran both of the attacker's AMIs with no metadata options. Amazon Linux 2023 came back required, denied only by the new EC2 deny, so the IMDSv2 policy didn't match it. Ubuntu 22.04 came back optional, denied by both. Before that day, the IMDSv2 policy was the only one of those two that existed, and it would have let the Amazon Linux launch through.

Then the quota. A new account's on-demand GPU quota is zero until you ask AWS for more, and I never had. That would have stopped the p3.2xlarge even with the SCP satisfied. It would not have stopped a CPU miner, and it would not have stopped anything that wasn't EC2.

I'm glad I turned on GuardDuty. Without it, I'd have nothing. The EC2 calls were sitting in CloudTrail, but nothing alerts on them. My posture scanner checks configuration, and the attacker changed none. The credentials expired quietly. I'd have found out from a bill, if they had got an instance, or never.

It also has limits. When I say "as far as the logs can show," I mean that my organization trail records management events only: every EC2 and IAM call that credential made, but no data events, so an S3 GetObject or a DynamoDB read would not appear anywhere. GuardDuty S3 Protection was on and raised nothing else, which is the absence of an alarm, not proof. I've decided not to pay to record data events in these accounts, because nothing in them is sensitive enough. If yours hold customer data, make that call the other way, and make it before you need the answer.

What I changed

The workflow. Every value that comes from the event goes through env: and is read as a quoted shell variable. Bash treats it as data, so a quote in it is just a character. The job also refuses anyone who isn't an owner, member or collaborator:

if: |
  github.event.issue.pull_request &&
  startsWith(github.event.comment.body, 'outcomeops:') &&
  contains(fromJSON('["OWNER","MEMBER","COLLABORATOR"]'),
           github.event.comment.author_association)
...
- name: Invoke Handle Command Lambda
  env:
    COMMENT_BODY: ${{ github.event.comment.body }}
    PR_BRANCH: ${{ steps.pr.outputs.branch }}
  run: |
    COMMAND=$(printf '%s\n' "$COMMENT_BODY" | head -1)

The role. The PR workflows moved to the invoke-only role OutcomeOps already ships. They no longer touch the hub or the admin-equivalent spoke at all.

The hub's trust. I pulled 90 days of AssumeRoleWithWebIdentity events from CloudTrail and listed every subject that had actually used the hub. There were three. One was the repository above, which moved to its own role. One was a private copy of it with the same bug, which I archived. That left one: an end-to-end test suite on main. The trust went from two wildcards to that one exact subject. The wildcard repo:outcomeops/* had zero uses in 90 days. It was attack surface and nothing else.

An SCP that denies EC2 outright. Nothing in my organization runs on EC2. It's all Lambda and Fargate. So the luck in that table is now a rule, attached to every OU:

{
  "Sid": "DenyEC2Compute",
  "Effect": "Deny",
  "Action": [
    "ec2:RunInstances",
    "ec2:RunScheduledInstances",
    "ec2:RequestSpotInstances",
    "ec2:RequestSpotFleet",
    "ec2:CreateFleet",
    "autoscaling:CreateAutoScalingGroup"
  ],
  "Resource": "*"
}

There's no exemption, not even for AWSControlTowerExecution. My first draft had one out of habit. Control Tower never launches an instance, so an exemption would only be a way around the rule that nothing uses. Fargate isn't affected, because SCPs don't apply to service-linked roles. After it was applied, a dry run that the old policies allowed, with IMDSv2 set, returns an explicit SCP deny.

Be clear about what that covers: EC2, and only EC2. A stolen credential with this much access can still rent compute elsewhere. Lightsail is a common target, and so are SageMaker training jobs, Batch, ECS tasks on Fargate, and CodeBuild. I use Fargate and CodeBuild, so those can't simply be denied, and the narrower CI role is the real answer there. Lightsail, SageMaker and Batch I never use, so my first step was to add them to the same unconditional deny.

Adding services to a deny one at a time is still the weaker version, and I know it, because it isn't what I build for clients. Every client landing zone I build gets an SCP called DenyUnapprovedServices. It's an allowlist: it denies every AWS service except the couple of hundred the client has approved, with exceptions only for the named platform roles that run the landing zone itself. A service nobody has thought about yet is denied by default, which is exactly the case where a stolen credential goes shopping for compute.

I didn't build one for myself. When I set up my own organization from the same template, I took that policy out on purpose and never went back. So the afternoon caught me twice: a workflow I'd have flagged in a client's review, and a guardrail I'd have insisted on in theirs. The cobbler's children, as usual, have no shoes.

So I built mine, and I built it from evidence rather than memory. The obvious data source didn't work. IAM can produce an organization-wide report of every service used in the last 400 days, and mine said almost every service in AWS was in use in every account, including ones I've never touched. That's Prowler: a posture scanner reads every service every night, and the report can't tell a scanner from a workload. So I went one level down and pulled last-accessed data for every IAM role and user in the workload accounts, 357 of them, leaving out the scanners and read-only roles. That gave 82 services. Twelve of them had been touched by exactly one principal, an AWS agent I tried once and no longer use, so they went.

Usage data has a blind spot, though. My SSO admin roles were only created when these accounts joined the organization a few months ago, so anything I last deployed before then is invisible. WAF was the proof: five web ACLs in production, and no API call to WAF in the data. So I added every AWS resource type declared in the Terraform of the repositories that deploy into the organization, plus a small operational core (STS, KMS, logging, billing, support). The result is an allowlist of 86 services. Every principal still in use fits inside it, and the policy simulator agrees: a Lambda calling Bedrock is allowed; Lightsail, SageMaker and IoT get an explicit deny, even for me. The scanner and the platform roles that run the landing zone are the only exceptions. The EC2 deny stays alongside it. An allowlist works per service, and EC2 has to be on it because the networking that Lambda and Fargate use lives there, so only the action-level deny stops an instance launching.

The spoke role lost its IAM permissions. The textbook answer here is a permissions boundary, so that roles CI creates can't be more powerful than CI. I won't use them. I ran a large enterprise AWS transformation that leaned on them, and they caused nothing but problems: every team's Terraform has to attach the boundary to every role it creates, forever, and the first time someone forgets, an apply fails with an access-denied error that explains nothing.

I asked a simpler question instead: does anything use this? IAM keeps last-accessed data for every role, down to the action. In production, the spoke had used exactly two services since it was created in October: DynamoDB, from the end-to-end test suite seeding data, and EC2, from the attacker. Never IAM. CloudTrail showed no IAM writes by it in any other account either. The grant that let a stolen credential create an admin role had never been used for anything. I deleted it. Removing a permission nothing uses beats wrapping it in a second policy that every future role has to remember.

The role still has PowerUserAccess for that one test suite, which is far more than seeding a few DynamoDB tables needs. Narrowing it to what the suite actually touches is next.

Even the alerting had a bug

Two different alert paths fired that afternoon. One told me about the attack. The other paged me about an attack that wasn't happening. How each one reached my inbox is worth showing, because the second one failed in a way the first one can't.

Path one: GuardDuty, about 14 minutes

GuardDuty runs in every governed region of every account, with a delegated administrator account that sees all of their findings. The email I got didn't come from there. It came from a small baseline in each workload account:

  1. GuardDuty raises a finding in whichever region the activity happened in.
  2. An EventBridge rule in each region forwards GuardDuty events to a central event bus in us-east-1 in the same account.
  3. A rule on that bus matches findings of severity 4 and up and sends them to an SNS topic.
  4. SNS emails the support inbox with the finding type, severity, region and account.

It worked, and it took about 14 minutes from the first malicious call to the finding. Most of that is GuardDuty: it builds a baseline of each identity's normal behavior and needs a few minutes of events to call something anomalous.

Writing this up, I noticed something I don't like. That whole path, the rules and the topic, lives in the production account. The role the attacker held had PowerUserAccess there, which includes EventBridge and SNS. A human attacker could have deleted the rule or the subscription first and then worked in silence. The finding would still have reached the delegated administrator, but nothing there emails anyone. Quieter still: GuardDuty lets you add suppression filters and trusted IP lists, and an attacker who adds one doesn't need to delete anything. Findings just stop. That path is now protected by its own SCP. Only my SSO admin permission set, which is how I deploy those resources, and Control Tower can change the rules, the topics, their encryption key, or GuardDuty's filters and IP lists. I checked it with the policy simulator both ways: as the CI role it's denied, as me it's allowed.

Path two: CloudTrail into Loki, about 3 minutes

The second alert came from a pipeline I built because GuardDuty doesn't cover everything I care about. Some API calls are dangerous in themselves, whoever makes them and however normal they look. Registering a delegated administrator in AWS Organizations is one: it hands an account organization-wide access to a service. I want to know within minutes, every time. This is how that event gets from AWS to my inbox:

  1. The Control Tower organization trail records every management event in every account and delivers it to a CloudWatch Logs group.
  2. An account-level subscription filter in each account forwards every log group to a cross-account destination in my log aggregation account, one per region.
  3. A Kinesis stream per region sits behind each destination. It's a buffer with 24 hours of retention, not a store.
  4. A small Python shipper on my monitoring box reads the streams, decompresses the CloudWatch payload, labels each line with its account, region and service, and pushes it to Loki. It checkpoints only after Loki accepts a batch, so a restart resumes instead of losing data.
  5. The Loki ruler evaluates the alert queries every minute against the CloudTrail lines.
  6. Alertmanager routes the firing alert to a webhook bridge on the host, which publishes it to an SNS topic in my shared services account, and SNS emails it.

End to end it's fast: about three minutes from the API call to the email. I'd built it to replace a posture check that could never tell my own legitimate delegation apart from an attacker's, and that only ran once a day.

That afternoon it fired, resolved, and fired again: a delegated administrator was registered in the AWS Organization, severity critical. In an afternoon that started with stolen credentials, that is not a page you want. I checked Organizations straight away. The delegated administrators were exactly what they had been since July. Nothing had been registered.

This was the rule:

sum(count_over_time({service="cloudtrail"}
  |= "RegisterDelegatedAdministrator" [10m])) > 0

That's a substring match against the whole CloudTrail record, not against the event name. Both matches were me. I was in the AWS console starting the AFT pipelines that applied the fixes in this post. AFT pulls its repositories through CodeStar Connections, and that call is logged as a UseConnection event whose response includes the repository's recent commit messages. Two of my old commits, from when I set up GuardDuty's delegated administrator, mention RegisterDelegatedAdministrator by name. Each pipeline run put those messages into CloudTrail, and the rule matched my commit history.

There was a second bug in the same pair of rules. The companion alert for removing a delegated administrator matched DeregisterDelegatedAdministrator, which contains the first string. A real deregistration, the one an attacker makes to blind GuardDuty before doing something noisy, would have fired both alerts and reported a registration that never happened.

The fix keeps the substring as a cheap pre-filter, then parses the record and decides on the real field:

sum(count_over_time({service="cloudtrail"}
  |= "RegisterDelegatedAdministrator"
  | json | eventName="RegisterDelegatedAdministrator" [10m])) > 0

A false positive is the safe way for an alert to fail, and I'll take it over silence. But a security alert that cries wolf in the middle of a real incident costs more than an ordinary one. It pulls you off the real work, and the next time it fires you're tempted to assume it's your commits again. The lesson I'd generalize: alert on structured fields, never on strings, because strings show up in places you didn't think to look, like your own commit messages.

Writing it down where the agents read

Fixing this workflow is the easy part. The harder question is how it got written, and how the next one won't be. Most of the code in my repositories is written by Claude Code, and the way I keep it consistent is the thing OutcomeOps is built around: architecture decision records that the agent reads before it writes.

My ADRs live in their own repository. OutcomeOps ingests them into its knowledge base, and Claude Code reaches that knowledge base through the OutcomeOps MCP server. In each project it's one line of setup:

claude mcp add --transport http outcomeops \
  https://<your-outcomeops-host>/mcp/v1 \
  --header "Authorization: Bearer <api-key>"

That gives the agent tools like get_coding_standards and query_knowledge_base. A skill I use for planning calls them up front, before any code is written. It asks "what is our standard for this kind of change," and it pastes the relevant ADR text verbatim into each unit of work, so the agent writing the code has the rule in front of it rather than a link it may never follow. If a query comes back empty, the plan stops. A missing standard is a finding, not a pass.

So I went back and asked what the knowledge base would have told an agent writing this workflow. The answer is worse than nothing.

My CI/CD standard, ADR-007, had a section on invoking the PR analysis Lambda. Its example was this:

run: |
  aws lambda invoke \
    --function-name "$ENVIRONMENT-$APP_NAME-analyze-pr" \
    --payload '{"pr_number": ${{ github.event.pull_request.number }}}' \
    /tmp/response.json

A pull request number is an integer, so that line can't be exploited. But it's the same shape: event data pasted into run:. The PR Commands workflow followed that shape with a comment body, and a comment body can hold anything. The standard didn't just fail to prevent the bug. It modeled it. The section on OIDC said "use OIDC" and nothing about what the role should be allowed to do or who should be able to assume it.

The second gap was coverage. The OutcomeOps MCP server is configured in 18 of my projects. My AWS Account Factory repositories, the ones that hold the hub trust with the PLACEHOLDER comment, aren't among them. The session that wrote repo:bcarpio/*:* had no standards to read at all.

Agents follow the standards you give them, faithfully, including the bad ones. I've written about the good side of that, where one ADR fixed what a model change couldn't and another took a recurring mistake to zero across 226 sessions. This is the other side: the same faithfulness copied a bad example into a workflow strangers could trigger. So I've written a new one. ADR-017 is proposed in my ADR repository, and ADR-017 is what an agent will get next time it asks how to write a workflow:

# ADR-017: GitHub Actions Untrusted Input and CI Identity

## Summary

Every GitHub Actions workflow in this org MUST treat event data as
untrusted input, and every AWS identity a workflow can reach MUST be
scoped to the one job that needs it.

1. Never interpolate ${{ github.event.* }}, or anything derived from
   it, into run:. Pass it through env: and read it as a quoted
   shell variable.
2. Workflows on untrusted triggers gate on author_association before
   any step that receives credentials.
3. One CI role per purpose. A workflow that only invokes something
   gets an invoke-only role. Deploy roles are never reachable from an
   untrusted trigger.
4. OIDC trusts list exact subjects. No wildcards in sub.
5. Allow only the AWS services we use; deny the rest at the org level.

This ADR is security-critical. A change that conflicts with it is a
defect, not a trade-off.

The full ADR lists every event field that counts as untrusted, every trigger a stranger can fire, a checklist for the moment a repository goes public, and the grep and CloudTrail commands to check an existing setup. ADR-007's example now passes the PR number through env: and points to ADR-017 for anything about identity.

Fixing the content was half of it. The MCP connection is now configured once for every repository rather than project by project, so the next session that touches a trust policy, in the infrastructure repositories included, is handed ADR-017 before it writes a line.

If you run GitHub Actions against AWS, check these today

  • Search your workflows for ${{ github.event. inside run:. Comment bodies, issue and PR titles and bodies, branch names, and step outputs built from any of them. Move every one to env:.
  • Look at the sub condition on every OIDC role. If it contains *, find out from CloudTrail which subjects actually use it and list only those. GitHub's OIDC documentation lists the subject formats.
  • For every workflow triggered by issue_comment or pull_request_target, ask what role it can reach. That role is what you're handing the internet.
  • Require approval for workflow runs from all outside contributors, not just first-time ones (repository settings, Actions, "Approval for running fork pull request workflows from contributors"). GitHub's default holds a contributor's first pull request, which is what held the second attempt below. One approved merge, though, and that account's next pull request runs without asking.
  • Before you flip a repository to public, reread every workflow as if a stranger can trigger it. A stranger now can.
  • Deny what you never do with an SCP. Better, allow only the services you use and deny the rest. If a deny needs an exception, make it about who is asking (aws:PrincipalArn), never about what the request says. The caller controls the request, and the IMDSv2 condition that saved me was one AMI choice from letting the launch through, with no extra parameters at all.
  • Test your SCPs against real resource ARNs with aws iam simulate-custom-policy. Pass an allow-all policy as well as the SCP, the way FullAWSAccess sits beside it in Organizations, and look for explicitDeny. On its own a deny-only policy returns implicitDeny for everything, matched or not.
  • Turn on GuardDuty, and decide about data events before you need them.

Epilogue: the second attempt

The same afternoon, while I was still writing this up, a second account opened a pull request from a fork. It was created two weeks earlier, and its PR title carried the same campaign tag the first payload used. This one didn't bother with comments. It added a script and hooked it into two places that run during a build: the first line of a build script, and an npm preinstall hook that runs during npm ci in the UI tests.

The script was more targeted than the first payload. It asked GitHub for an OIDC token, then tried to assume a list of guessed role names, the ones people commonly give a GitHub Actions role, in two accounts. One was my production account. The other was my AWS management account, and that one stopped me, because its ID isn't in any public repository. Every place it appears is private.

Then I remembered the first attacker's failed launch. When an SCP denies a request, AWS's error message names the policy that denied it, in plain text, ahead of the encoded part, and a policy's ARN contains the management account ID and the organization ID: arn:aws:organizations::<management-account>:policy/o-…. The guardrail that stopped the first attempt told the campaign where to aim the second. It wasn't learned any other way: the stolen role could have called organizations:DescribeOrganization, which returns the management account directly, but CloudTrail shows it never did. Every one of its calls was EC2 apart from two identity checks. There's nothing to fix there. Account IDs aren't secrets, and AWS will always say what denied you. What matters is that guessing the right name gets you nothing. No role in my management account trusts GitHub at all, and every role in the organization that does now names exact repositories.

None of it ran. GitHub holds workflow runs from first-time contributors until a maintainer approves them, and both runs sat at action required. Even if I'd clicked approve, workflows on a pull_request from a fork don't get an OIDC token, so the script would have died at its first step. The real risk was a careless click on merge, which would have planted the script in the project's build, to run the next time anyone built it. I closed the PR and reported the account.

Two attempts in one afternoon, from what looks like the same campaign, against a repository that had been public for four days. If you are about to open source something, that is the timeline to plan for.

Closing

Last week I wrote that open sourcing OutcomeOps was about being early again. It turned out to be early in one more way. A bot found a well-documented class of bug in my repository before most people had found the repository.

The bug was ordinary. What made it dangerous was a trust I'd marked as a placeholder and a role that did everything because it was easier. Both were fine while nobody outside could reach them, and that was the whole problem. Open sourcing a repo changes who can reach every workflow in it, all at once, and nothing in the code tells you. I've argued that your pull request is the guardrail. It is, as long as what a pull request can trigger can't be turned against you. On a public repo that's anyone's pull request, and anyone's comment.

GuardDuty told me. Luck did the rest. I'd rather it be design next time, and now more of it is.


Brian Carpio has spent 28 years in technology and 14 building enterprise cloud infrastructure on AWS, and ships AI in production daily. He writes about context engineering, governance, and the operating models that make AI-assisted development hold up at scale.