我正在使用 CDK 創建一個角色,我需要添加sts:SetSourceIdentity到 AssumeRolePolicyDocument。
我的代碼目前看起來像這樣:
new Role(this, 'MyRole', {
assumedBy: new AccountPrincipal(Stack.of(this).account),
...
});
這導致 AssumeRolePolicyDocument 如下所示:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::0123456789012:root"
},
"Action": "sts:AssumeRole"
}
]
}
我需要它看起來像這樣:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::0123456789012:root"
},
"Action": ["sts:AssumeRole", "sts:SetSourceIdentity"]
}
]
}
從上面的 CDK 代碼生成 CloudFormation 的結果如下:
"MyRoleCF2E104D": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Statement": [
{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"AWS": {
"Fn::Join": [
"",
[
"arn:",
{
"Ref": "AWS::Partition"
},
":iam::0123456789012:root"
]
]
}
}
}
],
"Version": "2012-10-17"
},
...
},
我不知道如何將sts:SetSourceIdentity添加到ActionCloudFormation 中。有任何想法嗎?我需要彈出到 L1 構造嗎?
uj5u.com熱心網友回復:
addStatements向角色的承擔角色策略檔案添加新操作:
role.assumeRolePolicy?.addStatements(
new iam.PolicyStatement({
actions: ['sts:SetSourceIdentity'],
principals: [new iam.AccountPrincipal(this.account)],
})
);
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/515189.html
