Open
Description
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?
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
mikeviviani commentedon Nov 4, 2021
Hi,
Looking at your IAM role, I do think your aud is not the correct one.
Based on the documentation ### (https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/configuring-openid-connect-in-amazon-web-services) aud contains your GH Org
"Condition": {
"StringEquals": {
"token.actions.githubusercontent.com:aud": "https://github.com/octo-org",
"token.actions.githubusercontent.com:sub": "token.actions.githubusercontent.com:sub": "repo:octo-org/octo-repo:ref:refs/heads/octo-branch"
Mike
[-]Cannot match actor tagwhen using OIDC[/-][+]Cannot match actor tag when using OIDC[/+]tve commentedon Nov 4, 2021
@mikeviviani yeah, except that documentation is completely wrong... If I remove the "actor" match in my policy and just leave the "aud" match it works (just is insecure). The "sub" match in that documentation isn't even valid json...
(
I don't remember where I got the aud match forEdit: the "sts.amazonaws.com" aud match comes from #280 (comment))sts.amazonaws.com
fromyotixify commentedon Nov 17, 2021
I am having the same issue as well when adding a conditional for the
actor
tag. When I remove the actor tag I have no issues and thesub
conditional works fine, when the actor tag is added into the conditional I get the following error:Policy
yotixify commentedon Nov 17, 2021
Update
After some more testing it looks like the
token.actions.githubusercontent.com:actor
key is either missing or null in the policy condition. I dumped a jwt token from the OIDC connector to verify that theactor
tag was in the jwt from the provider so it is getting passed into aws. However when I change the conditional to aNull
action with a value oftrue
instead of aStringLike
the condition passes and github actions is able to assume the role.Is there something on the AWS side that is dropping that value?
CallumHibbert commentedon Nov 19, 2021
@yotixify I can't even get the
token.actions.githubusercontent.com:sub
condition to work.My solution works without any conditions (big security hole) but as soon as I add a condition on
token.actions.githubusercontent.com:sub
it fails (I'm very sure I have the test value correct).Which version of
aws-actions/configure-aws-credentials
are you referencing? I'm referencing@master
, do you have something else?Thanks.
yotixify commentedon Nov 19, 2021
Im currently referencing master, I am not at my computer but i can provide a cloudformation template example that limits it by repostory name. Not ideal for scalability but works in a pinch. I plan to open a ticket with AWS on this issue in Monday related to the '''actor''' tag.
CallumHibbert commentedon Nov 20, 2021
Thanks for coming back to me. Interesting that you are using
@master
too.Do you happen to know if
repo:my-org-name-here/*
is valid to restrict by Org as a proof of concept (agree that tigher restrictions might make sense in a production implementation)?As far as I can tell that is a valid test value for
token.actions.githubusercontent.com:sub
but it won't work for me.Thanks.
CallumHibbert commentedon Nov 20, 2021
OK, so its case sensitive and that was the problem all along. Thanks.
tve commentedon Nov 21, 2021
What is case-sensitive? Did you get the actor match to work?
CallumHibbert commentedon Nov 21, 2021
Sorry, I should have been clearer, case sensitivity on the
token.actions.githubusercontent.com:sub
match in the AWS conditions that I was having trouble with (bringing me to this thread originally).martijngastkemper commentedon Nov 26, 2021
I mixed up
StringEquals
andStringLike
Doesn't work:
Works:
rsclarke-vgw commentedon Dec 1, 2021
Was there further guidance on getting the
actor
conditional claim to work? I'm equally trying withworkflow
to no avail.mungojam commentedon Feb 10, 2022
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.22 remaining items
SwiftEngineer commentedon Dec 17, 2022
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.
JMoserCricut commentedon Jan 18, 2023
As an alternative to @SwiftEngineer 's workaround, Github does have docs suggesting that for providers that only look at certain wellknown claims for authorization, that we can modify what is passed in the sub claim with some of the other custom claims. This does however seem quite complicated to get setup, and as such I've not tested it myself.
Onderkuru commentedon Jan 21, 2023
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.
unfor19 commentedon May 12, 2023
@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!
lukas-hetzenecker commentedon May 12, 2023
@unfor19 I've noticed that your include_claim_keys are:
"include_claim_keys": ["repo", "context", "actor"]
But in your
"token.actions.githubusercontent.com:sub"
you are only specifying repo and actor, you're missing thecontext
part here.So I think the solution would be to either remove
context
frominclude_claim_keys
, or change your sub comparison to include the context, like (untested):for workflows running from the main branch
unfor19 commentedon May 12, 2023
@lukas-hetzenecker - I think that it means I'm just sending "extra info" from GitHub to AWS; so I'm sending the extra
context
field, though, in AWS Trust Relationship, I'm not filtering bycontext
so it's like "any context is ok", and I'm filtering requests only byrepo
andactor
, so I think it's oklukas-hetzenecker commentedon May 12, 2023
All of the extra information is always part of the JSON Web Token, it is just the AWS does not support custom claims, and therefore cannot use any of that extra attributes (actor, etc.). AWS only allows you to use the
sub
field in your trust relationship for the role.With
include_claim_keys
you then configure what yoursub
field looks like. This is why"token.actions.githubusercontent.com:sub"
is expected to look like"repo:<repo>:<context>:actor:<actor>"
with your configuration. This is also why putting a wildcard ("*") in the place where context is fixes the issue.unfor19 commentedon May 12, 2023
@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
mungojam commentedon May 14, 2023
This 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
peterwoodworth commentedon Aug 24, 2023
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 needs[-]Cannot match actor tag when using OIDC[/-][+]AWS cannot filter for many claim keys in trust policies[/+]job_workflow_ref
issued by GHA while assuming IAM role #912javierlga commentedon Apr 9, 2025
For those who are having problems with this, you have to customize the
sub
claim template, in my case I wanted to verify the actor and repository, so first customize the claims in the repository:Verify the claims are applied:
IAM policy:
After triggering the workflow:
If you want to customize the
sub
claim template with other claim keys be sure to run the actions-oidc-debugger first.