Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: IAM Policy improvements on AppMesh Controller Add-on for TFSec compliance rules compliance. #1373

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 115 additions & 0 deletions modules/kubernetes-addons/appmesh-controller/data.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
data "aws_iam_policy_document" "this" {
statement {
sid = "AllowAppMesh"
effect = "Allow"
resources = ["arn:${var.addon_context.aws_partition_id}:appmesh:${var.addon_context.aws_region_name}:${var.addon_context.aws_caller_identity_account_id}:mesh/*"]

actions = [
"appmesh:ListVirtualRouters",
"appmesh:ListVirtualServices",
"appmesh:ListRoutes",
"appmesh:ListGatewayRoutes",
"appmesh:ListMeshes",
"appmesh:ListVirtualNodes",
"appmesh:ListVirtualGateways",
"appmesh:DescribeMesh",
"appmesh:DescribeVirtualRouter",
"appmesh:DescribeRoute",
"appmesh:DescribeVirtualNode",
"appmesh:DescribeVirtualGateway",
"appmesh:DescribeGatewayRoute",
"appmesh:DescribeVirtualService",
"appmesh:CreateMesh",
"appmesh:CreateVirtualRouter",
"appmesh:CreateVirtualGateway",
"appmesh:CreateVirtualService",
"appmesh:CreateGatewayRoute",
"appmesh:CreateRoute",
"appmesh:CreateVirtualNode",
"appmesh:UpdateMesh",
"appmesh:UpdateRoute",
"appmesh:UpdateVirtualGateway",
"appmesh:UpdateVirtualRouter",
"appmesh:UpdateGatewayRoute",
"appmesh:UpdateVirtualService",
"appmesh:UpdateVirtualNode",
"appmesh:DeleteMesh",
"appmesh:DeleteRoute",
"appmesh:DeleteVirtualRouter",
"appmesh:DeleteGatewayRoute",
"appmesh:DeleteVirtualService",
"appmesh:DeleteVirtualNode",
"appmesh:DeleteVirtualGateway"
]
}

statement {
sid = "CreateServiceLinkedRole"
effect = "Allow"
resources = ["arn:${var.addon_context.aws_partition_id}:iam::${var.addon_context.aws_caller_identity_account_id}:role/aws-service-role/appmesh.${local.dns_suffix}/AWSServiceRoleForAppMesh"]
actions = ["iam:CreateServiceLinkedRole"]

condition {
test = "StringLike"
variable = "iam:AWSServiceName"
values = ["appmesh.${local.dns_suffix}"]
}
}

statement {
sid = "AllowACMAccess"
effect = "Allow"
resources = ["arn:${var.addon_context.aws_partition_id}:acm:${var.addon_context.aws_region_name}:${var.addon_context.aws_caller_identity_account_id}:certificate/*"]
actions = [
"acm:ListCertificates",
"acm:DescribeCertificate",
]
}

statement {
sid = "AllowACMPCAAccess"
effect = "Allow"
resources = ["arn:${var.addon_context.aws_partition_id}:acm-pca:${var.addon_context.aws_region_name}:${var.addon_context.aws_caller_identity_account_id}:certificate-authority/*"]
actions = [
"acm-pca:DescribeCertificateAuthority",
"acm-pca:ListCertificateAuthorities"
]
}

statement {
sid = "AllowServiceDiscovery"
effect = "Allow"
resources = [
"arn:${var.addon_context.aws_partition_id}:servicediscovery:${var.addon_context.aws_region_name}:${var.addon_context.aws_caller_identity_account_id}:namespace/*",
"arn:${var.addon_context.aws_partition_id}:servicediscovery:${var.addon_context.aws_region_name}:${var.addon_context.aws_caller_identity_account_id}:service/*"
]
actions = [
"servicediscovery:CreateService",
"servicediscovery:DeleteService",
"servicediscovery:GetService",
"servicediscovery:GetInstance",
"servicediscovery:RegisterInstance",
"servicediscovery:DeregisterInstance",
"servicediscovery:ListInstances",
"servicediscovery:ListNamespaces",
"servicediscovery:ListServices",
"servicediscovery:GetInstancesHealthStatus",
"servicediscovery:UpdateInstanceCustomHealthStatus",
"servicediscovery:GetOperation"
]
}

statement {
sid = "AllowRoute53"
effect = "Allow"
resources = [
"arn:${var.addon_context.aws_partition_id}:route53:::*"]
actions = [
"route53:ChangeResourceRecordSets",
"route53:GetHealthCheck",
"route53:CreateHealthCheck",
"route53:UpdateHealthCheck",
"route53:DeleteHealthCheck"
]
}
}
97 changes: 0 additions & 97 deletions modules/kubernetes-addons/appmesh-controller/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ locals {
name = try(var.helm_config.name, "appmesh-controller")
namespace = try(var.helm_config.namespace, "appmesh-system")

partition = data.aws_partition.current.partition
dns_suffix = data.aws_partition.current.dns_suffix
}

