【问题标题】:CloudFormation route53:GetHostedZone User is not authorized to access this resourceCloudFormation route53:GetHostedZone 用户无权访问此资源
【发布时间】:2020-09-11 16:42:14
【问题描述】:

我有一个连接到 Github 存储库的 AWS CodeBuild 项目,并且在每次新提交时,它都会根据预定义的模板创建一个新的 CloudFormation 堆栈。完整模板can be found here

CodeBuild 项目的构建命令如下:

version: 0.2

phases:
  install:
    runtime-versions:
       nodejs: 12
  pre_build:
    commands:
       - NODE_ENV=development npm install
       - npm run makeScriptsExecutable
  build:
    commands:
       - stackName="stack-$CODEBUILD_RESOLVED_SOURCE_VERSION"
       - apiGatewayName="gateway-$CODEBUILD_RESOLVED_SOURCE_VERSION"
       - FUNCTION_NAME="lambda-$CODEBUILD_RESOLVED_SOURCE_VERSION"
       - S3_ASSETS_BUCKET="s3-$CODEBUILD_RESOLVED_SOURCE_VERSION"
       - S3_ASSETS_BUCKET_URI="s3://$S3_ASSETS_BUCKET"
       - DOMAIN_NAME="$CODEBUILD_RESOLVED_SOURCE_VERSION.guacchain.com"
       - BASE_NAME="prod"
       - echo "S3_ASSETS_BUCKET_URI value here:"
       - echo $S3_ASSETS_BUCKET_URI
       - TEMPLATE_URL=https://s3-external-1.amazonaws.com/cf-templates-1npj2t2ifo384-us-east-1/2020146JeV-stack2.yaml
       - aws cloudformation create-stack --stack-name $stackName --template-url $TEMPLATE_URL --parameters ParameterKey=apiGatewayStageName,ParameterValue=$BASE_NAME ParameterKey=lambdaFunctionName,ParameterValue=$FUNCTION_NAME ParameterKey=s3BucketName,ParameterValue=$S3_ASSETS_BUCKET ParameterKey=domainName,ParameterValue=$DOMAIN_NAME ParameterKey=subdomain,ParameterValue=$CODEBUILD_RESOLVED_SOURCE_VERSION --capabilities CAPABILITY_IAM
       - sleep 45
       - sed -i "s/COMMIT_ID/$CODEBUILD_RESOLVED_SOURCE_VERSION/g" .babelrc
       - NODE_ENV=production npm run start
       - NODE_ENV=production npm run build
       - NODE_ENV=production npm run build:server
       - NODE_ENV=production npm run deploy

我目前遇到的问题是,自从添加AWS::Route53::RecordSet 类型的资源后,堆栈创建失败,原因是:API: route53:GetHostedZone User: arn:aws:sts::XXXX:assumed-role/CodeBuildServiceRole/AWSCodeBuild-XXXX is not authorized to access this resource

该资源当前如下所示:

  domainRecordSet:
    Type: 'AWS::Route53::RecordSet'
    Properties:
      AliasTarget:
        DNSName: !GetAtt domainNameResource.DistributionDomainName
        HostedZoneId: !GetAtt domainNameResource.DistributionHostedZoneId
      Type: A
      HostedZoneId: !GetAtt domainNameResource.DistributionHostedZoneId
      Name: !Sub '${subdomain}.guacchain.com'

subdomain 变量作为参数提供给堆栈。引用的domainNameResource 确实在堆栈创建失败之前成功创建:

此外,CodeBuildServiceRole 应用于 CodeBuild 项目。我认为给它 AdministratorAccessAmazonRoute53FullAccessAWSCloudFormationFullAccess 策略就足够了,但显然不是!

在 IAM 权限选项卡上,它显示 Permissions boundary (not set)

在“受信任的关系”选项卡上,“受信任的实体”列表中只有一行:The identity provider(s) codebuild.amazonaws.com。还显示“没有与此角色关联的条件。”

必须对这个 IAM 角色、Codebuild 项目或 CloudFormation 堆栈(或它们的某种组合)执行什么操作才能成功创建 Route53 RecordSet 资源?

【问题讨论】:

  • CodeBuild 创建堆栈是什么意思?您是指具有 CloudFormation 部署操作提供程序的 CodePipeline?
  • 其中一个构建命令是 aws cloudformation create-stack --stack-name $stackName --template-url=... 我将更新问题以提供更多上下文
  • 第二个`HostedZoneId`应该是Route 53中你自己的托管区域的id。目前你正在尝试将你的domainRecordSet添加到AWS控制的托管区域中,因此你得到了错误- 您无权修改 AWS 拥有的托管区域。
  • 就是这样。在阅读了您的原始评论后,我更新了 CF 堆栈,这次成功了。如果您将其发布为答案,我会接受

标签: amazon-web-services amazon-cloudformation amazon-route53


【解决方案1】:

根据 cmets,问题在于第二个 HostedZoneId分配不正确

 HostedZoneId: !GetAtt domainNameResource.DistributionHostedZoneId

应该是OP控制的托管区的id,而不是AWS拥有的CloudFront分布的托管区。这解释了错误消息 - 您无权修改 AWS 拥有的托管区域。

【讨论】:

    猜你喜欢
    • 2018-06-19
    • 2021-05-19
    • 1970-01-01
    • 1970-01-01
    • 2018-11-10
    • 2021-02-15
    • 1970-01-01
    • 1970-01-01
    • 2014-12-12
    相关资源
    最近更新 更多