dnssec.tf 4.1 KB

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