-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip! GitHub OIDC → Cognito Identity → AssumeRoleWithWebSession
Let's us map GitHub token claims to principal tags, which is great. But ultimately not workable because GitHub OIDC doesn't include the repository name _sans_ owner in its token claims (e.g. "zika" for "nextstrain/zika"), so we don't have any policy variable to interpolate into policy conditions. I thought maybe we could (ab)use role session names for this and pass the unqualified repo name via it ourselves, but that hit a wall because while sts:RoleSessionName is available in the AssumeRoleWithWebIdentity request, it's not available on subsequent requests which we need to be able to use in policy conditions. Then I thought maybe we could use sts:SourceIdentity instead in the role assumption request which is available as aws:SourceIdentity in subsequent requests, except that GitHub's token would have to include an "https://aws.amazonaws.com/source_identity" claim, and it ofc does not provide any way to do that. If it did, it would likely also let us provide a custom "https://aws.amazonaws.com/tags" claim at which point all of this nonsense would be moot anyway. Finally, I thought maybe we could use a custom audience ("aud" claim) which GitHub _does_ let you specify. This is available in AWS requests as the "token.actions.githubusercontent.com:aud" key and we can use it as a policy variable. \o/ But to use it we'd need to cut out Cognito Identity (e.g. go back to where we started without it) and lose the token claims → principal tags mapping. So we'd need to customize the GitHub token's "sub" claim and match against it. We'd also need to explicitly list out all possible valid "aud" on the AWS OIDC IdP configuration (as "client_id_list"), and that would be frustrating. This all feels more complex than it's worth at this point.
- Loading branch information
Showing
4 changed files
with
123 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# XXX FIXME: describe what we're doing here | ||
# <https://catnekaise.github.io/github-actions-abac-aws/cognito-identity/> | ||
# <https://catnekaise.github.io/github-actions-abac-aws/detailed-explanation/> | ||
# <https://awsteele.com/blog/2023/10/25/aws-role-session-tags-for-github-actions.html> | ||
resource "aws_cognito_identity_pool" "github-actions" { | ||
identity_pool_name = "github-actions" | ||
allow_unauthenticated_identities = false | ||
allow_classic_flow = true | ||
openid_connect_provider_arns = [aws_iam_openid_connect_provider.github-actions.arn] | ||
} | ||
|
||
resource "aws_cognito_identity_pool_provider_principal_tag" "github-actions" { | ||
identity_pool_id = aws_cognito_identity_pool.github-actions.id | ||
identity_provider_name = aws_iam_openid_connect_provider.github-actions.id | ||
use_defaults = false | ||
principal_tags = { | ||
# tag name = OIDC token claim | ||
repository_owner = "repository_owner" | ||
repository = "repository" | ||
job_workflow_ref = "job_workflow_ref" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.