ACM 证书跨账户 DNS 验证

发布于 2025-01-11 06:06:22 字数 2581 浏览 0 评论 0原文

我有 2 个 AWS 账户:devprod

prod 帐户中,我设置了一个 DNS 域 (example.com),以及 2 个公共托管区域:example.com 和 <代码>prod.example.com。 2 还为这些域 internal.prod.example.comeks.prod.example.com 颁发了 ACM 证书。这些证书已由 DNS 正确验证。

dev 帐户中,我创建了 2 个公共托管区域:dev.example.comexample.com。我为 internal.dev.example.comeks.dev.example.com 颁发了 2 个 ACM 证书,据我所知,需要使用 DNS 进行验证prod 帐户。

这些证书处于待处理状态。

我如何验证它们?

到目前为止我所做的:

  • 我在 example.comprod 帐户中添加了一条名为 dev.example.com 的 NS 记录托管区。 NS 记录的值是在 dev 帐户中创建的 dev.example.com 托管区域的值。这是在 prod 中委托 R53 托管区域的所有权。请参阅此处< /a>.

  • dev 帐户中,ACM 请求的域的 CNAME 已添加到 dev.example.com 托管区域中验证。

以下代码是如何在产品帐户上完成(和工作)的。

注意 - 这是我接管的代码,所以我不知道是否采取了任何手动步骤。

data "aws_route53_zone" "dns-zone" {
  name = "${var.environment}.${var.zone_name}"
}

resource "aws_acm_certificate" "cert" {
  domain_name       = "*.${var.environment}.${var.zone_name}"
  validation_method = "DNS"
  subject_alternative_names = list("*.internal.${var.environment}.${var.zone_name}", "*.eks.${var.environment}.${var.zone_name}")

  lifecycle {
    create_before_destroy = true
    prevent_destroy = true
  }
}

resource "aws_route53_record" "cert_validation" {
  for_each = {
    for dvo in aws_acm_certificate.cert.domain_validation_options : dvo.domain_name => {
      name    = dvo.resource_record_name
      record  = dvo.resource_record_value
      type    = dvo.resource_record_type
      zone_id = data.aws_route53_zone.dns-zone.zone_id
    }
  }

  allow_overwrite = true
  name            = each.value.name
  records         = [each.value.record]
  ttl             = 60
  type            = each.value.type
  zone_id         = each.value.zone_id
}


resource "aws_acm_certificate_validation" "cert" {
  certificate_arn         = aws_acm_certificate.cert.arn
  validation_record_fqdns = [for record in aws_route53_record.cert_validation : record.fqdn]
}

PS - 如果您需要更多说明,请告诉我。

I have 2 AWS accounts: dev and prod.

In the prod account, I setup a DNS domain (example.com), as well as 2 public Hosted Zone: example.com and prod.example.com. 2 ACM certificates are also issued for these domains internal.prod.example.com and eks.prod.example.com. Those certificates are correctly validated by DNS.

In the dev account, I have created 2 public Hosted Zones: dev.example.com and example.com. I issued 2 ACM certificates for internal.dev.example.com and eks.dev.example.com which, as far as I understand need to be validated with the DNS in the prod account.

These certificated are in pending state.

How can I validate them?

What I did so far:

  • I added a NS record called dev.example.com in the prod account for the example.com Hosted Zone. The value of the NS record are the ones of the dev.example.com Hosted Zone created in the dev account. This is to delegate the ownership of the R53 Hosted Zone in prod. See here.

  • In the dev account, the CNAME of the requested domain from ACM have been added in the dev.example.com Hosted Zone for validation.

The following code is how it's been done (and working) on the prod account.

Note - this is a code that I took over, so I'm not aware if any manual steps have been taken.

data "aws_route53_zone" "dns-zone" {
  name = "${var.environment}.${var.zone_name}"
}

resource "aws_acm_certificate" "cert" {
  domain_name       = "*.${var.environment}.${var.zone_name}"
  validation_method = "DNS"
  subject_alternative_names = list("*.internal.${var.environment}.${var.zone_name}", "*.eks.${var.environment}.${var.zone_name}")

  lifecycle {
    create_before_destroy = true
    prevent_destroy = true
  }
}

resource "aws_route53_record" "cert_validation" {
  for_each = {
    for dvo in aws_acm_certificate.cert.domain_validation_options : dvo.domain_name => {
      name    = dvo.resource_record_name
      record  = dvo.resource_record_value
      type    = dvo.resource_record_type
      zone_id = data.aws_route53_zone.dns-zone.zone_id
    }
  }

  allow_overwrite = true
  name            = each.value.name
  records         = [each.value.record]
  ttl             = 60
  type            = each.value.type
  zone_id         = each.value.zone_id
}


resource "aws_acm_certificate_validation" "cert" {
  certificate_arn         = aws_acm_certificate.cert.arn
  validation_record_fqdns = [for record in aws_route53_record.cert_validation : record.fqdn]
}

Ps - Should you need more clarification, please let me know.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

相守太难 2025-01-18 06:06:22

开发与开发您有 example.com 的产品帐户吗?只有1个可以正常使用。无论 注册商 位于 example.com 的何处...该注册商只能使用其中 1 个托管区域中的名称服务器

您提到您有 2 个 ACM 证书:internal.dev.example.com 和eks.dev.example.com ...如果这些域是在 DEV 帐户中创建的,则应在 DEV 帐户中对其进行验证。

另外,我建议您在 ACM 中为 *.dev.example.com & 创建 1 个通配符证书。验证 DEV 帐户中的 1。任何子域(例如 eks.dev.example.com)都可以使用它。

dev & prod account you have example.com? Only 1 can be used properly. Wherever the registrar is for example.com ... that registrar can only use the name servers from 1 of those hosted zones.

You mentioned you have 2 ACM certs for internal.dev.example.com & eks.dev.example.com ... those should be validated in the DEV Account if that's where their domains are created.

Also I recommend you just create 1 wild card cert in ACM for *.dev.example.com & validate that 1 in the DEV account. Any subdomains such as eks.dev.example.com will be able to use it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文