Skip to content

Commit 801ce9b

Browse files
committed
feat: Add support for Mountpoint S3 CSI driver
1 parent b75e8de commit 801ce9b

File tree

6 files changed

+123
-10
lines changed

6 files changed

+123
-10
lines changed

README.md

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,22 @@ module "amazon_managed_service_prometheus_pod_identity" {
286286
}
287287
```
288288

289+
### [Mountpoint S3 CSI Driver](https://github.com/awslabs/mountpoint-s3)
290+
291+
module "mountpoint_s3_csi_pod_identity" {
292+
source = "terraform-aws-modules/eks-pod-identity/aws"
293+
294+
name = "mountpoint-s3-csi"
295+
296+
attach_mountpoint_s3_csi_policy = true
297+
mountpoint_s3_csi_bucket_arns = ["arn:aws:s3:::mountpoint-s3"]
298+
mountpoint_s3_csi_bucket_path_arns = ["arn:aws:s3:::mountpoint-s3/example/*"]
299+
300+
tags = {
301+
Environment = "dev"
302+
}
303+
}
304+
289305
### [AWS Node Termination Handler](https://github.com/aws/aws-node-termination-handler)
290306

291307
```hcl
@@ -327,9 +343,9 @@ module "velero_pod_identity" {
327343
328344
name = "velero"
329345
330-
attach_velero_policy = true
331-
velero_s3_bucket_arns = ["arn:aws:s3:::velero-backups"]
332-
velero_s3_bucket_paths = ["arn:aws:s3:::velero-backups/example/*"]
346+
attach_velero_policy = true
347+
velero_s3_bucket_arns = ["arn:aws:s3:::velero-backups"]
348+
velero_s3_bucket_path_arns = ["arn:aws:s3:::velero-backups/example/*"]
333349
334350
tags = {
335351
Environment = "dev"
@@ -414,6 +430,7 @@ No modules.
414430
| [aws_iam_policy.fsx_lustre_csi](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy) | resource |
415431
| [aws_iam_policy.lb_controller](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy) | resource |
416432
| [aws_iam_policy.lb_controller_targetgroup_only](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy) | resource |
433+
| [aws_iam_policy.mountpoint_s3_csi](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy) | resource |
417434
| [aws_iam_policy.node_termination_handler](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy) | resource |
418435
| [aws_iam_policy.velero](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy) | resource |
419436
| [aws_iam_policy.vpc_cni](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy) | resource |
@@ -434,6 +451,7 @@ No modules.
434451
| [aws_iam_role_policy_attachment.fsx_lustre_csi](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
435452
| [aws_iam_role_policy_attachment.lb_controller](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
436453
| [aws_iam_role_policy_attachment.lb_controller_targetgroup_only](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
454+
| [aws_iam_role_policy_attachment.mountpoint_s3_csi](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
437455
| [aws_iam_role_policy_attachment.node_termination_handler](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
438456
| [aws_iam_role_policy_attachment.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
439457
| [aws_iam_role_policy_attachment.velero](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
@@ -454,6 +472,7 @@ No modules.
454472
| [aws_iam_policy_document.fsx_lustre_csi](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
455473
| [aws_iam_policy_document.lb_controller](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
456474
| [aws_iam_policy_document.lb_controller_targetgroup_only](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
475+
| [aws_iam_policy_document.mountpoint_s3_csi](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
457476
| [aws_iam_policy_document.node_termination_handler](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
458477
| [aws_iam_policy_document.velero](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
459478
| [aws_iam_policy_document.vpc_cni](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
@@ -486,6 +505,7 @@ No modules.
486505
| <a name="input_attach_custom_policy"></a> [attach\_custom\_policy](#input\_attach\_custom\_policy) | Determines whether to attach the custom IAM policy to the role | `bool` | `false` | no |
487506
| <a name="input_attach_external_dns_policy"></a> [attach\_external\_dns\_policy](#input\_attach\_external\_dns\_policy) | Determines whether to attach the External DNS IAM policy to the role | `bool` | `false` | no |
488507
| <a name="input_attach_external_secrets_policy"></a> [attach\_external\_secrets\_policy](#input\_attach\_external\_secrets\_policy) | Determines whether to attach the External Secrets policy to the role | `bool` | `false` | no |
508+
| <a name="input_attach_mountpoint_s3_csi_policy"></a> [attach\_mountpoint\_s3\_csi\_policy](#input\_attach\_mountpoint\_s3\_csi\_policy) | Determines whether to attach the Mountpoint S3 CSI IAM policy to the role | `bool` | `false` | no |
489509
| <a name="input_attach_velero_policy"></a> [attach\_velero\_policy](#input\_attach\_velero\_policy) | Determines whether to attach the Velero IAM policy to the role | `bool` | `false` | no |
490510
| <a name="input_aws_ebs_csi_kms_arns"></a> [aws\_ebs\_csi\_kms\_arns](#input\_aws\_ebs\_csi\_kms\_arns) | KMS key ARNs to allow EBS CSI to manage encrypted volumes | `list(string)` | `[]` | no |
491511
| <a name="input_aws_ebs_csi_policy_name"></a> [aws\_ebs\_csi\_policy\_name](#input\_aws\_ebs\_csi\_policy\_name) | Custom name of the EBS CSI IAM policy | `string` | `null` | no |
@@ -518,6 +538,9 @@ No modules.
518538
| <a name="input_external_secrets_secrets_manager_arns"></a> [external\_secrets\_secrets\_manager\_arns](#input\_external\_secrets\_secrets\_manager\_arns) | List of Secrets Manager ARNs that contain secrets to mount using External Secrets | `list(string)` | `[]` | no |
519539
| <a name="input_external_secrets_ssm_parameter_arns"></a> [external\_secrets\_ssm\_parameter\_arns](#input\_external\_secrets\_ssm\_parameter\_arns) | List of Systems Manager Parameter ARNs that contain secrets to mount using External Secrets | `list(string)` | `[]` | no |
520540
| <a name="input_max_session_duration"></a> [max\_session\_duration](#input\_max\_session\_duration) | Maximum CLI/API session duration in seconds between 3600 and 43200 | `number` | `null` | no |
541+
| <a name="input_mountpoint_s3_csi_bucket_arns"></a> [mountpoint\_s3\_csi\_bucket\_arns](#input\_mountpoint\_s3\_csi\_bucket\_arns) | List of S3 Bucket ARNs that Mountpoint S3 CSI needs access to list | `list(string)` | `[]` | no |
542+
| <a name="input_mountpoint_s3_csi_bucket_path_arns"></a> [mountpoint\_s3\_csi\_bucket\_path\_arns](#input\_mountpoint\_s3\_csi\_bucket\_path\_arns) | S3 path ARNs to allow Mountpoint S3 CSI driver to manage items at the provided path(s). This is required if `attach_mountpoint_s3_csi_policy = true` | `list(string)` | `[]` | no |
543+
| <a name="input_mountpoint_s3_csi_policy_name"></a> [mountpoint\_s3\_csi\_policy\_name](#input\_mountpoint\_s3\_csi\_policy\_name) | Custom name of the Mountpoint S3 CSI IAM policy | `string` | `null` | no |
521544
| <a name="input_name"></a> [name](#input\_name) | Name of IAM role | `string` | `""` | no |
522545
| <a name="input_override_policy_documents"></a> [override\_policy\_documents](#input\_override\_policy\_documents) | List of IAM policy documents that are merged together into the exported document | `list(string)` | `[]` | no |
523546
| <a name="input_path"></a> [path](#input\_path) | Path of IAM role | `string` | `"/"` | no |
@@ -530,7 +553,7 @@ No modules.
530553
| <a name="input_use_name_prefix"></a> [use\_name\_prefix](#input\_use\_name\_prefix) | Determines whether the role name and policy name(s) are used as a prefix | `string` | `true` | no |
531554
| <a name="input_velero_policy_name"></a> [velero\_policy\_name](#input\_velero\_policy\_name) | Custom name of the Velero IAM policy | `string` | `null` | no |
532555
| <a name="input_velero_s3_bucket_arns"></a> [velero\_s3\_bucket\_arns](#input\_velero\_s3\_bucket\_arns) | List of S3 Bucket ARNs that Velero needs access to list | `list(string)` | `[]` | no |
533-
| <a name="input_velero_s3_bucket_paths"></a> [velero\_s3\_bucket\_paths](#input\_velero\_s3\_bucket\_paths) | List of S3 Bucket paths that Velero needs access to in order to backup and restore cluster resources | `list(string)` | `[]` | no |
556+
| <a name="input_velero_s3_bucket_path_arns"></a> [velero\_s3\_bucket\_path\_arns](#input\_velero\_s3\_bucket\_path\_arns) | S3 path ARNs to allow Velero to manage items at the provided path(s). This is required if `attach_mountpoint_s3_csi_policy = true` | `list(string)` | `[]` | no |
534557

535558
## Outputs
536559

examples/complete/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ Note that this example may create resources which will incur monetary charges on
5252
| <a name="module_disabled"></a> [disabled](#module\_disabled) | ../../ | n/a |
5353
| <a name="module_external_dns_pod_identity"></a> [external\_dns\_pod\_identity](#module\_external\_dns\_pod\_identity) | ../../ | n/a |
5454
| <a name="module_external_secrets_pod_identity"></a> [external\_secrets\_pod\_identity](#module\_external\_secrets\_pod\_identity) | ../../ | n/a |
55+
| <a name="module_mountpoint_s3_csi_pod_identity"></a> [mountpoint\_s3\_csi\_pod\_identity](#module\_mountpoint\_s3\_csi\_pod\_identity) | ../../ | n/a |
5556
| <a name="module_velero_pod_identity"></a> [velero\_pod\_identity](#module\_velero\_pod\_identity) | ../../ | n/a |
5657

5758
## Resources

examples/complete/main.tf

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,18 @@ module "amazon_managed_service_prometheus_pod_identity" {
185185
tags = local.tags
186186
}
187187

188+
module "mountpoint_s3_csi_pod_identity" {
189+
source = "../../"
190+
191+
name = "mountpoint-s3-csi"
192+
193+
attach_mountpoint_s3_csi_policy = true
194+
mountpoint_s3_csi_bucket_arns = ["arn:aws:s3:::mountpoint-s3"]
195+
mountpoint_s3_csi_bucket_path_arns = ["arn:aws:s3:::mountpoint-s3/example/*"]
196+
197+
tags = local.tags
198+
}
199+
188200
module "aws_node_termination_handler_pod_identity" {
189201
source = "../../"
190202

@@ -212,9 +224,9 @@ module "velero_pod_identity" {
212224

213225
name = "velero"
214226

215-
attach_velero_policy = true
216-
velero_s3_bucket_arns = ["arn:aws:s3:::velero-backups"]
217-
velero_s3_bucket_paths = ["arn:aws:s3:::velero-backups/example/*"]
227+
attach_velero_policy = true
228+
velero_s3_bucket_arns = ["arn:aws:s3:::velero-backups"]
229+
velero_s3_bucket_path_arns = ["arn:aws:s3:::velero-backups/example/*"]
218230

219231
tags = local.tags
220232
}

mountpoint_s3_csi.tf

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
################################################################################
2+
# Mountpoint S3 CSI Driver Policy
3+
################################################################################
4+
5+
#https://github.com/awslabs/mountpoint-s3/blob/main/doc/CONFIGURATION.md#iam-permissions
6+
7+
data "aws_iam_policy_document" "mountpoint_s3_csi" {
8+
count = var.create && var.attach_mountpoint_s3_csi_policy ? 1 : 0
9+
10+
source_policy_documents = [data.aws_iam_policy_document.base[0].json]
11+
override_policy_documents = var.override_policy_documents
12+
13+
statement {
14+
sid = "MountpointFullBucketAccess"
15+
actions = ["s3:ListBucket"]
16+
resources = coalescelist(var.mountpoint_s3_csi_bucket_arns, ["arn:${local.partition}:s3:::*"])
17+
}
18+
19+
statement {
20+
sid = "MountpointFullObjectAccess"
21+
actions = [
22+
"s3:GetObject",
23+
"s3:PutObject",
24+
"s3:AbortMultipartUpload",
25+
"s3:DeleteObject"
26+
]
27+
resources = var.mountpoint_s3_csi_bucket_path_arns
28+
}
29+
}
30+
31+
locals {
32+
mountpoint_s3_csi_policy_name = coalesce(var.mountpoint_s3_csi_policy_name, "${var.policy_name_prefix}MountpointS3CSI")
33+
}
34+
35+
resource "aws_iam_policy" "mountpoint_s3_csi" {
36+
count = var.create && var.attach_mountpoint_s3_csi_policy ? 1 : 0
37+
38+
name = var.use_name_prefix ? null : local.mountpoint_s3_csi_policy_name
39+
name_prefix = var.use_name_prefix ? "${local.mountpoint_s3_csi_policy_name}-" : null
40+
path = var.path
41+
description = "Permissions for Mountpoint S3 CSI Driver"
42+
policy = data.aws_iam_policy_document.mountpoint_s3_csi[0].json
43+
44+
tags = var.tags
45+
}
46+
47+
resource "aws_iam_role_policy_attachment" "mountpoint_s3_csi" {
48+
count = var.create && var.attach_mountpoint_s3_csi_policy ? 1 : 0
49+
50+
role = aws_iam_role.this[0].name
51+
policy_arn = aws_iam_policy.mountpoint_s3_csi[0].arn
52+
}

variables.tf

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,31 @@ variable "external_secrets_create_permission" {
412412
default = false
413413
}
414414

415+
# Mountpoint S3 CSI
416+
variable "attach_mountpoint_s3_csi_policy" {
417+
description = "Determines whether to attach the Mountpoint S3 CSI IAM policy to the role"
418+
type = bool
419+
default = false
420+
}
421+
422+
variable "mountpoint_s3_csi_policy_name" {
423+
description = "Custom name of the Mountpoint S3 CSI IAM policy"
424+
type = string
425+
default = null
426+
}
427+
428+
variable "mountpoint_s3_csi_bucket_arns" {
429+
description = "List of S3 Bucket ARNs that Mountpoint S3 CSI needs access to list"
430+
type = list(string)
431+
default = []
432+
}
433+
434+
variable "mountpoint_s3_csi_bucket_path_arns" {
435+
description = "S3 path ARNs to allow Mountpoint S3 CSI driver to manage items at the provided path(s). This is required if `attach_mountpoint_s3_csi_policy = true`"
436+
type = list(string)
437+
default = []
438+
}
439+
415440
# Velero
416441
variable "attach_velero_policy" {
417442
description = "Determines whether to attach the Velero IAM policy to the role"
@@ -431,8 +456,8 @@ variable "velero_s3_bucket_arns" {
431456
default = []
432457
}
433458

434-
variable "velero_s3_bucket_paths" {
435-
description = "List of S3 Bucket paths that Velero needs access to in order to backup and restore cluster resources"
459+
variable "velero_s3_bucket_path_arns" {
460+
description = "S3 path ARNs to allow Velero to manage items at the provided path(s). This is required if `attach_mountpoint_s3_csi_policy = true`"
436461
type = list(string)
437462
default = []
438463
}

velero.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ data "aws_iam_policy_document" "velero" {
3333
"s3:AbortMultipartUpload",
3434
"s3:ListMultipartUploadParts",
3535
]
36-
resources = var.velero_s3_bucket_paths
36+
resources = var.velero_s3_bucket_path_arns
3737
}
3838

3939
statement {

0 commit comments

Comments
 (0)