Amazon web services 尽管IAM设置正确,但Beanstalk的代码管道部署失败 上下文

Amazon web services 尽管IAM设置正确,但Beanstalk的代码管道部署失败 上下文,amazon-web-services,amazon-elastic-beanstalk,amazon-iam,aws-codepipeline,aws-codebuild,Amazon Web Services,Amazon Elastic Beanstalk,Amazon Iam,Aws Codepipeline,Aws Codebuild,这最初是一个CodeStar项目,后来它发展成了一个更大的项目。我们重用Beanstalk应用程序来创建stage和prod环境,并保持最初创建的dev环境不变 我们使用“Elastic Beanstalk”作为提供程序更新了CodePipeline以部署到新环境中。(CodeStar使用CloudFormation为其在Beanstalk应用程序中自动配置的环境设置了部署。) 问题 部署失败,原因是出现了一个错误,该错误将自动缩放:descripBeautoScalingGroups称为未被代

这最初是一个CodeStar项目,后来它发展成了一个更大的项目。我们重用Beanstalk应用程序来创建
stage
prod
环境,并保持最初创建的
dev
环境不变

我们使用“Elastic Beanstalk”作为提供程序更新了CodePipeline以部署到新环境中。(CodeStar使用CloudFormation为其在Beanstalk应用程序中自动配置的环境设置了部署。)

问题 部署失败,原因是出现了一个错误,该错误将
自动缩放:descripBeautoScalingGroups
称为未被代码管道的IAM角色授权执行

以下是CodePipeline中显示的整个错误消息:

权限不足

部署失败

提供的角色没有足够的权限:用户: arn:aws:sts::xxx:cod工具链/yyy上的假定角色/CodeStarWorker xxx 未被授权执行:自动缩放:DescribeAutoScalingGroup (服务:AmazonaAutoScaling;状态代码:403;错误代码: 拒绝访问;请求ID:905ee6ef-d75d-4cf8-b5f3-e6b16a5f6477)

服务:AmazonAutoScaling,消息:用户: arn:aws:sts::xxx:cod工具链/yyy上的假定角色/CodeStarWorker xxx 未被授权执行:自动缩放:DescribeAutoScalingGroup

未能部署应用程序

服务:AmazonAutoScaling,消息:用户: arn:aws:sts::xxx:cod工具链/yyy上的假定角色/CodeStarWorker xxx 未被授权执行:自动缩放:DescribeAutoScalingGroup

国际机械师协会 以下是代码管道角色的内容(即cod工具链上的CodeStarWorker xxx):

下面是相关的权限边界(最初由CodeStar生成,最终由我们更新,以使整个过程正常工作):

管道

正如您所看到的,我们有两个代码构建,因为第一个是由CodeStar设置的,第二个是稍微修改输出工件的代码构建,以便以正确的格式直接上传到Beanstalk

成功的部署来自CodeStar(使用CloudFormation提供程序),下一个是失败的部署(使用Beanstalk提供程序)

CodeStar代码构建(
buildspec.yml
) CloudFormation部署使用输出人工制品:

version: 0.2

phases:
  install:
    runtime-versions:
      java: openjdk8
    commands:
      # Upgrade AWS CLI to the latest version
      - pip install --upgrade awscli
  pre_build:
    commands:
      - cd $CODEBUILD_SRC_DIR
      - mvn clean compile test
  build:
    commands:
      - mvn war:exploded
  post_build:
    commands:
      - cp -r .ebextensions/ target/ROOT/
      - aws cloudformation package --template template.yml --s3-bucket $S3_BUCKET --output-template-file template-export.yml
      # Do not remove this statement. This command is required for AWS CodeStar projects.
      # Update the AWS Partition, AWS Region, account ID and project ID in the project ARN on template-configuration.json file so AWS CloudFormation can tag project resources.
      - sed -i.bak 's/\$PARTITION\$/'${PARTITION}'/g;s/\$AWS_REGION\$/'${AWS_REGION}'/g;s/\$ACCOUNT_ID\$/'${ACCOUNT_ID}'/g;s/\$PROJECT_ID\$/'${PROJECT_ID}'/g' template-configuration.json
