【发布时间】:2020-01-25 20:21:15
【问题描述】:
我正在尝试使用 AWS 的云开发工具包为我网站的某些子域创建 SSL 证书。问题是我正在使用 AWS Organizations 并且相关资源属于不同的 AWS 账户。我的域的hosted zone 是我们主帐户的一部分,但我正在运行 CDK 以在链接帐户中部署堆栈。这意味着DnsValidatedCertificate class 能够请求新证书(在堆栈回滚后它们仍然在ACM 中可见),但是当它尝试自动创建 DNS 记录时会抛出错误验证请求。
这是错误(我的帐号和堆栈名称已编辑):
5/6 | 22:44:14 | CREATE_FAILED | AWS::CloudFormation::CustomResource | SubSubDomainsCertificate/CertificateRequestorResource/Default (SubSubDomainsCertificateCertificateRequestorResourceBC626C85) Failed to create resource. User: arn:aws:sts::123456789012:assumed-role/MyStack-SubSubDomainsCertificateCertificat-16QRI74P8POO2/MyStack-SubSubDomainsCertificateCertificat-BXZ55WHIH1XC is not authorized to access this resource
new CustomResource (C:\repos\my-project\node_modules\@aws-cdk\aws-cloudformation\lib\custom-resource.ts:92:21)
\_ new DnsValidatedCertificate (C:\repos\my-project\node_modules\@aws-cdk\aws-certificatemanager\lib\dns-validated-certificate.ts:81:29)
\_ new MyStack (C:\repos\my-project\.elasticbeanstalk\api-stack.js:91:25)
以下是相关的 CDK 代码(同样,HZ 和域已编辑):
// Executed with `cdk deploy --profile profileForLinkedAwsAccount`
const hostedZone = route53.HostedZone.fromHostedZoneAttributes(
this,
'MyDomainHostedZone',
{
hostedZoneId: 'Z2ABC1234RYN', // in master AWS account
zoneName: 'mydomain.com.'
}
);
const certificate = new certificatemanager.DnsValidatedCertificate(
this,
'SubSubDomainsCertificate',
{
domainName: `*.demo.mydomain.com`,
hostedZone,
region: 'us-east-1',
validationMethod: certificatemanager.ValidationMethod.DNS // ???
}
);
那么,是否有任何方法可以配置 CDK 以允许 DNS 验证自动发生?还是我需要在第二步中使用不同的配置文件?
编辑:根据 Michael 的建议,我向 master AWS 账户添加了一个名为 LinkedAccountCertValidatorRole 的角色。我附加到角色的托管策略及其信任关系如下所示。不幸的是,我仍然遇到同样的错误。此外,Access Advisor 选项卡表明该角色从未使用过该策略。
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": "route53:ChangeResourceRecordSets",
"Resource": "arn:aws:route53:::hostedzone/Z2ABC1234RYN"
}
]
}
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::123456789012:root"
},
"Action": "sts:AssumeRole",
"Condition": {}
}
]
}
【问题讨论】:
标签: amazon-web-services amazon-cloudformation amazon-iam aws-cdk aws-sts