configure-aws-credentials: AWS cannot filter for many claim keys in trust policies
I’m trying to match the GITHUB_ACTOR in my IAM trust relationship policy and cannot make it work. Is this supposed to work? The trust policy I have is:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Federated": "arn:aws:iam::00000000:oidc-provider/token.actions.githubusercontent.com"
},
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringEquals": {
"token.actions.githubusercontent.com:actor": "tve",
"token.actions.githubusercontent.com:aud": "sts.amazonaws.com"
}
}
}
]
}
The error I get is:
Run aws-actions/configure-aws-credentials@master
Error: Not authorized to perform sts:AssumeRoleWithWebIdentity
In my workflow I print ${{ github.actor }}
and it matches what I have in the trust policy. Is there a way to get a log of the actual JWT token that IAM receives?
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 12
- Comments: 36 (4 by maintainers)
Commits related to this issue
- Try to be specific to grant just this repo permissions Note that I seem to be having to abuse the `repositories` field a bit (is this field badly named?) in order to get this `repo:guardian/facia-sca... — committed to guardian/facia-scala-client by rtyley 2 years ago
- Add Continuous Integration (CI) as GitHub Action Running the tests for this project requires read access to s3://facia-tool-store/DEV/, so we need to provide the GitHub Action with AWS credentials fo... — committed to guardian/facia-scala-client by rtyley 2 years ago
- Add Continuous Integration (CI) as GitHub Action Running the tests for this project requires read access to s3://facia-tool-store/DEV/, so we need to provide the GitHub Action with AWS credentials fo... — committed to guardian/facia-scala-client by rtyley 2 years ago
- Add Continuous Integration (CI) as GitHub Action Running the tests for this project requires read access to s3://facia-tool-store/DEV/, so we need to provide the GitHub Action with AWS credentials fo... — committed to guardian/facia-scala-client by rtyley 2 years ago
I mixed up
StringEquals
andStringLike
Doesn’t work:
Works:
Reopening for visibility, but more importantly to track that this issue is related to a limitation in AWS (maybe we can push this internally)
I think this covers the supported token fields:
https://docs.aws.amazon.com/en_en/IAM/latest/UserGuide/reference_policies_iam-condition-keys.html#condition-keys-wif
Google brought me here. Thanks @mungojam for finding the AWS documentation on a list of supported claims.
The GitHub doc should be improved because
ForAllValues:StringEquals
is an insecure operator forAllow
statements. A non-existent / non-supported key (such asrepository_owner
) always evaulates totrue
. This makes ALL GitHub users be able to assume your IAM role.One should always use
StringEquals
orStringLike
. This way, even they accidentally specified an unsupported key, they will immediately find that out, instead of thinking “it works”, while actually letting everyone in.We now have a section in our docs with what’s now the most up-to-date information on the topic. Being able to customize the
sub
claim key should be able to help with most customization needsThis snippet might be useful for anyone getting this working. It will print out all the info in the token. Just use it in a private repo and not in a live setting though
@lukas-hetzenecker You are right! I’ve just tested the following-
.input.json
And AWS Trust Relationship -
repo:unfor19/gha-play-private:actor:unfor19
Thanks for the tip, updated my solution
@JMoserCricut I tried what you offered, and it seems to be working 😄
Here’s my setup-
unfor19-gha-play-private
token.actions.githubusercontent.com
sts.amazonaws.com
unfor19-gha-play-private-policy
unfor19-gha-play-private-role
) with the following trust relationship and assigned the above IAM Policy to itCreated input file for PUT request body -
.input.json
Used GitHub REST API to PUT custom subject OIDC claims
Used GitHub REST API to get GET custom subject OIDC claims (to verify)
Response:
So far, I’m all set; now it’s time to set the workflow-
.github/workflows/oidc.yml
The above setup works; @lukas-hetzenecker, thanks for the tip!
Arkadaşlar siz uçmuşssunuz bilmiyorum sizi yakalayabilirmiyimde inanın doktorların yazdığı reçete gibi konuşuyorsunuz. Hiç bir kelimenizi anlayamıyorum. Bari konudan bahsederken ne işe yaradığını düzeltme veya kodu yazınca nasıldı hangi işi pratikte görebileceğini bunlarıda açıklarsanız inanın sevinirim.
Hi y’all 👋 Just wanted to let y’all know there’s a workaround for this issue, but it comes with some big caveats, namely, the fact that you’ll need to utilize AWS Cognito rather than STS directly, which means it would almost certainly require some changes to this project in order to get working (disclaimer: I don’t actually use this Github Action, I was just pointed here by an altruistic coworker).
In a nutshell, the idea is this:
arn:aws:iam::00000000:oidc-provider/token.actions.githubusercontent.com
)Now you’ll have to actually interface with AWS Cognito instead of just straight up going straight to STS. It’s a quick 1-2 punch that goes like this:
Again, this would almost certainly require changes to this project, but I thought it’d be worth offering up as a potential workaround if anyone felt particularly ambitious! I tested to make sure all of this works using the AWS CLI and I can confirm that it does, albeit with a bit of additional cost to the user.
Woops, you are correct! ForAllValues behaves as you said.
After testing more thoroughly, I could not find a way to make it work correctly with
repository_owner
. I ended up having to switch to usingStringLike
with thesub
claim. There is definitely something wrong here.I think it isn’t doing what you think it is. Try changing the owner condition to something random and it will still let you in (so you are currently very insecure).
From the AWS Docs:
I think it is for testing a different type of request that has multiple sets of key/values in. The name seems really confusing.
I’m having the same problem with
token.actions.githubusercontent.com:repository_owner
. To me it seems that it’s a bug in AWS itself. I can see the property in the token itself when I decode it, but IAM doesn’t appear to think it exists. You can verify that by changing the condition toStringEqualsIfExists
which then passes because IAM doesn’t see it for some reason.