Skip to content

Commit 4c26b48

Browse files
authored
Merge pull request #31 from nphilbrook/nphilbrook_vault_backed_aws_improvement
Add policy to allow Vault user to rotate its own creds; other small improvements
1 parent 5308cd9 commit 4c26b48

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

vault-backed/aws/aws.tf

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff 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
8690
resource "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+
}

vault-backed/aws/vars.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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+
}

vault-backed/aws/vault.tf

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ provider "vault" {
1010
#
1111
# https://registry.terraform.io/providers/hashicorp/vault/latest/docs/resources/jwt_auth_backend
1212
resource "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
4546
resource "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
9092
resource "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+
}

0 commit comments

Comments
 (0)