artifacts:
  type: zip
  files:
    - target/ROOT/**/*
    - .ebextensions/**/*
    - 'template-export.yml'
    - 'template-configuration.json'
# Everything up to that point is the very same as the code from above

artifacts:
  type: zip
  base-directory: 'target/ROOT'
  files:
    - ./**/*
    - .ebextensions/**/*
我们的代码构建(
buildspec two.yml
) 输出人工制品由(失败的)Beanstalk部署使用:

version: 0.2

phases:
  install:
    runtime-versions:
      java: openjdk8
    commands:
      # Upgrade AWS CLI to the latest version
      - pip install --upgrade awscli
  pre_build:
    commands:
      - cd $CODEBUILD_SRC_DIR
      - mvn clean compile test
  build:
    commands:
      - mvn war:exploded
  post_build:
    commands:
      - cp -r .ebextensions/ target/ROOT/
      - aws cloudformation package --template template.yml --s3-bucket $S3_BUCKET --output-template-file template-export.yml
      # Do not remove this statement. This command is required for AWS CodeStar projects.
      # Update the AWS Partition, AWS Region, account ID and project ID in the project ARN on template-configuration.json file so AWS CloudFormation can tag project resources.
      - sed -i.bak 's/\$PARTITION\$/'${PARTITION}'/g;s/\$AWS_REGION\$/'${AWS_REGION}'/g;s/\$ACCOUNT_ID\$/'${ACCOUNT_ID}'/g;s/\$PROJECT_ID\$/'${PROJECT_ID}'/g' template-configuration.json
artifacts:
  type: zip
  files:
    - target/ROOT/**/*
    - .ebextensions/**/*
    - 'template-export.yml'
    - 'template-configuration.json'
# Everything up to that point is the very same as the code from above

artifacts:
  type: zip
  base-directory: 'target/ROOT'
  files:
    - ./**/*
    - .ebextensions/**/*
结论 我不知道部署怎么会失败,因为权限边界和基本IAM角色都提到了
autoscaling:descripebautoscalinggroups

此外,对CodeStar环境的部署运行良好,但部署失败的特定环境来自一个精确的复制(就配置而言)

有什么想法吗

(此外,初始的
dev
环境,就像新创建的
stage
环境一样,甚至没有与之关联的自动缩放组……因此我不知道部署为什么要这样做。)


(我已经查看了S3,以确保部署的两个人工制品具有相同的结构。)

这是一个很难解决的问题,但从我所看到的来看,有两个潜在的问题。一是“DescribeAutoScalingGroups”操作不支持资源级权限,因此它必须是资源的星号,而不是资源arn。您可以尝试删除以下内容:

"Resource": [
                "arn:aws:autoscaling:yyy:xxx:autoScalingGroup:*"
            ]
在权限边界中,并将其替换为

"Resource": [
                "*"
            ]
看看这能否解决问题

其次,“AWSCodeDeployFullAccess”角色在策略中不包含“DescribeAutoScalingGroups”操作。您可能需要替换和/或添加“AWSCodeDeployRole”才能使用该操作。这也许能解决问题

当涉及到权限时,CodeStar项目是相当封闭的,因此扩展项目会变得相当复杂。请点击此处:

在这里:


我现在遇到以下错误:
提供的角色没有足够的权限访问Elastic Beanstalk:您没有访问Amazon S3对象的权限。Bucket='elasticbeanstalk yyy xxx',key='resources/environments/e-mjdwv9ptcz/_runtime/_embedded_extensions/yyy/zzz'。
。。。再说一次,我有合适的IAM。另外,您在哪里发现“DescribeAutoScalingGroups”操作不支持资源级权限?信息在EC2自动缩放文档中,这里:对于后代:我将
自动缩放
操作更改为
*
,并放弃了遵循“最低特权”的东西,并添加了
ec2:
s3:
以及。亚马逊的错误消息不够精确,我无法决定花更多的时间在这上面。