-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
348 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,167 @@ | ||
| resource "aws_iam_policy" "nlb-policy" { | ||
| name = format("%v%v-nlb", local.prefixes["eks-policy"], var.cluster_name) | ||
| path = "/" | ||
| description = "Allow configuration of the ELB" | ||
| policy = data.aws_iam_policy_document.nlb-policy.json | ||
|
|
||
| } | ||
|
|
||
| # Q: why CreateSecurityGroup | ||
| # TBD: refine resources to limit only to eks configurations | ||
| data "aws_iam_policy_document" "nlb-policy" { | ||
| statement { | ||
| sid = "EKSNLBConfiguration" | ||
| effect = "Allow" | ||
| actions = [ | ||
| "elasticloadbalancing:*", | ||
| "ec2:CreateSecurityGroup", | ||
| "ec2:Describe*", | ||
| ] | ||
| resources = ["*"] | ||
| } | ||
| } | ||
|
|
||
| resource "aws_iam_policy" "cloudwatch-policy" { | ||
| name = format("%v%v-cloudwatch", local.prefixes["eks-policy"], var.cluster_name) | ||
| path = "/" | ||
| description = "Allow sending metric data to cloudwatch" | ||
| policy = data.aws_iam_policy_document.cloudwatch-policy.json | ||
|
|
||
| } | ||
|
|
||
| # TBD: refine resources to limit only to eks configurations | ||
| data "aws_iam_policy_document" "cloudwatch-policy" { | ||
| statement { | ||
| sid = "EKSCloudwatchMetrics" | ||
| effect = "Allow" | ||
| actions = [ | ||
| "cloudwatch:PutMetricData", | ||
| ] | ||
| resources = ["*"] | ||
| } | ||
| } | ||
|
|
||
| #--- | ||
| # cluster admin policy | ||
| #--- | ||
| resource "aws_iam_policy" "cluster-admin-policy" { | ||
| name = format("%v%v-cluster-admin", local.prefixes["eks-policy"], var.cluster_name) | ||
| path = "/" | ||
| description = "Allow for administration of the cluster ${var.cluster_name} using AWS resources" | ||
| policy = data.aws_iam_policy_document.cluster-admin-policy.json | ||
|
|
||
| } | ||
|
|
||
| data "aws_iam_policy_document" "cluster-admin-policy" { | ||
| dynamic "statement" { | ||
| for_each = local.admin_policy_statements | ||
| iterator = s | ||
| content { | ||
| sid = format("%v%vAccess", lookup(s.value, "effect", "Allow"), s.key) | ||
| effect = lookup(s.value, "effect", "Allow") | ||
| actions = lookup(s.value, "actions", []) | ||
| resources = lookup(s.value, "resources", []) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| locals { | ||
| iam_arn = format("arn:%v:iam::%v:%%v", data.aws_arn.current.partition, data.aws_caller_identity.current.account_id) | ||
| common_arn = format("arn:%v:%%v:%v:%v:%%v", data.aws_arn.current.partition, data.aws_region.current.name, data.aws_caller_identity.current.account_id) | ||
| eks_resources = ["cluster", "addon", "nodegroup", "identityproviderconfig"] | ||
|
|
||
| admin_policy_statements = { | ||
| ECRRead = { | ||
| actions = [ | ||
| "ecr:Describe*", | ||
| "ecr:Get*", | ||
| "ecr:ListImages", | ||
| "ecr:BatchGetImage", | ||
| "ecr:BatchCheckLayerAvailability", | ||
| "ecr:GetDownloadUrlForLayer", | ||
| ] | ||
| resources = ["*"] | ||
| } | ||
| ECRWrite = { | ||
| actions = [ | ||
| "ecr:BatchDeleteImage", | ||
| "ecr:CompleteLayerUpload", | ||
| "ecr:CreateRepository", | ||
| "ecr:DeleteRepository", | ||
| "ecr:InitiateLayerUpload", | ||
| "ecr:PutImage", | ||
| "ecr:UploadLayerPart" | ||
| ] | ||
| resources = [format(local.common_arn, "ecr", format("repository/eks/%v/*", var.cluster_name))] | ||
| } | ||
| EKSRead = { | ||
| actions = [ | ||
| "eks:ListClusters", | ||
| "eks:ListAddons", | ||
| "eks:ListNodegroups", | ||
| "eks:DescribeCluster", | ||
| "eks:DescribeAddon*", | ||
| "eks:DescribeNodegroup", | ||
| ] | ||
| resources = [ | ||
| format(local.common_arn, "eks", "cluster/*"), | ||
| format(local.common_arn, "eks", "addon/*"), | ||
| format(local.common_arn, "eks", "addons/*"), | ||
| format(local.common_arn, "eks", "/addons/*"), | ||
| format(local.common_arn, "eks", "nodegroup/*"), | ||
| ] | ||
| } | ||
| IAMRead = { | ||
| actions = [ | ||
| "iam:ListRoles", | ||
| ] | ||
| resources = ["*"] | ||
| } | ||
| SSMGet = { | ||
| actions = [ | ||
| "ssm:GetParameter", | ||
| ] | ||
| resources = [ | ||
| format("arn:%v:%v:%v:%v:%v", data.aws_arn.current.partition, "ssm", data.aws_region.current.name, "", "parameter/aws/service/eks/*") | ||
| ] | ||
| } | ||
| EKSReadMyClusters = { | ||
| actions = [ | ||
| "eks:List*", | ||
| "eks:Read*", | ||
| "eks:Describe*", | ||
| "eks:AccessKubernetesApi", | ||
| ] | ||
| resources = flatten(concat( | ||
| [format(local.common_arn, "eks", format("/clusters/%v/addons", var.cluster_name))], | ||
| [for r in local.eks_resources : [format(local.common_arn, "eks", format("%v/%v", r, var.cluster_name)), | ||
| format(local.common_arn, "eks", format("%v/%v/*", r, var.cluster_name))]] | ||
| )) | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
| #--- | ||
| # cluster admin assume policy | ||
| #--- | ||
| resource "aws_iam_policy" "cluster-admin_assume_policy" { | ||
| name = format("%v%v-cluster-admin-assume", local.prefixes["eks-policy"], var.cluster_name) | ||
| path = "/" | ||
| description = "Allow for assume role to the cluster-admin role for ${var.cluster_name}" | ||
| policy = data.aws_iam_policy_document.cluster-admin_assume_policy.json | ||
|
|
||
| tags = merge( | ||
| local.base_tags, | ||
| tomap({ "Name" = format("%v%v-cluster-admin-assume", local.prefixes["eks-policy"], var.cluster_name) }), | ||
| ) | ||
| } | ||
|
|
||
| data "aws_iam_policy_document" "cluster-admin_assume_policy" { | ||
| statement { | ||
| sid = "AllowSTSAssumeClusterAdminRole" | ||
| effect = "Allow" | ||
| actions = ["sts:AssumeRole"] | ||
| resources = [module.role_cluster-admin.role_arn] | ||
| } | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.