assume_role_policy-okta_saml.tf 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. data "aws_iam_policy_document" "okta_saml_assume_role_policy" {
  2. statement {
  3. sid = "AllowAssumeRoleViaOkta"
  4. effect = "Allow"
  5. principals {
  6. type = "Federated"
  7. identifiers = [aws_iam_saml_provider.okta.arn]
  8. }
  9. actions = [
  10. "sts:AssumeRoleWithSAML",
  11. ]
  12. condition {
  13. test = "StringEquals"
  14. variable = "SAML:aud"
  15. values = [
  16. local.saml_signin_page[local.aws_partition]
  17. ]
  18. }
  19. }
  20. # Note this could be a security issue. We are counting on
  21. # All of the other roles, groups, etc in the account to have reasonable
  22. # limitations on sts:AssumeRole
  23. statement {
  24. sid = "AllowAssumeRoleFromOtherRolesInThisAccount"
  25. effect = "Allow"
  26. principals {
  27. type = "AWS"
  28. identifiers = [
  29. "arn:${local.aws_partition}:iam::${local.aws_account}:root"
  30. ]
  31. }
  32. actions = [
  33. "sts:AssumeRole",
  34. ]
  35. }
  36. }
  37. # Notice the source_json here. I had forgotten how this worked and
  38. # had to refresh myself. See terraform AWS provider docs at
  39. # https://www.terraform.io/docs/providers/aws/d/iam_policy_document.html
  40. # "Statements with non-blank sids in the current policy document will overwrite
  41. # statements with the same sid in the source json."
  42. # The idea here is that IF var.trusted_arns is set, then we append a new SID
  43. # to the policy to enable AssumeRole from other accounts.
  44. #
  45. # This ties to local.tf:
  46. # assume_role_policy = (length(var.trusted_arns) > 0) ?
  47. # data.aws_iam_policy_document.okta_saml_plus_crossaccount_assume_role_policy.json :
  48. # data.aws_iam_policy_document.okta_saml_assume_role_policy.json
  49. #
  50. # Maybe that local should be defined here in this file and not in locals.tf, not sure which
  51. # is clearer.
  52. data "aws_iam_policy_document" "okta_saml_plus_crossaccount_assume_role_policy" {
  53. source_json = data.aws_iam_policy_document.okta_saml_assume_role_policy.json
  54. statement {
  55. sid = "AllowAssumeRoleFromOtherAccounts"
  56. effect = "Allow"
  57. principals {
  58. type = "AWS"
  59. identifiers = var.trusted_arns
  60. }
  61. actions = [
  62. "sts:AssumeRole",
  63. ]
  64. }
  65. }