main.tf 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #----------------------------------------------------------------------------
  2. # Okta Auth
  3. #----------------------------------------------------------------------------
  4. resource "vault_okta_auth_backend" "okta" {
  5. description = "Terraform Okta auth backend"
  6. organization = "mdr-multipass"
  7. token = data.aws_secretsmanager_secret_version.okta_api_token.secret_string
  8. base_url = "okta.com"
  9. ttl = "1h"
  10. max_ttl = "8h"
  11. group {
  12. group_name = "mdr-admins"
  13. policies = [vault_policy.admins.name]
  14. }
  15. group {
  16. group_name = "mdr-engineers"
  17. policies = [vault_policy.engineers.name]
  18. }
  19. group {
  20. group_name = "phantom-role-administrator"
  21. policies = [vault_policy.phantom.name]
  22. }
  23. group {
  24. group_name = "vault-admins"
  25. policies = [vault_policy.admins.name]
  26. }
  27. group {
  28. group_name = "analyst-shift-lead"
  29. policies = [vault_policy.soc.name]
  30. }
  31. group {
  32. group_name = "analyst-tier-3"
  33. policies = [vault_policy.soc.name]
  34. }
  35. }
  36. #----------------------------------------------------------------------------
  37. # Okta OIDC Auth
  38. #----------------------------------------------------------------------------
  39. #NOTICE: Members of the default_role do not need to type in the role, like a boss.
  40. # If you are not a member of the default_role, then you must type in your role, like a peasent.
  41. resource "vault_jwt_auth_backend" "okta_oidc" {
  42. description = "Terraform Managed OIDC Auth"
  43. path = "oidc"
  44. type = "oidc"
  45. oidc_discovery_url = "https://mdr-multipass.okta.com"
  46. oidc_client_id = var.environment == "test" ? "0oa5icfdd1PdtoER0297" : "0oa5jb5198xfxqLiE297"
  47. oidc_client_secret = data.aws_secretsmanager_secret_version.okta_oidc_client_secret.secret_string
  48. bound_issuer = "https://mdr-multipass.okta.com"
  49. default_role = "mdr-admins"
  50. tune {
  51. listing_visibility = "unauth"
  52. max_lease_ttl = "8h"
  53. default_lease_ttl = "1h"
  54. token_type = "default-service"
  55. }
  56. #the oidc_client_secret causes terraform to think it needs to apply changes.
  57. #lifecycle { ignore_changes = [oidc_client_secret,]}
  58. }
  59. #max token length of 28800 seconds ( 8 Hours )
  60. resource "vault_jwt_auth_backend_role" "okta_oidc" {
  61. for_each = var.roles
  62. backend = vault_jwt_auth_backend.okta_oidc.path
  63. role_name = each.key
  64. token_policies = each.value.token_policies
  65. user_claim = "email"
  66. role_type = "oidc"
  67. allowed_redirect_uris = ["https://vault.${var.dns_info["private"]["zone"]}/ui/vault/auth/oidc/oidc/callback"]
  68. oidc_scopes = ["profile", "email", "groups"]
  69. bound_claims = { groups = join(",", each.value.bound_groups) }
  70. verbose_oidc_logging = false
  71. token_explicit_max_ttl = "28800"
  72. }
  73. #----------------------------------------------------------------------------
  74. # AWS Auth
  75. #----------------------------------------------------------------------------
  76. resource "vault_auth_backend" "aws" {
  77. type = "aws"
  78. }
  79. #vault write auth/aws/config/client sts_endpoint=https://sts.us-gov-east-1.amazonaws.com sts_region=us-gov-east-1
  80. #https://github.com/terraform-providers/terraform-provider-vault/pull/717
  81. #https://github.com/terraform-providers/terraform-provider-vault/issues/689
  82. resource "vault_aws_auth_backend_client" "aws" {
  83. backend = vault_auth_backend.aws.path
  84. sts_endpoint = "https://sts.${var.aws_region}.amazonaws.com"
  85. sts_region = var.aws_region
  86. }
  87. resource "vault_aws_auth_backend_role" "portal" {
  88. backend = vault_auth_backend.aws.path
  89. role = "portal"
  90. auth_type = "iam"
  91. bound_iam_principal_arns = ["arn:${var.aws_partition}:iam::${var.aws_account_id}:role/portal-instance-role"]
  92. #inferred_aws_region = "us-gov-east-1"
  93. token_ttl = 60
  94. token_max_ttl = 86400
  95. token_policies = ["portal"]
  96. }
  97. resource "vault_aws_auth_backend_role" "portal-data-sync-lambda-role" {
  98. backend = vault_auth_backend.aws.path
  99. role = "portal-data-sync-lambda-role"
  100. auth_type = "iam"
  101. bound_iam_principal_arns = ["arn:${var.aws_partition}:iam::${var.aws_account_id}:role/portal-data-sync-lambda-role"]
  102. #inferred_aws_region = "us-gov-east-1"
  103. token_ttl = 60
  104. token_max_ttl = 86400
  105. token_policies = ["portal"]
  106. }
  107. #----------------------------------------------------------------------------
  108. # AppRole Auth ( not currently used )
  109. #----------------------------------------------------------------------------
  110. resource "vault_auth_backend" "approle" {
  111. type = "approle"
  112. description = "approle"
  113. }
  114. #----------------------------------------------------------------------------
  115. # File Audit
  116. #----------------------------------------------------------------------------
  117. resource "vault_audit" "file_audit" {
  118. type = "file"
  119. options = {
  120. file_path = "/var/log/vault.log"
  121. }
  122. }