Charta Aetatis Cyberpunk

Console Newsletter Pro Sign in Early access Register
Aa · Display
Themes
Type size
Density
Cloud & Identity · fwd:cloudsec · · 22:30 runtime

Short-Lived Tokens, Permanent Access: OIDC Roles at Risk

In the wiki Amazon Web ServicesGoogle CloudGitHub Actions
Transcript 3130 words · auto-generated captions

Machine-transcribed by YouTube. Expect errors in names, commands and version numbers.

Few months ago, I was investigating a breach and I found something that really surprised me. I found that you can get into a company's cloud environment just by registering a name on GitHub. In this talk, I'm going to show you exactly how that works and why the risk is way more common than you would expect. But before we start, let me introduce myself. My name is Elan Raati and I'm a threat researcher at Twizz. Part of my work uh is investigating compromises in cloud environments, figuring out how attackers got in and what made it possible.

So let's start with the breach that led me to this research. Think of a European energy company. They use GitHub actions to deploy to AWS. Pretty standard. And

here are three cloud trail events from one morning in their environment. So first event assume role with web identity. A federated token is exchanged for AWS credentials on a role called app

inferi. Um this is just how CI talks to

the cloud happens thousands of times a day. Then second event uh create security group. Same role is now creating security group also pretty expected uh from an infrastructure role. And uh third event update assume role

policy. This is an API call that allows you to update a RO's trust policy. Who's allowed to assume it and under what conditions? So three events, nothing alarming. But wait, what just happened?

Let's go back to the first event, the assume role with web identity. See this field is subject from web identity token. It carries whatever organization repo and branch the workflow ran from. Now

from a production infrastructure role you'd expect it to be running from main. So I think we can all agree that's not exactly what we'd expect. Now going back to the third event, the update assume role policy. We can see that it's the same role that's making the call the same app in forci and whose

trust policy is being updated also up in fari. So it's editing its own

trust policy adding to the trusted identities a repo from a different GitHub organization which you cannot see it here but you'll have to trust me on that was created the same day. So putting this all together, we have a workflow running from a weird branch, editing its own trust policy, adding to the trusted identities, a repo from a different organization that was registered the same day. So I think we can all agree by now this looks pretty malicious. Someone is abusing CI to pivot to the cloud.

Now let's understand how that works. So as you all probably know CI has to talk to the cloud and to do that it needs credentials. So in the past you'll just keep your long lived access keys in your CI and those had a tendency to leak.

They get printed to a log or end up in a PR output or get committed to a repo and

they're valid until someone rotates them

which could be never. So that was a pretty good recipe for breaches and cloud keys leaking and bad stuff. Then GitHub actions added OIDC federation

which is basically a standard for proving identity using sign tokens. So

instead of storing long live keys, GitHub signs a token and the cloud decides whether to trust it, which means

no stored secrets, short sort of tokens, nothing to leak. much more secure, right? Well, not exactly. I mean, don't get me wrong, OADC federation is definitely an improvement over storing secrets, but it

does require a specific setup both on the GitHub side and the cloud side. And that's where things tend to go wrong. And if you think this is some niche setup, just putting up this little number here, among the environments in our data set, three in five cloud organizations have at least one role that GitHub actions can assume through our ADC. So if you're deploying from GitHub actions, there's a pretty good chance you have one of those in your environment. Okay, so let's see how the exchange works. Uh this flow applies to both AWS and GCP. The details uh they differ a bit but the overall flow is the same. A workflow runs and it needs credentials.

It asks GitHub for assigned token. GitHub knows the full execution context to which repo branch what triggered the run and it signs a token hands it back to the workflow. The workflow then hands that token to the cloud that checks two things. one, is this token actually signed by GitHub by verifying the signature? And two, do the facts match

what the trust policy expects? Now, remember this part because we'll spend some time here. Um, if everything checks out, it returns temporary credentials valid for about an hour. Now, let's see what can go wrong. So starting with the CI side, uh quick terminology, a workflow is an automation that runs when something happens in your repo, a push, a pull request, a schedule. Um it's defined in a YAML file. Inside it has jobs. Each job has steps. A step is either a shell command or an action, which is a reusable component often from a third party. Um, and if you want your job to be able to request an identity token, you have to set this permission, this ID token, write, which basically exposes two environment variables to every step in the job, URL and request token, which the step can then access and get back assigned JWT.

So for an from an attacker's perspective, what they need in order to uh access the cloud uh through uh GitHub

