Amazon web services AWS cfn init是否需要DescripteBackResource的配置文件/角色?

Amazon web services AWS cfn init是否需要DescripteBackResource的配置文件/角色?,amazon-web-services,amazon-ec2,amazon-cloudformation,Amazon Web Services,Amazon Ec2,Amazon Cloudformation,从第页开始: 要使用AWS CloudFormation引导功能,您需要向 引导脚本。强烈建议您在EC2实例上为分配IAM角色 当实例启动时 这看起来很简单,但当我查看AWS文档中的所有示例时,他们从未为此设置角色或配置文件。例如 我错过了什么?是否存在cfn init需要额外权限而不需要其他权限的情况?clou init脚本需要连接到AWS服务以检索您在cfn模板中提供的元数据 为了连接到AWS服务,您可以直接将访问/密钥传递给cfn init脚本,或者将具有必要权限的IAM角色附加到EC2实

从第页开始:

要使用AWS CloudFormation引导功能,您需要向 引导脚本。强烈建议您在EC2实例上为分配IAM角色 当实例启动时

这看起来很简单,但当我查看AWS文档中的所有示例时,他们从未为此设置角色或配置文件。例如


我错过了什么?是否存在cfn init需要额外权限而不需要其他权限的情况?

clou init脚本需要连接到AWS服务以检索您在cfn模板中提供的元数据

为了连接到AWS服务,您可以直接将访问/密钥传递给cfn init脚本,或者将具有必要权限的IAM角色附加到EC2实例,以便cfn init脚本使用IAM角色连接到AWS服务

请进一步阅读:


cfn init提供的所有示例都假定您已将IAM角色附加到实例,因此无需将访问/保密密钥直接传递给cfn init脚本。

否,为了访问cloudformation元数据,您不再需要将cloudformation:DescribeSackResource添加到与实例概要文件关联的角色的任何策略中。诸如cfn get metadata和cfn init之类的脚本是使用一个特殊的cfn头而不是标准来授权的。来自CFN脚本的请求如下所示:

# This command succeeds regardless of your instance profile
cfn-get-metadata --region us-west-1 --stack cftest --resource LaunchConfig  --key AWS::CloudFormation::Init

GET /?Action=DescribeStackResource&StackName=cftest&Version=2010-05-15&ContentType=JSON&LogicalResourceId=LaunchConfig HTTP/1.1
Host: cloudformation.us-west-1.amazonaws.com
Connection: keep-alive
Accept: application/json
Accept-Encoding: gzip, deflate
Authorization: CFN_V1 ewogICJwcml2YXRlSX(truncated)==:b9ZM3/EnzeX(truncated)=
User-Agent: CloudFormation Tools
# This command fails if you don’t have cloudformation:DescribeStackResource permission!
aws cloudformation --region us-west-1 describe-stack-resource --stack-name cftest --logical-resource-id LaunchConfig

POST / HTTP/1.1
Host: cloudformation.us-west-1.amazonaws.com
Accept-Encoding: identity
Content-Length: 95
X-Amz-Date: 20160630T010040Z
User-Agent: aws-cli/1.10.43 Python/2.7.11+ Linux/4.4.0-28-generic botocore/1.4.33
X-Amz-Security-Token: FQoDY(truncated-token)=
Content-Type: application/x-www-form-urlencoded
Authorization: AWS4-HMAC-SHA256 Credential=ASIA(truncated)/20160630/us-west-1/cloudformation/aws4_request, SignedHeaders=host;x-amz-date;x-amz-security-token, Signature=fbad7aeef75186cb18bbd44810c4d0379d7d1cf1b8a80be14ea1e3192d2ec531

Action=DescribeStackResource&StackName=cftest&Version=2010-05-15&LogicalResourceId=LaunchConfig
CFN授权头是和的串联,只允许实例从自己的堆栈中查看CloudFormation元数据

相反,使用实例配置文件的请求如下所示:

# This command succeeds regardless of your instance profile
cfn-get-metadata --region us-west-1 --stack cftest --resource LaunchConfig  --key AWS::CloudFormation::Init

GET /?Action=DescribeStackResource&StackName=cftest&Version=2010-05-15&ContentType=JSON&LogicalResourceId=LaunchConfig HTTP/1.1
Host: cloudformation.us-west-1.amazonaws.com
Connection: keep-alive
Accept: application/json
Accept-Encoding: gzip, deflate
Authorization: CFN_V1 ewogICJwcml2YXRlSX(truncated)==:b9ZM3/EnzeX(truncated)=
User-Agent: CloudFormation Tools
# This command fails if you don’t have cloudformation:DescribeStackResource permission!
aws cloudformation --region us-west-1 describe-stack-resource --stack-name cftest --logical-resource-id LaunchConfig

POST / HTTP/1.1
Host: cloudformation.us-west-1.amazonaws.com
Accept-Encoding: identity
Content-Length: 95
X-Amz-Date: 20160630T010040Z
User-Agent: aws-cli/1.10.43 Python/2.7.11+ Linux/4.4.0-28-generic botocore/1.4.33
X-Amz-Security-Token: FQoDY(truncated-token)=
Content-Type: application/x-www-form-urlencoded
Authorization: AWS4-HMAC-SHA256 Credential=ASIA(truncated)/20160630/us-west-1/cloudformation/aws4_request, SignedHeaders=host;x-amz-date;x-amz-security-token, Signature=fbad7aeef75186cb18bbd44810c4d0379d7d1cf1b8a80be14ea1e3192d2ec531

Action=DescribeStackResource&StackName=cftest&Version=2010-05-15&LogicalResourceId=LaunchConfig
实例配置文件临时凭据是从中获取的,如中所述

(注意:为了收集这些请求,我运行了
nc-l80&
并运行了
cfn get metadata--urlhttp://localhost
aws——端点urlhttp://localhost


此CFNSigner功能已添加到aws-cfn-bootstrap-1.1(2012-03)和aws-cfn-bootstrap-1.3.6(2012-09)之间的客户端。在2012年之前,您确实需要使用具有cloudformation:DescribeSackResource权限的角色,如本2011年文档所述。注意,只有cfn-*脚本使用CFNSigner;如果您想使用aws cloudformation,您需要确保您的角色允许它。

情况似乎并非如此。可以通过IAM角色或显式凭据在没有任何权限的情况下使用
cfn get metadata
。但是,如果您对
aws cloudformation描述堆栈资源
执行相同的操作,它将失败。