dnssec.tf 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. locals {
  2. domains_to_secure = toset(local.hosted_public_dns_zones)
  3. }
  4. resource "aws_kms_key" "dnssec" {
  5. customer_master_key_spec = "ECC_NIST_P256"
  6. deletion_window_in_days = 30
  7. key_usage = "SIGN_VERIFY"
  8. policy = jsonencode({
  9. Statement = [
  10. {
  11. Action = [
  12. "kms:DescribeKey",
  13. "kms:GetPublicKey",
  14. "kms:Sign",
  15. ],
  16. Effect = "Allow"
  17. Principal = {
  18. Service = "api-service.dnssec.route53.aws.internal"
  19. }
  20. Sid = "Route 53 DNSSEC Permissions"
  21. },
  22. {
  23. Action = "kms:*"
  24. Effect = "Allow"
  25. Principal = {
  26. AWS = "*"
  27. }
  28. Resource = "*"
  29. Sid = "IAM User Permissions"
  30. },
  31. ]
  32. Version = "2012-10-17"
  33. })
  34. }
  35. # For rotation, uncomment the following
  36. #resource "aws_kms_key" "dnssec_2" {
  37. # customer_master_key_spec = "ECC_NIST_P256"
  38. # deletion_window_in_days = 30
  39. # key_usage = "SIGN_VERIFY"
  40. # policy = jsonencode({
  41. # Statement = [
  42. # {
  43. # Action = [
  44. # "kms:DescribeKey",
  45. # "kms:GetPublicKey",
  46. # "kms:Sign",
  47. # ],
  48. # Effect = "Allow"
  49. # Principal = {
  50. # Service = "api-service.dnssec.route53.aws.internal"
  51. # }
  52. # Sid = "Route 53 DNSSEC Permissions"
  53. # },
  54. # {
  55. # Action = "kms:*"
  56. # Effect = "Allow"
  57. # Principal = {
  58. # AWS = "*"
  59. # }
  60. # Resource = "*"
  61. # Sid = "IAM User Permissions"
  62. # },
  63. # ]
  64. # Version = "2012-10-17"
  65. # })
  66. #}
  67. resource "aws_route53_key_signing_key" "dnssec" {
  68. for_each = local.domains_to_secure
  69. hosted_zone_id = aws_route53_zone.public[each.value].id
  70. key_management_service_arn = aws_kms_key.dnssec.arn
  71. name = "202105"
  72. }
  73. # For rotation, uncomment the following
  74. #resource "aws_route53_key_signing_key" "dnssec_2" {
  75. # for_each = local.domains_to_secure
  76. # hosted_zone_id = aws_route53_zone.public[each.value].id
  77. # key_management_service_arn = aws_kms_key.dnssec.arn
  78. # name = "UPDATEME"
  79. #}
  80. output "public_keys_note" {
  81. value = "You must *MANUALLY* add the public keys to the 'registered domains' page on the route53 console."
  82. }
  83. output "manually_entered_information" {
  84. value = { for domain in local.domains_to_secure :
  85. domain => {
  86. "KeyType" : aws_route53_key_signing_key.dnssec[domain].flag,
  87. "Algorithm" : aws_route53_key_signing_key.dnssec[domain].signing_algorithm_type,
  88. "PublicKey" : aws_route53_key_signing_key.dnssec[domain].public_key
  89. "DS_Record" : aws_route53_key_signing_key.dnssec[domain].ds_record
  90. }
  91. }
  92. }
  93. # For rotation, uncomment the following
  94. #output "manually_entered_information_1" {
  95. # value = { for domain in local.domains_to_secure:
  96. # domain => {
  97. # "KeyType": aws_route53_key_signing_key.dnssec_2[domain].flag,
  98. # "Algorithm": aws_route53_key_signing_key.dnssec_2[domain].signing_algorithm_type,
  99. # "PublicKey": aws_route53_key_signing_key.dnssec_2[domain].public_key
  100. # "DS_Record": aws_route53_key_signing_key.dnssec_2[domain].ds_record
  101. # }
  102. # }
  103. #}
  104. resource "aws_route53_hosted_zone_dnssec" "dnssec" {
  105. for_each = local.domains_to_secure
  106. # AFTER rotating the key, applying, and adding to the registar, update this to `dnssec_2` and re-apply.
  107. hosted_zone_id = aws_route53_key_signing_key.dnssec[each.value].hosted_zone_id
  108. }
  109. resource "aws_route53_record" "ds" {
  110. for_each = local.domains_with_parents
  111. allow_overwrite = true
  112. name = each.key
  113. ttl = 300
  114. type = "DS"
  115. zone_id = aws_route53_zone.public[each.value].id
  116. # AFTER rotating the key, applying, and adding to the registar, update this to `dnssec_2` and re-apply.
  117. records = [aws_route53_key_signing_key.dnssec[each.key].ds_record]
  118. }