我的代码构建位于 Account A 和 s3 bucket 位于 Account B 上。我尝试在 Account B 上设置受信任的 IAM STS 角色,并在 Account A 上设置策略以包含 Account B IAM 角色,附上此策略到我的代码构建服务角色。但是,我的代码构建仍然显示了 s3 上的存储桶。我在这里做错了或配置错了吗?
对账户 B 具有信任关系的角色
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::Account:root"
},
"Action": "sts:AssumeRole",
"Condition": {}
}
]
账户 A 的政策
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "sts:AssumeRole",
"Resource": "arn:aws:iam::Account B:role/testcli"
}
]
}
CodeBuild BuildSpec.yml
version: 0.2
env:
variables:
TF_VERSION: "0.12.28"
phases:
install:
commands:
# install required binary
- echo test
pre_build:
commands:
- echo print s3 buckets
- aws s3 ls
post_build:
commands:
- echo test1
最佳答案
假设您的 CodeBuild (CB) 具有 sts:AssumeRole
的权限,在您的 buildspec.yml
中,您必须显式承担角色Acc B.
有两种方法可以做到这一点。
“手动”调用 assume-role在您的
buildspec.yml
中。该调用将返回一组临时凭证。获得的凭证随后可用于从您的 CB 在 Acc B 中执行 AWS CLI 命令。
在这两种情况下,CB 服务角色都需要 sts:AssumeRole
权限。
关于amazon-web-services - AWS codebuild 列出其他帐户的 s3 存储桶,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63699825/