[英]How to deploy CDK with AWS role from Jenkins?
嗨,我已經用 jenkins 創建了 CDK 項目。 我想使用角色進行部署。 例如帶有角色的 cdk 部署。 例如在 cloudformation 我正在做如下。
cfn_manage deploy-stack \
--stack-name "$CFN_CDK_STACK" \
--template-file "cloudformation/templates/cdk.yml" \
--parameters-file "$PARAMS_FILE" \
--role-name infra-cfnrole-location-nonprivileged
現在我有如下 CDK 項目。
checkout scm
withCredentials([[$class: 'AmazonWebServicesCredentialsBinding',credentialsId: "${env.PROJECT_ID}-aws-${CFN_ENVIRONMENT}"]]) {
abc = docker.build('cdkimage', "--build-arg http_proxy=${env.http_proxy} --build-arg https_proxy=${env.https_proxy} .")
abc.inside{
sh 'ls -la'
sh "bash ./scripts/build.sh"
}
然后在 build.sh 里面
NONPRIV_ROLE_NAME='infra-cfnrole-location-nonprivileged'
aws sts assume-role --role-arn 'arn:aws:iam::id:role/infra-cfnrole-location-nonprivileged' --role-session-name jenkins --query '[Credentials.AccessKeyId,Credentials.SecretAccessKey,Credentials.SessionToken]' --output text
cdk synth
cdk deploy
這是拋出錯誤
An error occurred (AccessDenied) when calling the AssumeRole operation: User: arn:aws:iam::id:user/infra-prjauth-location is not authorized to perform: sts:AssumeRole on resource: arn:aws:iam::187628286232:role/infra-cfnrole-location-nonprivileged
對於受信任關系中的角色 cfnrole-location-nonprivileged 我有以下策略
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "cloudformation.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
有人可以幫我部署角色嗎? 任何幫助,將不勝感激。 謝謝
我認為問題在於您在 IAM 角色的信任關系中沒有特別信任您的 IAM 用戶。
假設此角色具有 CDK 部署所需的正確權限(有關更多信息,請參見此處),您需要允許您的 IAM 用戶訪問該角色,而不是 cloudformation 。 Cloudformation 已經可以訪問您的帳戶資源。
我認為這個版本的信任關系策略應該可以解決問題:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Resource": "<full ARN of the relevant user>",
"Action": "sts:AssumeRole"
}
]
}
讓我知道它是否有效!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.