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" {
80
80
}
81
81
82
82
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
84
88
#
85
89
# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_user_policy
86
90
resource "aws_iam_user_policy" "vault_secrets_engine_generate_credentials" {
@@ -92,11 +96,14 @@ resource "aws_iam_user_policy" "vault_secrets_engine_generate_credentials" {
92
96
Statement = [
93
97
{
94
98
Action = [
95
- " sts:AssumeRole" ,
99
+ " iam:GetUser" ,
100
+ " iam:CreateAccessKey" ,
101
+ " iam:DeleteAccessKey" ,
102
+ " iam:ListAccessKeys"
96
103
]
97
104
Effect = " Allow"
98
- Resource = " ${ aws_iam_role . tfc_role . arn } "
105
+ Resource = aws_iam_user.secrets_engine .arn
99
106
},
100
107
]
101
108
})
102
- }
109
+ }
Original file line number Diff line number Diff line change @@ -56,4 +56,4 @@ variable "tfc_vault_audience" {
56
56
type = string
57
57
default = " vault.workload.identity"
58
58
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" {
10
10
#
11
11
# https://registry.terraform.io/providers/hashicorp/vault/latest/docs/resources/jwt_auth_backend
12
12
resource "vault_jwt_auth_backend" "tfc_jwt" {
13
+ namespace = var. vault_namespace
13
14
path = var. jwt_backend_path
14
15
type = " jwt"
15
16
oidc_discovery_url = " https://${ var . tfc_hostname } "
@@ -43,7 +44,8 @@ resource "vault_jwt_auth_backend_role" "tfc_role" {
43
44
#
44
45
# https://registry.terraform.io/providers/hashicorp/vault/latest/docs/resources/policy
45
46
resource "vault_policy" "tfc_policy" {
46
- name = " tfc-policy"
47
+ namespace = var. vault_namespace
48
+ name = " tfc-policy"
47
49
48
50
policy = << EOT
49
51
# Allow tokens to query themselves
@@ -88,9 +90,10 @@ resource "vault_aws_secret_backend" "aws_secret_backend" {
88
90
#
89
91
# https://registry.terraform.io/providers/hashicorp/vault/latest/docs/resources/aws_secret_backend_role
90
92
resource "vault_aws_secret_backend_role" "aws_secret_backend_role" {
93
+ namespace = var. vault_namespace
91
94
backend = vault_aws_secret_backend. aws_secret_backend . path
92
95
name = var. aws_secret_backend_role_name
93
96
credential_type = " assumed_role"
94
97
95
98
role_arns = [aws_iam_role . tfc_role . arn ]
96
- }
99
+ }
You can’t perform that action at this time.
0 commit comments