Skip to content

Commit

Permalink
terraform - kms.tf
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelberston committed Nov 26, 2024
1 parent 9b791a3 commit 7ff6ba0
Showing 1 changed file with 85 additions and 0 deletions.
85 changes: 85 additions & 0 deletions terraform/kms.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
resource "aws_kms_key" "eks" {
description = "EKS Secret Encryption Key"
deletion_window_in_days = 7
enable_key_rotation = true

policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Sid = "Enable Root Account Permissions"
Effect = "Allow"
Principal = {
AWS = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:root"
}
Action = "kms:*"
Resource = "*"
},
{
Sid = "Allow EKS Service"
Effect = "Allow"
Principal = {
Service = "eks.amazonaws.com"
}
Action = [
"kms:Encrypt",
"kms:Decrypt",
"kms:CreateGrant",
"kms:DescribeKey"
]
Resource = "*"
},
{
Sid = "Allow EKS Node Group Role"
Effect = "Allow"
Principal = {
AWS = aws_iam_role.eks_node_group_role.arn
}
Action = [
"kms:Decrypt",
"kms:DescribeKey",
"kms:Encrypt",
"kms:GenerateDataKey*"
]
Resource = "*"
},
{
Sid = "Allow EKS Admin Role"
Effect = "Allow"
Principal = {
AWS = aws_iam_role.eks_admin.arn
}
Action = [
"kms:Decrypt",
"kms:DescribeKey",
"kms:Encrypt",
"kms:GenerateDataKey*"
]
Resource = "*"
},
{
Sid = "Allow EKS Cluster Role" // Add this block
Effect = "Allow"
Principal = {
AWS = aws_iam_role.eks_cluster_role.arn
}
Action = [
"kms:Decrypt",
"kms:DescribeKey",
"kms:Encrypt",
"kms:GenerateDataKey*",
"kms:CreateGrant",
"kms:ListGrants",
"kms:RevokeGrant"
]
Resource = "*"
},
]
})
}

# Add an alias for easier key management
resource "aws_kms_alias" "eks" {
name = "alias/eks-secure-auth-cluster-v2"
target_key_id = aws_kms_key.eks.key_id
}

0 comments on commit 7ff6ba0

Please sign in to comment.