Skip to content

Commit f00f327

Browse files
Updated roles and polices to match required permissions and resources, using web identity
1 parent 44ae9a0 commit f00f327

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

infrastructure/cloudwatch_rum.tf

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,15 @@ resource "aws_iam_role" "cognito_unauth_role" {
3131
Principal : {
3232
Federated : "cognito-identity.amazonaws.com"
3333
},
34-
Action = "sts:AssumeRole"
34+
Action = "sts:AssumeRoleWithWebIdentity",
35+
Condition = {
36+
StringEquals = {
37+
"cognito-identity.amazonaws.com:aud" = "${local.current_region}:${aws_cognito_identity_pool.rum_identity_pool[0].id}"
38+
},
39+
"ForAnyValue:StringLike" = {
40+
"cognito-identity.amazonaws.com:amr" = "unauthenticated"
41+
}
42+
}
3543
}
3644
]
3745
})
@@ -41,19 +49,16 @@ resource "aws_iam_policy" "cognito_access_policy" {
4149
name = "${terraform.workspace}-cognito-access-policy"
4250
description = "Policy for unauthenticated Cognito identities"
4351

44-
policy = jsonencode({
45-
Version = "2012-10-17",
46-
Statement = [
47-
{
48-
Effect = "Allow",
49-
Action = [
50-
"mobileanalytics:PutEvents",
51-
"cognito-sync:*",
52-
"cognito-identity:*",
53-
],
54-
Resource = "*"
55-
}
56-
]
52+
policy = jsonencode(
53+
{
54+
"Version" : "2012-10-17",
55+
"Statement" : [
56+
{
57+
"Effect" : "Allow",
58+
"Action" : "rum:PutRumEvents",
59+
"Resource" : "arn:aws:rum:${local.current_region}:${local.current_account_id}:appmonitor/${terraform.workspace}-app-monitor"
60+
}
61+
]
5762
})
5863
}
5964

@@ -125,4 +130,4 @@ resource "aws_rum_app_monitor" "app_monitor" {
125130
tags = {
126131
ServiceRole = aws_iam_role.rum_service_role.arn
127132
}
128-
}
133+
}

0 commit comments

Comments
 (0)