@@ -150,8 +150,12 @@ resource "aws_s3_bucket_inventory" "artifacts" {
150
150
}
151
151
}
152
152
153
- resource "aws_iam_role" "try_builds" {
154
- name = " ${ var . iam_prefix } --try-role"
153
+ data "aws_iam_openid_connect_provider" "gha" {
154
+ url = " https://token.actions.githubusercontent.com"
155
+ }
156
+
157
+ resource "aws_iam_role" "oidc" {
158
+ name = " ${ var . iam_prefix } --role"
155
159
156
160
assume_role_policy = jsonencode ({
157
161
Version = " 2012-10-17"
@@ -160,11 +164,29 @@ resource "aws_iam_role" "try_builds" {
160
164
Effect = " Allow"
161
165
Action = " sts:AssumeRoleWithWebIdentity"
162
166
Principal = {
163
- Federated = " arn:aws:iam::890664054962:oidc-provider/token.actions.githubusercontent.com"
167
+ Federated = " cognito-identity.amazonaws.com"
168
+ }
169
+ Condition = {
170
+ StringEquals = {
171
+ " cognito-identity.amazonaws.com:aud" = " ${ aws_cognito_identity_pool . main . id } "
172
+ // This forces the caller to set the session name according to the caller's run & sha
173
+ " sts:RoleSessionName" = " $${aws:RequestTag/run_id}@$${aws:RequestTag/sha}"
174
+ " aws:RequestTag/repository" = " ${ var . source_repo } "
175
+ // For now only allow new bors & try builds
176
+ " aws:RequestTag/ref" = " refs/heads/automation/bors/try"
177
+ " aws:RequestTag/event_name" = " push"
178
+ }
179
+ }
180
+ },
181
+ {
182
+ Effect = " Allow"
183
+ Action = " sts:TagSession"
184
+ Principal = {
185
+ Federated = " cognito-identity.amazonaws.com"
164
186
}
165
187
Condition = {
166
188
StringEquals = {
167
- " token.actions.githubusercontent. com:sub " = " repo: ${ var . repo } :ref:refs/heads/automation/bors/try "
189
+ " cognito-identity.amazonaws. com:aud " = " ${ aws_cognito_identity_pool . main . id } "
168
190
}
169
191
}
170
192
}
@@ -180,10 +202,8 @@ resource "aws_iam_role" "try_builds" {
180
202
Sid = " ArtifactsBucketWrite"
181
203
Effect = " Allow"
182
204
Resource = [
183
- " ${ aws_s3_bucket . artifacts . arn } /rustc-builds-try" ,
184
- " ${ aws_s3_bucket . artifacts . arn } /rustc-builds-try/*" ,
185
- " ${ aws_s3_bucket . artifacts . arn } /rustc-builds-try-alt" ,
186
- " ${ aws_s3_bucket . artifacts . arn } /rustc-builds-try-alt/*" ,
205
+ " ${ aws_s3_bucket . artifacts . arn } /rustc-builds/$${aws:PrincipalTag/sha}/*" ,
206
+ " ${ aws_s3_bucket . artifacts . arn } /rustc-builds-alt/$${aws:PrincipalTag/sha}/*" ,
187
207
]
188
208
Action = [
189
209
" s3:GetObject" ,
0 commit comments