Skip to content
This repository has been archived by the owner on Sep 27, 2024. It is now read-only.

Commit

Permalink
adds Flux policy for IRSA (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
UncleGedd authored Oct 4, 2022
1 parent da29c06 commit 527fa06
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# batcave-tf-irsa
This repo is a Terraform module that contains the code to create IAM roles and policies for the implementation of [IRSA](https://docs.aws.amazon.com/eks/latest/userguide/iam-roles-for-service-accounts.html) in Batcave clusters.
1 change: 0 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ resource "aws_iam_role" "this" {
count = var.create_role ? 1 : 0

name = var.role_name
name_prefix = var.role_name_prefix
path = var.role_path
description = var.role_description

Expand Down
49 changes: 49 additions & 0 deletions policies.tf
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,52 @@ resource "aws_iam_role_policy_attachment" "velero" {
role = aws_iam_role.this[0].name
policy_arn = aws_iam_policy.velero[0].arn
}

################################################################################
# Flux Policy
################################################################################
data "aws_kms_alias" "sops" {
name = "alias/batcave-landing-sops"
}

data "aws_iam_policy_document" "flux" {
count = var.create_role && var.attach_flux_policy ? 1 : 0

statement {
sid = "kmslist"
actions = [
"kms:List*",
"kms:Describe*"
]
resources = ["*"]
}

statement {
sid = "K8sNodes"
actions = [
"kms:Decrypt",
]
resources = [
data.aws_kms_alias.sops.arn,
data.aws_kms_alias.sops.target_key_arn,
]
}
}

resource "aws_iam_policy" "flux" {
count = var.create_role && var.attach_flux_policy ? 1 : 0

name_prefix = "${var.policy_name_prefix}Flux_Policy-"
path = var.role_path
description = "Provides Flux permissions to view and decrypt KMS keys"
policy = data.aws_iam_policy_document.flux[0].json

tags = var.tags
}

resource "aws_iam_role_policy_attachment" "flux" {
count = var.create_role && var.attach_flux_policy ? 1 : 0

role = aws_iam_role.this[0].name
policy_arn = aws_iam_policy.flux[0].arn
}
7 changes: 7 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,10 @@ variable "velero_s3_bucket_arns" {
type = list(string)
default = ["*"]
}

#Flux
variable "attach_flux_policy" {
description = "Determines whether to attach the Flux IAM policy to the role"
type = bool
default = false
}

0 comments on commit 527fa06

Please sign in to comment.