Skip to content
This repository was archived by the owner on Nov 26, 2025. It is now read-only.

Commit 7a7fcfe

Browse files
Add AWS IAM Redis passwordless authentication support
- Add redis_enable_iam_auth variable for IAM authentication control - Create ElastiCache IAM user and user group for passwordless access - Configure replication group to use IAM authentication when enabled - Add IAM policy for ElastiCache Connect permissions in service accounts - Pass IAM authentication parameters to runtime container engine config - Enable passwordless Redis authentication using AWS IAM roles This allows TFE to connect to ElastiCache Redis using IAM authentication instead of passwords, improving security and enabling passwordless workflows.
1 parent ac9cd1d commit 7a7fcfe

File tree

6 files changed

+89
-0
lines changed

6 files changed

+89
-0
lines changed

main.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ module "service_accounts" {
4545
postgres_client_key_secret_id = var.postgres_client_key_secret_id
4646
postgres_ca_certificate_secret_id = var.postgres_ca_certificate_secret_id
4747
vm_key_secret_id = var.vm_key_secret_id
48+
redis_enable_iam_auth = var.redis_enable_iam_auth
4849
}
4950

5051
# -----------------------------------------------------------------------------
@@ -94,6 +95,7 @@ module "redis" {
9495
redis_encryption_in_transit = var.redis_encryption_in_transit
9596
redis_encryption_at_rest = var.redis_encryption_at_rest
9697
redis_use_password_auth = var.redis_use_password_auth
98+
redis_enable_iam_auth = var.redis_enable_iam_auth
9799
redis_port = var.redis_encryption_in_transit ? "6380" : "6379"
98100
}
99101

@@ -327,6 +329,8 @@ module "runtime_container_engine_config" {
327329
redis_ca_cert_path = "/etc/ssl/private/terraform-enterprise/redis/cacert.pem"
328330
redis_client_cert_path = "/etc/ssl/private/terraform-enterprise/redis/cert.pem"
329331
redis_client_key_path = "/etc/ssl/private/terraform-enterprise/redis/key.pem"
332+
redis_passwordless_aws_use_iam = var.redis_enable_iam_auth && !var.redis_use_password_auth
333+
redis_passwordless_aws_region = var.redis_enable_iam_auth && !var.redis_use_password_auth ? data.aws_region.current.name : ""
330334

331335

332336
trusted_proxies = local.trusted_proxies

modules/redis/main.tf

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
locals {
55
redis_use_password_auth = var.redis_use_password_auth || var.redis_authentication_mode == "PASSWORD"
6+
redis_use_iam_auth = var.redis_enable_iam_auth && !var.redis_use_password_auth
67
}
78

89
resource "random_id" "redis_password" {
@@ -63,6 +64,38 @@ resource "aws_elasticache_subnet_group" "tfe" {
6364
subnet_ids = var.network_subnets_private
6465
}
6566

67+
# ElastiCache User for IAM authentication
68+
resource "aws_elasticache_user" "iam_user" {
69+
count = var.active_active && local.redis_use_iam_auth ? 1 : 0
70+
user_id = "${var.friendly_name_prefix}-iam-user"
71+
user_name = "${var.friendly_name_prefix}-iam-user"
72+
73+
# For IAM authentication, we don't set passwords but use IAM policies
74+
authentication_mode {
75+
type = "iam"
76+
}
77+
78+
# Access string for Redis commands - allow all commands for TFE
79+
access_string = "on ~* &* +@all"
80+
engine = "REDIS"
81+
82+
tags = {
83+
Name = "${var.friendly_name_prefix}-redis-iam-user"
84+
}
85+
}
86+
87+
# ElastiCache User Group for IAM authentication
88+
resource "aws_elasticache_user_group" "iam_group" {
89+
count = var.active_active && local.redis_use_iam_auth ? 1 : 0
90+
engine = "REDIS"
91+
user_group_id = "${var.friendly_name_prefix}-iam-group"
92+
user_ids = [aws_elasticache_user.iam_user[0].user_id]
93+
94+
tags = {
95+
Name = "${var.friendly_name_prefix}-redis-iam-group"
96+
}
97+
}
98+
6699
resource "aws_elasticache_replication_group" "redis" {
67100
count = var.active_active ? 1 : 0
68101
node_type = var.cache_size
@@ -88,4 +121,7 @@ resource "aws_elasticache_replication_group" "redis" {
88121

89122
at_rest_encryption_enabled = var.redis_encryption_at_rest
90123
kms_key_id = var.redis_encryption_at_rest ? var.kms_key_arn : null
124+
125+
# IAM authentication configuration
126+
user_group_ids = local.redis_use_iam_auth ? [aws_elasticache_user_group.iam_group[0].user_group_id] : null
91127
}

modules/redis/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,9 @@ variable "redis_use_password_auth" {
8282
type = bool
8383
description = "Determine if a password is required for Redis."
8484
}
85+
86+
variable "redis_enable_iam_auth" {
87+
type = bool
88+
description = "Whether to enable IAM authentication for Redis. Used for passwordless authentication."
89+
default = false
90+
}

modules/service_accounts/main.tf

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,34 @@ resource "aws_iam_policy" "kms_policy" {
114114
]
115115
})
116116
}
117+
118+
# Redis IAM authentication policy
119+
resource "aws_iam_role_policy_attachment" "redis_iam_policy" {
120+
count = var.existing_iam_instance_profile_name == null && var.redis_enable_iam_auth ? 1 : 0
121+
122+
role = local.iam_instance_role.name
123+
policy_arn = aws_iam_policy.redis_iam_policy[0].arn
124+
}
125+
126+
resource "aws_iam_policy" "redis_iam_policy" {
127+
count = var.existing_iam_instance_profile_name == null && var.redis_enable_iam_auth ? 1 : 0
128+
129+
name = "${var.friendly_name_prefix}-redis-iam"
130+
policy = jsonencode({
131+
Version = "2012-10-17"
132+
Statement = [
133+
{
134+
Action = [
135+
"elasticache:Connect"
136+
]
137+
Effect = "Allow"
138+
Resource = "*"
139+
Condition = {
140+
StringEquals = {
141+
"elasticache:Username" = "${var.friendly_name_prefix}-iam-user"
142+
}
143+
}
144+
},
145+
]
146+
})
147+
}

modules/service_accounts/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,9 @@ variable "postgres_client_key_secret_id" {
9898
default = null
9999
description = "The secrets manager secret ID of the Base64 & PEM encoded private key for postgres."
100100
}
101+
102+
variable "redis_enable_iam_auth" {
103+
type = bool
104+
description = "Whether to enable IAM authentication for Redis. Used for passwordless authentication."
105+
default = false
106+
}

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,12 @@ variable "sentinel_leader" {
208208
description = "The name of the Redis Sentinel leader"
209209
}
210210

211+
variable "redis_enable_iam_auth" {
212+
type = bool
213+
description = "Whether to enable IAM authentication for Redis. Used for passwordless authentication."
214+
default = false
215+
}
216+
211217
# Postgres
212218
# --------
213219
variable "db_name" {

0 commit comments

Comments
 (0)