Skip to content

Commit

Permalink
add beginning of example for cluster admin
Browse files Browse the repository at this point in the history
  • Loading branch information
badra001 committed Dec 30, 2022
1 parent 713dbcc commit 38b7af8
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
2 changes: 2 additions & 0 deletions examples/cluster-assume-role/group.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# add to user group
# aws_iam_policy.list_assume_policy.arn
33 changes: 33 additions & 0 deletions examples/cluster-assume-role/policies.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# we want the per-cluster assume policies, but adding them all to the role may exceed the limit. Here, we'll create a policy that
# includes all the clusters that this group woudl manage

data "aws_iam_role" "list" {
for_each = toset([for c in var.admin_cluster_list : format("r-eks-%v-cluster-admin", c)])
name = each.key
}

#---
# cluster admin assume policy
#---
resource "aws_iam_policy" "list_assume_policy" {
name = format("p-%v-cluster-admin-role-assume", local.app_name)
path = "/"
description = "Allow SAML role to assume cluster-admin roles"
policy = data.aws_iam_policy_document.cluster-admin_assume_policy.json

tags = merge(
local.base_tags,
# var.tags,
var.application_tags,
tomap({ "Name" = format("p-%v-cluster-admin-role-assume", local.app_name) }),
)
}

data "aws_iam_policy_document" "cluster-admin_assume_policy" {
statement {
sid = "AllowSTSAssumeClusterAdminRole"
effect = "Allow"
actions = ["sts:AssumeRole"]
resources = [for k, v in data.aws_iam_role.list : v.arn]
}
}
5 changes: 5 additions & 0 deletions examples/cluster-assume-role/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
variable "admin_cluster_list" {
description = "List of cluster names for which {cluster-name}-cluster-admin roles should be granted"
type = list(string)
default = []
}

0 comments on commit 38b7af8

Please sign in to comment.