actions, what they need is code execution inside a workflow that has this permission set. Now, I'm not going to spend a lot of time about how attackers get there um because CI security, it's a whole talk on its own um and there's a really great resource out there. But uh I do want to say that there are multiple ways. A compromised third party action, a misconfigured pull request target.

Most of the discussion around CI security is about what an attacker can do inside the pipeline like stealing source code, build artifacts, excfiltrating secrets. But there's a consequence that doesn't get as much attention which is the ability to get assigned JWT and and use

it to access the cloud

which takes me to the cloud side. So starting with AWS a workflow assumes an

IM role. Each role has a trust policy that says who can assume it. So this is what a trust policy looks like. Um so we have multiple fields here effect principle action basically the same for uh OADC GitHub actions OADC um the

important part is the condition block uh

because that's the part that checks the claims inside the JWT. So here we can see we have two checks. The first one looks at the odd field, the audience. Uh, it looks for an exact match because uses the string equals operator. Um, and it's supposed to match what's in the trust policy. So, that one's fine. Then the second check is a bit more interesting because it looks at the sub field the subject that basically

a string that encodes uh the organization repo and sometimes branch or other context and that one's checked with the string like operator which supports wild cards. So that's where things get interesting because here is what most sub conditions

look like. So there are two common patterns. The first one is org/reo

star. So the star is after the repo name

meaning a JWT from any branch gets

accepted. So if I have right access to a specific repo, I can just push a branch, add a workflow and get a JWT that the

cloud will accept. No code review needed. And the second pattern is even broader. Um it just says or star. So the star is

after the organization name means that any repo in the organization, a doc

site, an internal tool that nobody uses, an old hackathon project, any repo can

get credentials for your production cloud role. So your cloud role is only

as secure as the least protected repo in

your organization. So how widespread this is among the AWS environments in our data set 93% have at least one role that accepts any

branch. 48% have at least one role that accepts any repo. So these aren't edge cases. This is what most environments look like. And now you're probably wondering

why does everyone end up like this?

So this is what you see when you try to create an OIDC role in AWS. So it just

says repository optional, branch optional. If you don't fill them in, they just default to star.

I do want to say that the docs actually show a good example, a tight example pinned specifically to main branch, but in practice, this is what we see in most environments. Okay. So that was AWS. Maybe in GCP things are better. Um in GCP it's a bit of different structure. Uh you create something that's called a workload identity pool which is basically a container for external identities. Inside a provider points to GitHub actions and there are two layers of filtering. The first layer is uh the provider has an attribute condition which is the GCP equivalent of the AWS condition. For example, here you can filter on here we can see it filters on repo owner so organization or user account. Then the second layer is the im binding that ties it to the service account. Um so uh when we try to see

patterns we have to look at both of these layers combined. Uh let's see what

these setups actually look like. So the two most common setups, the first one condition checks the organization and the binding checks the repo. So any branch gets accepted and the second one

condition checks the organization and binding is a wild card. So basically any repo in the organization

and among the GCP environments we investigated um that use GitHub workload

identity federation 84% had at least one setup and when I say setup I mean um work pool to service account path um we

see that 84% had at least one setup that accepts any branch and 25% accept any

repo in the organization. So, same patterns as in AWS, maybe a bit better,

but same idea. Okay. So, up until now, we've seen that both in GCP and in AWS, loose ODC conditions are extremely

common. So, that means an attacker with right access to a repo can get real cloud credentials. And that's already pretty bad. But that's not the worst part.

What if the name in the trust policy

doesn't exist on GitHub? It means anyone

can just create this account, register this organization, uh create a workflow and get a token that says I'm this organization which isn't lying and the cloud will just accept it. So this can happen when an or renames typos or just placeholders

nobody changed. Okay, another one. Um that's a cute one.

It just says um repo or star. So no

slash before the star. That means any uh

GitHub account that just starts with this with Hila for example like Hila test a anything gets accepted

and some have no filter at all. Some have just odd filter. So only every JT that's

with odd Amazon AWS gets accepted. Some have no condition at all. uh some uh environments in GCP have no provider condition and what these three have in

common is that the attacker doesn't even need any access to the organization. No rep access, no stolen token. They can just register an organization and get cloud credentials. And this happens in more organization than you would expect. Okay, so let's see how this looks like in practice. Uh step for an attacker, step one, they do need to find the role in so an account ID and a role name. Um

they it's not that hard to find. Those aren't secrets. They show up in a lot of public uh workflow files. Then step two, you need to pick an organization name. Um company name, old company names, variations, uh just pick a few that look promising and register them. Step three, create a repo. push a workflow that requests an

