Skip to content

Commit 378678b

Browse files
authored
Enable EKS Pod Identity for Hub-Spoke Patterns (#55)
Signed-off-by: Carlos Santana <[email protected]>
1 parent 91bd2fa commit 378678b

File tree

20 files changed

+180
-161
lines changed

20 files changed

+180
-161
lines changed

argocd/iac/terraform/examples/eks/multi-cluster/hub-spoke-shared/README.md

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,6 @@ Access ArgoCD's UI, run the command from the output:
5050
terraform output -raw access_argocd
5151
```
5252

53-
## Verify that ArgoCD Service Accouts has the annotation for IRSA
54-
```shell
55-
kubectl get sa -n argocd argocd-application-controller -o json | jq '.metadata.annotations."eks.amazonaws.com/role-arn"'
56-
kubectl get sa -n argocd argocd-server -o json | jq '.metadata.annotations."eks.amazonaws.com/role-arn"'
57-
```
58-
The output should match the `arn` for the IAM Role that will assume the IAM Role in spoke/remote clusters
59-
```text
60-
"arn:aws:iam::0123456789:role/hub-spoke-control-plane-argocd-hub"
61-
```
62-
6353
## Deploy the Spoke EKS Cluster
6454
Initialize Terraform and deploy the EKS clusters:
6555
Is recommended to use a new terminal window for each cluster

argocd/iac/terraform/examples/eks/multi-cluster/hub-spoke-shared/hub/main.tf

Lines changed: 44 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,9 @@ locals {
7373
enable_ack_emrcontainers = try(var.addons.enable_ack_emrcontainers, false)
7474
enable_ack_sfn = try(var.addons.enable_ack_sfn, false)
7575
enable_ack_eventbridge = try(var.addons.enable_ack_eventbridge, false)
76-
enable_aws_argocd = try(var.addons.enable_aws_argocd, false)
7776
}
7877
oss_addons = {
79-
enable_argocd = try(var.addons.enable_argocd, false)
78+
enable_argocd = try(var.addons.enable_argocd, true)
8079
enable_argo_rollouts = try(var.addons.enable_argo_rollouts, false)
8180
enable_argo_events = try(var.addons.enable_argo_events, false)
8281
enable_argo_workflows = try(var.addons.enable_argo_workflows, false)
@@ -107,7 +106,6 @@ locals {
107106
aws_vpc_id = module.vpc.vpc_id
108107
},
109108
{
110-
argocd_iam_role_arn = module.argocd_irsa.iam_role_arn
111109
argocd_namespace = local.argocd_namespace
112110
},
113111
{
@@ -149,43 +147,49 @@ module "gitops_bridge_bootstrap" {
149147
################################################################################
150148
# ArgoCD EKS Access
151149
################################################################################
152-
module "argocd_irsa" {
153-
source = "aws-ia/eks-blueprints-addon/aws"
154-
155-
create_release = false
156-
create_role = true
157-
role_name_use_prefix = false
158-
role_name = "${module.eks.cluster_name}-argocd-hub"
159-
assume_role_condition_test = "StringLike"
160-
create_policy = false
161-
role_policies = {
162-
ArgoCD_EKS_Policy = aws_iam_policy.irsa_policy.arn
163-
}
164-
oidc_providers = {
165-
this = {
166-
provider_arn = module.eks.oidc_provider_arn
167-
namespace = local.argocd_namespace
168-
service_account = "argocd-*"
150+
data "aws_iam_policy_document" "eks_assume" {
151+
statement {
152+
effect = "Allow"
153+
principals {
154+
type = "Service"
155+
identifiers = ["pods.eks.amazonaws.com"]
169156
}
157+
actions = ["sts:AssumeRole","sts:TagSession"]
170158
}
171-
tags = local.tags
172-
173159
}
174-
175-
resource "aws_iam_policy" "irsa_policy" {
176-
name = "${module.eks.cluster_name}-argocd-irsa"
177-
description = "IAM Policy for ArgoCD Hub"
178-
policy = data.aws_iam_policy_document.irsa_policy.json
179-
tags = local.tags
160+
resource "aws_iam_role" "argocd_hub" {
161+
name = "${module.eks.cluster_name}-argocd-hub"
162+
assume_role_policy = data.aws_iam_policy_document.eks_assume.json
180163
}
181-
182-
data "aws_iam_policy_document" "irsa_policy" {
164+
data "aws_iam_policy_document" "aws_assume_policy" {
183165
statement {
184166
effect = "Allow"
185167
resources = ["*"]
186-
actions = ["sts:AssumeRole"]
168+
actions = ["sts:AssumeRole","sts:TagSession"]
187169
}
188170
}
171+
resource "aws_iam_policy" "aws_assume_policy" {
172+
name = "${module.eks.cluster_name}-argocd-aws-assume"
173+
description = "IAM Policy for ArgoCD Hub"
174+
policy = data.aws_iam_policy_document.aws_assume_policy.json
175+
tags = local.tags
176+
}
177+
resource "aws_iam_role_policy_attachment" "aws_assume_policy" {
178+
role = aws_iam_role.argocd_hub.name
179+
policy_arn = aws_iam_policy.aws_assume_policy.arn
180+
}
181+
resource "aws_eks_pod_identity_association" "argocd_app_controller" {
182+
cluster_name = module.eks.cluster_name
183+
namespace = "argocd"
184+
service_account = "argocd-application-controller"
185+
role_arn = aws_iam_role.argocd_hub.arn
186+
}
187+
resource "aws_eks_pod_identity_association" "argocd_api_server" {
188+
cluster_name = module.eks.cluster_name
189+
namespace = "argocd"
190+
service_account = "argocd-server"
191+
role_arn = aws_iam_role.argocd_hub.arn
192+
}
189193

190194
################################################################################
191195
# EKS Blueprints Addons
@@ -228,7 +232,7 @@ module "eks_blueprints_addons" {
228232
#tfsec:ignore:aws-eks-enable-control-plane-logging
229233
module "eks" {
230234
source = "terraform-aws-modules/eks/aws"
231-
version = "~> 19.13"
235+
version = "~> 20.5"
232236

233237
cluster_name = local.name
234238
cluster_version = local.cluster_version
@@ -238,6 +242,10 @@ module "eks" {
238242
vpc_id = module.vpc.vpc_id
239243
subnet_ids = module.vpc.private_subnets
240244

245+
# Cluster access entry
246+
# To add the current caller identity as an administrator
247+
enable_cluster_creator_admin_permissions = true
248+
241249
eks_managed_node_groups = {
242250
initial = {
243251
instance_types = ["t3.medium"]
@@ -249,6 +257,10 @@ module "eks" {
249257
}
250258
# EKS Addons
251259
cluster_addons = {
260+
eks-pod-identity-agent = {
261+
most_recent = true
262+
before_compute = true
263+
}
252264
vpc-cni = {
253265
# Specify the VPC CNI addon should be deployed before compute to ensure
254266
# the addon is configured before data plane compute resources are created

argocd/iac/terraform/examples/eks/multi-cluster/hub-spoke-shared/hub/outputs.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@ output "access_argocd" {
3636

3737
output "argocd_iam_role_arn" {
3838
description = "IAM Role for ArgoCD Cluster Hub, use to connect to spoke clusters"
39-
value = module.argocd_irsa.iam_role_arn
39+
value = aws_iam_role.argocd_hub.arn
4040
}
4141

42+
4243
output "cluster_name" {
4344
description = "Cluster Hub name"
4445
value = module.eks.cluster_name

argocd/iac/terraform/examples/eks/multi-cluster/hub-spoke-shared/hub/variables.tf

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,15 @@ variable "region" {
1111
variable "kubernetes_version" {
1212
description = "Kubernetes version"
1313
type = string
14-
default = "1.28"
14+
default = "1.29"
1515
}
1616
variable "addons" {
1717
description = "Kubernetes addons"
1818
type = any
1919
default = {
2020
enable_aws_load_balancer_controller = true
2121
enable_metrics_server = true
22-
# Enable argocd with IRSA
23-
enable_aws_argocd = true
24-
# Disable argocd without IRSA
25-
enable_argocd = false
22+
enable_argocd = true
2623
}
2724
}
2825
# Addons Git

argocd/iac/terraform/examples/eks/multi-cluster/hub-spoke-shared/hub/versions.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ terraform {
44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 4.67.0"
7+
version = ">= 5.39.1"
88
}
99
helm = {
1010
source = "hashicorp/helm"
11-
version = ">= 2.10.1"
11+
version = ">= 2.12.1"
1212
}
1313
kubernetes = {
1414
source = "hashicorp/kubernetes"
15-
version = "2.22.0"
15+
version = ">= 2.26.0"
1616
}
1717
}
1818

argocd/iac/terraform/examples/eks/multi-cluster/hub-spoke-shared/spokes/main.tf

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,9 @@ locals {
111111
enable_ack_emrcontainers = try(var.addons.enable_ack_emrcontainers, false)
112112
enable_ack_sfn = try(var.addons.enable_ack_sfn, false)
113113
enable_ack_eventbridge = try(var.addons.enable_ack_eventbridge, false)
114-
enable_aws_argocd = try(var.addons.enable_aws_argocd, false)
115114
}
116115
oss_addons = {
117-
enable_argocd = try(var.addons.enable_argocd, false)
116+
enable_argocd = try(var.addons.enable_argocd, true)
118117
enable_argo_rollouts = try(var.addons.enable_argo_rollouts, false)
119118
enable_argo_events = try(var.addons.enable_argo_events, false)
120119
enable_argo_workflows = try(var.addons.enable_argo_workflows, false)
@@ -187,7 +186,7 @@ resource "time_sleep" "wait_for_argocd_namespace_and_crds" {
187186
depends_on = [module.gitops_bridge_bootstrap_hub]
188187
}
189188
module "gitops_bridge_bootstrap_spoke" {
190-
source = "github.com/gitops-bridge-dev/gitops-bridge-argocd-bootstrap-terraform?ref=v2.0.0"
189+
source = "gitops-bridge-dev/gitops-bridge/helm"
191190

192191
install = false # Not installing argocd via helm on spoke cluster
193192
cluster = {
@@ -208,7 +207,7 @@ module "gitops_bridge_bootstrap_spoke" {
208207
# GitOps Bridge: Bootstrap for Hub Cluster
209208
################################################################################
210209
module "gitops_bridge_bootstrap_hub" {
211-
source = "github.com/gitops-bridge-dev/gitops-bridge-argocd-bootstrap-terraform?ref=v2.0.0"
210+
source = "gitops-bridge-dev/gitops-bridge/helm"
212211

213212
# The ArgoCD remote cluster secret is deploy on hub cluster not on spoke clusters
214213
providers = {
@@ -240,20 +239,21 @@ module "gitops_bridge_bootstrap_hub" {
240239
################################################################################
241240
# ArgoCD EKS Access
242241
################################################################################
243-
resource "aws_iam_role" "spoke" {
244-
name = "${module.eks.cluster_name}-argocd-spoke"
245-
assume_role_policy = data.aws_iam_policy_document.assume_role_policy.json
246-
}
247-
248242
data "aws_iam_policy_document" "assume_role_policy" {
249243
statement {
250-
actions = ["sts:AssumeRole"]
244+
actions = ["sts:AssumeRole","sts:TagSession"]
251245
principals {
252246
type = "AWS"
253247
identifiers = [data.terraform_remote_state.cluster_hub.outputs.argocd_iam_role_arn]
254248
}
255249
}
256250
}
251+
resource "aws_iam_role" "spoke" {
252+
name = "${module.eks.cluster_name}-argocd-spoke"
253+
assume_role_policy = data.aws_iam_policy_document.assume_role_policy.json
254+
}
255+
256+
257257

258258

259259

@@ -298,7 +298,7 @@ module "eks_blueprints_addons" {
298298
#tfsec:ignore:aws-eks-enable-control-plane-logging
299299
module "eks" {
300300
source = "terraform-aws-modules/eks/aws"
301-
version = "~> 19.13"
301+
version = "~> 20.5"
302302

303303
cluster_name = local.name
304304
cluster_version = local.cluster_version
@@ -308,17 +308,25 @@ module "eks" {
308308
vpc_id = module.vpc.vpc_id
309309
subnet_ids = module.vpc.private_subnets
310310

311-
manage_aws_auth_configmap = true
312-
aws_auth_roles = [
313-
# Granting access to ArgoCD from hub cluster
314-
{
315-
rolearn = aws_iam_role.spoke.arn
316-
username = "gitops-role"
317-
groups = [
318-
"system:masters"
319-
]
320-
},
321-
]
311+
# Cluster access entry
312+
# To add the current caller identity as an administrator
313+
enable_cluster_creator_admin_permissions = true
314+
315+
access_entries = {
316+
# One access entry with a policy associated
317+
argocd = {
318+
principal_arn = aws_iam_role.spoke.arn
319+
320+
policy_associations = {
321+
argocd = {
322+
policy_arn = "arn:aws:eks::aws:cluster-access-policy/AmazonEKSClusterAdminPolicy"
323+
access_scope = {
324+
type = "cluster"
325+
}
326+
}
327+
}
328+
}
329+
}
322330

323331
eks_managed_node_groups = {
324332
initial = {
@@ -331,6 +339,10 @@ module "eks" {
331339
}
332340
# EKS Addons
333341
cluster_addons = {
342+
eks-pod-identity-agent = {
343+
most_recent = true
344+
before_compute = true
345+
}
334346
vpc-cni = {
335347
# Specify the VPC CNI addon should be deployed before compute to ensure
336348
# the addon is configured before data plane compute resources are created

argocd/iac/terraform/examples/eks/multi-cluster/hub-spoke-shared/spokes/versions.tf

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ terraform {
44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 4.67.0"
8-
}
9-
helm = {
10-
source = "hashicorp/helm"
11-
version = ">= 2.10.1"
7+
version = ">= 5.39.1"
128
}
139
kubernetes = {
1410
source = "hashicorp/kubernetes"
15-
version = "2.22.0"
11+
version = ">= 2.26.0"
12+
}
13+
helm = {
14+
source = "hashicorp/helm"
15+
version = ">= 2.12.1"
1616
}
1717
time = {
1818
source = "hashicorp/time"
19-
version = ">= 0.9.1"
19+
version = ">= 0.10.0"
2020
}
2121
}
2222

argocd/iac/terraform/examples/eks/multi-cluster/hub-spoke-shared/spokes/workspaces/dev.tfvars

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
vpc_cidr = "10.1.0.0/16"
22
region = "us-west-2"
3-
kubernetes_version = "1.28"
3+
kubernetes_version = "1.29"
44
addons = {
55
enable_aws_load_balancer_controller = true
66
enable_metrics_server = true

argocd/iac/terraform/examples/eks/multi-cluster/hub-spoke-shared/spokes/workspaces/prod.tfvars

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
vpc_cidr = "10.3.0.0/16"
22
region = "us-west-2"
3-
kubernetes_version = "1.28"
3+
kubernetes_version = "1.29"
44
addons = {
55
enable_aws_load_balancer_controller = true
66
enable_metrics_server = true

argocd/iac/terraform/examples/eks/multi-cluster/hub-spoke-shared/spokes/workspaces/staging.tfvars

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
vpc_cidr = "10.2.0.0/16"
22
region = "us-west-2"
3-
kubernetes_version = "1.28"
3+
kubernetes_version = "1.29"
44
addons = {
55
enable_aws_load_balancer_controller = true
66
enable_metrics_server = true

argocd/iac/terraform/examples/eks/multi-cluster/hub-spoke/README.md

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,6 @@ Access ArgoCD's UI, run the command from the output:
5050
terraform output -raw access_argocd
5151
```
5252

53-
## Verify that ArgoCD Service Accouts has the annotation for IRSA
54-
```shell
55-
kubectl get sa -n argocd argocd-application-controller -o json | jq '.metadata.annotations."eks.amazonaws.com/role-arn"'
56-
kubectl get sa -n argocd argocd-server -o json | jq '.metadata.annotations."eks.amazonaws.com/role-arn"'
57-
```
58-
The output should match the `arn` for the IAM Role that will assume the IAM Role in spoke/remote clusters
59-
```text
60-
"arn:aws:iam::0123456789:role/hub-spoke-control-plane-argocd-hub"
61-
```
62-
6353
## Deploy the Spoke EKS Cluster
6454
Initialize Terraform and deploy the EKS clusters:
6555
```shell

0 commit comments

Comments
 (0)