@@ -25,47 +25,52 @@ module "elastio_asset_account" {
2525resource "aws_iam_role" "admin" {
2626 provider = aws. admin
2727
28- assume_role_policy = data. aws_iam_policy_document . admin_trust . json
29- name = " AWSCloudFormationStackSetAdministrationRole"
30- }
31-
32- data "aws_iam_policy_document" "admin_trust" {
33- statement {
34- actions = [" sts:AssumeRole" ]
35- effect = " Allow"
36-
37- principals {
38- identifiers = [" cloudformation.amazonaws.com" ]
39- type = " Service"
40- }
41-
42- # Conditions to prevent the confused deputy attack
43- condition {
44- test = " StringEquals"
45- variable = " aws:SourceAccount"
46- values = [local . admin_account_id ]
47- }
28+ name = " AWSCloudFormationStackSetAdministrationRole"
4829
49- condition {
50- test = " StringLike"
51- variable = " aws:SourceArn"
52- values = [" arn:aws:cloudformation:*:${ local . admin_account_id } :stackset/*" ]
30+ # Allow assuming for CFN with some `Condition` elements to prevent the confused deputy attack
31+ # as described in AWS docs: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/stacksets-prereqs-self-managed.html#confused-deputy-mitigation
32+ assume_role_policy = jsonencode (
33+ {
34+ " Version" : " 2012-10-17" ,
35+ " Statement" : [
36+ {
37+ " Effect" : " Allow" ,
38+ " Principal" : {
39+ " Service" : " cloudformation.amazonaws.com"
40+ },
41+ " Action" : " sts:AssumeRole" ,
42+ " Condition" : {
43+ " StringEquals" : {
44+ " aws:SourceAccount" : local.admin_account_id
45+ },
46+ " StringLike" : {
47+ " aws:SourceArn" : " arn:aws:cloudformation:*:${ local . admin_account_id } :stackset/*"
48+ }
49+ }
50+ }
51+ ],
5352 }
54- }
55- }
56-
57- data "aws_iam_policy_document" "admin_execution" {
58- statement {
59- actions = [" sts:AssumeRole" ]
60- effect = " Allow"
61- resources = [" arn:aws:iam::*:role/AWSCloudFormationStackSetExecutionRole" ]
62- }
53+ )
6354}
6455
6556resource "aws_iam_role_policy" "admin_execution" {
6657 provider = aws. admin
6758
68- name = " AssumeExecutionRole"
69- policy = data. aws_iam_policy_document . admin_execution . json
70- role = aws_iam_role. admin . name
59+ name = " AssumeExecutionRole"
60+ role = aws_iam_role. admin . name
61+
62+ # Allow assuming the execution role in any (*) account to avoid coupling the
63+ # target accounts with assets with this policy.
64+ policy = jsonencode (
65+ {
66+ " Version" : " 2012-10-17" ,
67+ " Statement" : [
68+ {
69+ " Effect" : " Allow" ,
70+ " Action" : " sts:AssumeRole" ,
71+ " Resource" : " arn:aws:iam::*:role/AWSCloudFormationStackSetExecutionRole"
72+ }
73+ ]
74+ }
75+ )
7176}
0 commit comments