-
Notifications
You must be signed in to change notification settings - Fork 25
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
Add clamev efs #725
Merged
Merged
Add clamev efs #725
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
8 changes: 4 additions & 4 deletions
8
terraform/deployments/cluster-infrastructure/aws_ebs_csi_iam.tf
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
66 changes: 66 additions & 0 deletions
66
terraform/deployments/cluster-infrastructure/aws_efs_csi_iam.tf
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,66 @@ | ||
locals { | ||
efs_csi_driver_controller_service_account_name = "efs-csi-controller-sa" | ||
} | ||
|
||
module "aws_efs_csi_driver_iam_role" { | ||
source = "terraform-aws-modules/iam/aws//modules/iam-assumable-role-with-oidc" | ||
version = "~> 4.0" | ||
create_role = true | ||
role_name = "${local.efs_csi_driver_controller_service_account_name}-${var.cluster_name}" | ||
role_description = "Role for the AWS EFS CSI driver controller. Corresponds to ${local.efs_csi_driver_controller_service_account_name} k8s ServiceAccount." | ||
provider_url = module.eks.oidc_provider | ||
role_policy_arns = [aws_iam_policy.aws_efs_csi_driver.arn] | ||
oidc_fully_qualified_subjects = ["system:serviceaccount:kube-system:${local.efs_csi_driver_controller_service_account_name}"] | ||
} | ||
|
||
resource "aws_iam_role_policy_attachment" "eks_nodes_efs" { | ||
role = module.eks.eks_managed_node_groups["main"].iam_role_name | ||
policy_arn = aws_iam_policy.aws_efs_csi_driver.arn | ||
} | ||
|
||
resource "aws_iam_policy" "aws_efs_csi_driver" { | ||
name = "AWSEfsCsiController-${var.cluster_name}" | ||
description = "Allow the driver to manage AWS EFS" | ||
|
||
# The argument to jsonencode() is the verbatim contents of | ||
# https://github.com/kubernetes-sigs/aws-efs-csi-driver/blob/master/docs/iam-policy-example.json | ||
# (except for whitespace changes from terraform fmt). | ||
policy = jsonencode({ | ||
|
||
"Version" : "2012-10-17", | ||
"Statement" : [ | ||
{ | ||
"Effect" : "Allow", | ||
"Action" : [ | ||
"elasticfilesystem:DescribeAccessPoints", | ||
"elasticfilesystem:DescribeFileSystems", | ||
"elasticfilesystem:DescribeMountTargets", | ||
"ec2:DescribeAvailabilityZones" | ||
], | ||
"Resource" : "*" | ||
}, | ||
{ | ||
"Effect" : "Allow", | ||
"Action" : [ | ||
"elasticfilesystem:CreateAccessPoint" | ||
], | ||
"Resource" : "*", | ||
"Condition" : { | ||
"StringLike" : { | ||
"aws:RequestTag/efs.csi.aws.com/cluster" : "true" | ||
} | ||
} | ||
}, | ||
{ | ||
"Effect" : "Allow", | ||
"Action" : "elasticfilesystem:DeleteAccessPoint", | ||
"Resource" : "*", | ||
"Condition" : { | ||
"StringEquals" : { | ||
"aws:ResourceTag/efs.csi.aws.com/cluster" : "true" | ||
} | ||
} | ||
} | ||
] | ||
}) | ||
} |
31 changes: 31 additions & 0 deletions
31
terraform/deployments/cluster-infrastructure/clamav_db_efs.tf
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,31 @@ | ||
locals { | ||
clamav_db_name = "clamav-db-${var.cluster_name}" | ||
} | ||
|
||
resource "aws_efs_file_system" "clamav-db" { | ||
creation_token = local.clamav_db_name | ||
tags = { "Description" = "EFS where Clamav virus signature database is stored" } | ||
} | ||
|
||
resource "aws_security_group" "clamav-db" { | ||
name = local.clamav_db_name | ||
vpc_id = data.terraform_remote_state.infra_vpc.outputs.vpc_id | ||
description = "Security group of ${local.clamav_db_name}" | ||
} | ||
|
||
resource "aws_security_group_rule" "clamav_db_from_eks_workers" { | ||
description = "Clamav DB EFS accepts requests from EKS nodes" | ||
type = "ingress" | ||
from_port = 2049 | ||
to_port = 2049 | ||
protocol = "tcp" | ||
security_group_id = aws_security_group.clamav-db.id | ||
source_security_group_id = local.node_security_group_id | ||
} | ||
|
||
resource "aws_efs_mount_target" "clamav-db-mount-targets" { | ||
for_each = toset(data.terraform_remote_state.infra_networking.outputs.private_subnet_ids) | ||
file_system_id = aws_efs_file_system.clamav-db.id | ||
subnet_id = each.key | ||
security_groups = [aws_security_group.clamav-db.id] | ||
} | ||
fredericfran-gds marked this conversation as resolved.
Show resolved
Hide resolved
|
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
31 changes: 31 additions & 0 deletions
31
terraform/deployments/cluster-services/aws_efs_csi_driver.tf
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,31 @@ | ||
resource "helm_release" "efs_csi_driver" { | ||
chart = "aws-efs-csi-driver" | ||
name = "aws-efs-csi-driver" | ||
namespace = "kube-system" | ||
repository = "https://kubernetes-sigs.github.io/aws-efs-csi-driver" | ||
version = "2.2.7" # TODO: Dependabot or equivalent so this doesn't get neglected. | ||
|
||
values = [yamlencode({ | ||
controller = { | ||
serviceAccount = { | ||
create = true | ||
name = data.terraform_remote_state.cluster_infrastructure.outputs.aws_efs_csi_driver_controller_service_account_name | ||
annotations = { | ||
"eks.amazonaws.com/role-arn" = data.terraform_remote_state.cluster_infrastructure.outputs.aws_efs_csi_driver_iam_role_arn | ||
} | ||
} | ||
} | ||
storageClasses = [{ | ||
name = "clamav-db-efs-sc" | ||
apiVersion = "storage.k8s.io/v1" | ||
mountOptions = ["tls"] | ||
parameters = { | ||
provisioningMode = "efs-ap" | ||
fileSystemId = data.terraform_remote_state.cluster_infrastructure.outputs.clamav_db_efs_id | ||
directoryPerms = "755" | ||
} | ||
reclaimPolicy = "Retain" | ||
volumeBindingMode = "WaitForFirstConsumer" | ||
}] | ||
})] | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like you have a service account for the controller, but you're attaching the policy to the nodes. You want to attach the policy to the IAM role that corresponds to the k8s serviceaccount, right?
If you attach the policy to the nodes, you're granting all pods the ability to manage EFS — which is presumably what you're trying to avoid by creating the serviceaccount and corresponding IRSA IAM role etc.?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got the info from here, the same specs for csi driver and eks nodes: https://github.com/kubernetes-sigs/aws-efs-csi-driver#installation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right so where it talks about "several methods to grant IAM permission", you want the first one (IAM Role for Service Account). It looks like you're kinda doing both here at the moment though.