File tree Expand file tree Collapse file tree 3 files changed +17
-7
lines changed Expand file tree Collapse file tree 3 files changed +17
-7
lines changed Original file line number Diff line number Diff line change @@ -80,7 +80,11 @@ resource "aws_iam_access_key" "secrets_engine_credentials" {
8080}
8181
8282
83- # Provides an IAM policy attached to a user. In this case, allowing the secrets_engine user to assume other roles via STS
83+ # Provides an IAM policy attached to a user. In this case, allowing the secrets_engine user rotate its own access key
84+ #
85+ # https://developer.hashicorp.com/vault/api-docs/secret/aws#rotate-root-iam-credentials
86+ #
87+ # Note that if the credentials are rotated, there will be drift in this Terraform configuration
8488#
8589# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_user_policy
8690resource "aws_iam_user_policy" "vault_secrets_engine_generate_credentials" {
@@ -92,11 +96,14 @@ resource "aws_iam_user_policy" "vault_secrets_engine_generate_credentials" {
9296 Statement = [
9397 {
9498 Action = [
95- " sts:AssumeRole" ,
99+ " iam:GetUser" ,
100+ " iam:CreateAccessKey" ,
101+ " iam:DeleteAccessKey" ,
102+ " iam:ListAccessKeys"
96103 ]
97104 Effect = " Allow"
98- Resource = " ${ aws_iam_role . tfc_role . arn } "
105+ Resource = aws_iam_user.secrets_engine .arn
99106 },
100107 ]
101108 })
102- }
109+ }
Original file line number Diff line number Diff line change @@ -56,4 +56,4 @@ variable "tfc_vault_audience" {
5656 type = string
5757 default = " vault.workload.identity"
5858 description = " The audience value to use in run identity tokens"
59- }
59+ }
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ provider "vault" {
1010#
1111# https://registry.terraform.io/providers/hashicorp/vault/latest/docs/resources/jwt_auth_backend
1212resource "vault_jwt_auth_backend" "tfc_jwt" {
13+ namespace = var. vault_namespace
1314 path = var. jwt_backend_path
1415 type = " jwt"
1516 oidc_discovery_url = " https://${ var . tfc_hostname } "
@@ -43,7 +44,8 @@ resource "vault_jwt_auth_backend_role" "tfc_role" {
4344#
4445# https://registry.terraform.io/providers/hashicorp/vault/latest/docs/resources/policy
4546resource "vault_policy" "tfc_policy" {
46- name = " tfc-policy"
47+ namespace = var. vault_namespace
48+ name = " tfc-policy"
4749
4850 policy = << EOT
4951# Allow tokens to query themselves
@@ -88,9 +90,10 @@ resource "vault_aws_secret_backend" "aws_secret_backend" {
8890#
8991# https://registry.terraform.io/providers/hashicorp/vault/latest/docs/resources/aws_secret_backend_role
9092resource "vault_aws_secret_backend_role" "aws_secret_backend_role" {
93+ namespace = var. vault_namespace
9194 backend = vault_aws_secret_backend. aws_secret_backend . path
9295 name = var. aws_secret_backend_role_name
9396 credential_type = " assumed_role"
9497
9598 role_arns = [aws_iam_role . tfc_role . arn ]
96- }
99+ }
You can’t perform that action at this time.
0 commit comments