forked from rust-lang/simpleinfra
-
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.
Limit write access to specific prefix
This uses Cognito as a dispatch authority to convert OIDC claims to IAM condition values, and then fitlers the resulting role to only writing into the passed sha. See https://awsteele.com/blog/2023/10/25/aws-role-session-tags-for-github-actions.html for some related context.
- Loading branch information
1 parent
349d0fd
commit 0906539
Showing
2 changed files
with
51 additions
and
8 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
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,23 @@ | ||
resource "aws_cognito_identity_pool" "main" { | ||
identity_pool_name = "${var.iam_prefix}--rustc-ci" | ||
allow_classic_flow = true | ||
allow_unauthenticated_identities = false | ||
openid_connect_provider_arns = ["${data.aws_iam_openid_connect_provider.gha.arn}"] | ||
} | ||
|
||
resource "aws_cognito_identity_pool_provider_principal_tag" "gha_mapper" { | ||
identity_pool_id = aws_cognito_identity_pool.main.id | ||
identity_provider_name = data.aws_iam_openid_connect_provider.gha.arn | ||
use_defaults = false | ||
|
||
// This maps the claims on the left (from GHA, see https://token.actions.githubusercontent.com/.well-known/openid-configuration) | ||
// to "RequestTag"'s on the right. These are then matchable in the AssumeRole policy. | ||
principal_tags = { | ||
actor = "actor" | ||
workflow_sha = "sha" | ||
run_id = "run_id" | ||
event = "event_name" | ||
ref = "ref" | ||
repository = "repository" | ||
} | ||
} |