Amazon cloudformation 基于模板url的云信息访问控制

Amazon cloudformation 基于模板url的云信息访问控制,amazon-cloudformation,amazon-iam,Amazon Cloudformation,Amazon Iam,我目前正在学习一门使用AWS EMR的课程。每次我想使用EMR时,我都必须启动一个.sh脚本(我们称之为launch.sh),它基本上是启动一个cloudformation模板(我们称之为cf.json)。launch.sh中有一个template\uURL变量,该变量将其指向s3(cf.json)中的json文件,其中包含http端点 我有权限写入和读取该存储桶(而不是删除/附加acl)。我成功地创建了cf.json的副本,我称之为cf2.json。然而,当我将launch.sh指向cf2.j

我目前正在学习一门使用AWS EMR的课程。每次我想使用EMR时,我都必须启动一个.sh脚本(我们称之为
launch.sh
),它基本上是启动一个cloudformation模板(我们称之为
cf.json
)。
launch.sh
中有一个
template\uURL
变量,该变量将其指向s3(
cf.json
)中的json文件,其中包含http端点

我有权限写入和读取该存储桶(而不是删除/附加acl)。我成功地创建了
cf.json
的副本,我称之为
cf2.json
。然而,当我将
launch.sh
指向
cf2.json
时,我得到了权限拒绝错误

你知道这是什么原因吗?CloudInformation中是否有关于
模板\u url
的权限控制

这是我得到的错误。我屏蔽了日志中的所有细节,以防止隐私问题

An error occurred (AccessDenied) when calling the CreateStack operation: User:
 arn:aws:sts::12345678:assumed-role/CrossStack-IamRole-
ABCDEFGH/i-0123456 is not authorized to perform:
 cloudformation:CreateStack on resource: arn:aws:cloudformation:us-east-
1:12345678:stack/student-emr/*
但是,当我使用原始url时,我收到一条成功消息:

Creating EMR Cluster. This will take about 15 minutes...
{
    "StackId": "arn:aws:cloudformation:us-east-1:12345678:stack/student-emr/some-hash-id"
}
这是
launch.sh中的脚本

aws cloudformation create-stack --region $emr_region --stack-name $stackname \
    --template-url $template_url \
    --parameters ParameterKey=Owner,ParameterValue=$student_id \
    --role-arn $cf_role_arn
我更改了
$template\u url
变量的值

注意


这两个.json文件(
cf.json
&
cf2.json
)都没有
公共读取
ACL,我已通过尝试从我的个人计算机复制该文件确认了这一点,在尝试执行
s3 cp

时返回403。我在AWS文档中找到了它

您可以在IAM角色中强制使用模板url

{
    "Version":"2012-10-17",
    "Statement":[{
        "Effect": "Deny",
        "Action": [
            "cloudformation:CreateStack",
            “cloudformation:UpdateStack”
        ],
        "Resource": "*",
        "Condition": {
            "StringNotEquals": {
                "cloudformation:TemplateURL": [
                    "https://s3.amazonaws.com/cloudformation-templates-us-east-1/IAM_Users_Groups_and_Policies.template"
                ]
            }
        }
    },
    {
        "Effect": "Deny",
        "Action": [
            "cloudformation:CreateStack",
            "cloudformation:UpdateStack"
        ],
        "Resource": "*",
        "Condition": {
            "Null": {
                "cloudformation:TemplateURL": "true"
            }
        }
    }]
}