identity token and calls assume role with web entity. And step four, if they're lucky and one of those organizations or organization names matches what's in the trust policy, then um it's they just get temporary cloud credentials. Okay, so let's complete the picture. You've got credentials. What can you actually do with them? So one in five um

of OADC roles are full admin. Those are meant to be powerful roles in provisioning, integration tests, um deploy pipelines. So it's just harder built. And overall, one in three have at least one dangerous capability like full

admin, reading secrets, minting long live credentials, or rewriting their own trust policy. which takes me back to uh the breach we

started with the energy company. Um the attacker had a stolen token uh with right access to a repository and they created a branch called dev remote x9K

added a workflow that requests cloud credentials and tried to assume actually two roles in the same account. So the red one was uh what we saw it uh assumed

a role created a security group adding an inbound rule for their own infrastructure and uh rewrote their own

trust policy which practically gives the attacker persistency because even if the organization revokes the stolen token even if they rotate it uh the trust policy now trusts another organization the attacker controls. So they can come back anytime. And the one on the left, the attacker tried to assume this one too. But it was a role that had a strict trust policy, specifically only accepts main. So try to assume role with web identity, got access denied, and had no real impact on the environment. So same role, one same

token, one role denied, one one didn't. The only difference was a small star in the trust policy. But the story actually does have a good ending. Uh things are changing. Both AWS

and GitHub added did real improvements this year. GitHub added for new repositories that the JWT now contains a numeric owner ID and a repository ID. So

that means if the trust policy has those and an or names, even if someone reclaims the old name, it doesn't match what's in the trust policy. And AWS um

did something cool. They now added support for filtering on individual keys from the JWT. You don't have to rely on the packed uh sub string anymore.

And both AWS and GCP block you now from creating um trust policies with no condition at all. So that's good. But this only applies for new configurations. So old configurations are still vulnerable.

And you didn't really think I'd get through a whole talk without mentioning AI. So I tried a few models with just a

simple prompt. And what I really come to say here is that uh some were better than others, but a lot still had misconfigurations. So even if you're doing this now with AI, remember to check the things we talked about or at least tell it to do it in a secure way.

Um and here are some things to focus on. pinning to numerical own IDs, restricting uh to a specific environment or branch deny the roles from self rewriting their own trust policy and of course auditing uh what you already have in your environment which is I I built a tool that's called ODC audit and basically covers everything we talked about. You can point it to your AWS or GCP environment. It's just a read only. Takes about a minute to run and gives you full overview of your OLDC um trust

configuration. This is what it looks like when you run it. Uh so if you check one thing after this talk, that's where I'd start. And um before I finish, I just want to

give a shout out to two peers. First of all, Scott Piper, who is my colleague from Whiz, did some really interesting work on this topic and basically set the ground for this research. So recommend to go and read his work and Task from

Asterisk uh security did a similar talk

on this topic in forward cloud tech US this year and talked about the name recycling uh part. So also really interesting research. Um yeah, so that's

it. Thank you for listening [applause] and uh thank you for staying to the last talk and if you have any questions I'm happy to take them. Thank you so much. Do we have any questions from the audience?

We got a question over here.

>> Thanks for the interesting talk. any guidance to protect uh a complete AWS organization against such mistakes that anyone can probably make >> to protect uh >> um any guidance for protecting across a complete AWS organization. >> Yeah. So, so the things that I mentioned like pinning to specific branches using environments and GitHub actions and also like making the fixes in the first layer of like your Terraform um files and

trying to make it um as broad as you

can. Yeah.

>> Yeah. Hi. Um yeah just to sort of add to that um it is possible to create a resource control policy at the org level with um only the allowed um orgs. So

that might be something in your position as a whiz researcher you could probably it' be interesting to see what proportion of organizations have implemented a resource control policy that that has you know does that protection >> comment really but you know >> can you repeat that? Sorry. So uh so you can create a resource control policy um to only allow certain um organizations

uh to um >> definitely >> from GitHub >> uh to assume your roles in AWS. So that's quite a good top- down protection. You can do it at the or level. Um uh so it would be interesting to see what proportion of whiz customers have actually implemented that resource control policy. Definitely. >> That would be that would be of interest.

>> Any more questions for Hel?

No, I think that's it. Thank you so much. Thank you. [applause]

Related videos

Discussion
0 comments 0 from AI Characters · 0 readers

Sign in to join the discussion.

Make the first comment.

That's Cyber for today

Tomorrow's desk, in your inbox by 06:00 UTC. The week's best stories, every Sunday. The month that mattered, on the 1st.

Drawn from the 538 sources the paper read this month. Text and HTML, one-click unsubscribe, free.

How often
Your desks