Expand Down Expand Up @@ -52,99 +51,3 @@ resource "aws_iam_policy" "this" {
description = "IAM Policy for App Mesh"
policy = data.aws_iam_policy_document.this.json
}

data "aws_iam_policy_document" "this" {
statement {
sid = "appmesh"
effect = "Allow"
resources = ["*"]

actions = [
"appmesh:ListVirtualRouters",
"appmesh:ListVirtualServices",
"appmesh:ListRoutes",
"appmesh:ListGatewayRoutes",
"appmesh:ListMeshes",
"appmesh:ListVirtualNodes",
"appmesh:ListVirtualGateways",
"appmesh:DescribeMesh",
"appmesh:DescribeVirtualRouter",
"appmesh:DescribeRoute",
"appmesh:DescribeVirtualNode",
"appmesh:DescribeVirtualGateway",
"appmesh:DescribeGatewayRoute",
"appmesh:DescribeVirtualService",
"appmesh:CreateMesh",
"appmesh:CreateVirtualRouter",
"appmesh:CreateVirtualGateway",
"appmesh:CreateVirtualService",
"appmesh:CreateGatewayRoute",
"appmesh:CreateRoute",
"appmesh:CreateVirtualNode",
"appmesh:UpdateMesh",
"appmesh:UpdateRoute",
"appmesh:UpdateVirtualGateway",
"appmesh:UpdateVirtualRouter",
"appmesh:UpdateGatewayRoute",
"appmesh:UpdateVirtualService",
"appmesh:UpdateVirtualNode",
"appmesh:DeleteMesh",
"appmesh:DeleteRoute",
"appmesh:DeleteVirtualRouter",
"appmesh:DeleteGatewayRoute",
"appmesh:DeleteVirtualService",
"appmesh:DeleteVirtualNode",
"appmesh:DeleteVirtualGateway"
]
}

statement {
sid = "CreateServiceLinkedRole"
effect = "Allow"
resources = ["arn:${local.partition}:iam::*:role/aws-service-role/appmesh.${local.dns_suffix}/AWSServiceRoleForAppMesh"]
actions = ["iam:CreateServiceLinkedRole"]

condition {
test = "StringLike"
variable = "iam:AWSServiceName"
values = ["appmesh.${local.dns_suffix}"]
}
}

statement {
sid = "ACMAccess"
effect = "Allow"
resources = ["*"]
actions = [
"acm:ListCertificates",
"acm:DescribeCertificate",
"acm-pca:DescribeCertificateAuthority",
"acm-pca:ListCertificateAuthorities"
]
}

statement {
sid = "ServiceDiscovery"
effect = "Allow"
resources = ["*"]
actions = [
"servicediscovery:CreateService",
"servicediscovery:DeleteService",
"servicediscovery:GetService",
"servicediscovery:GetInstance",
"servicediscovery:RegisterInstance",
"servicediscovery:DeregisterInstance",
"servicediscovery:ListInstances",
"servicediscovery:ListNamespaces",
"servicediscovery:ListServices",
"servicediscovery:GetInstancesHealthStatus",
"servicediscovery:UpdateInstanceCustomHealthStatus",
"servicediscovery:GetOperation",
"route53:GetHealthCheck",
"route53:CreateHealthCheck",
"route53:UpdateHealthCheck",
"route53:ChangeResourceRecordSets",
"route53:DeleteHealthCheck"
]
}
}