Skip to content

feat: Add ebs_csi_restrict_tagging_to_create to allow EBS CSI tag modification on existing volumes - #651

Open
somaz94 wants to merge 4 commits into
terraform-aws-modules:masterfrom
somaz94:fix/ebs-csi-volume-tagging
Open

somaz94 wants to merge 4 commits into
terraform-aws-modules:masterfrom
somaz94:fix/ebs-csi-volume-tagging

Conversation

@somaz94

@somaz94 somaz94 commented Jun 24, 2026 •

Copy link
Copy Markdown

Description

The EBS CSI policy grants ec2:CreateTags only with a ec2:CreateAction condition (CreateVolume / CreateSnapshot), so the driver can tag volumes at creation but cannot tag existing volumes. This blocks VolumeAttributesClass tag modifications, which fail with UnauthorizedOperation: ... ec2:CreateTags.

This adds an ebs_csi_restrict_tagging_to_create variable (default true). At the default the ec2:CreateAction condition stays exactly as it is today. Setting it to false drops the condition so the driver can tag existing volumes/snapshots. The relaxation is an explicit opt-out because the upstream EBS CSI driver leaves this permission out of its example policy on purpose, so existing users see no change unless they ask for it.

Note ec2:DeleteTags in the same policy is already unconditional, so this restores the symmetry for tag modification.

Motivation and Context

Fixes #649 (and the earlier, stale-closed #630).

Breaking Changes

None. The default true renders a policy that is byte-identical to master.

How Has This Been Tested?

terraform fmt -recursive -check, terraform validate on modules/iam-role-for-service-accounts and wrappers/iam-role-for-service-accounts, and pre-commit run -a all pass, and terraform-docs was regenerated so the submodule README inputs table matches. I also rendered the aws_iam_policy document with attach_ebs_csi_policy = true via terraform plan and terraform show -json: at the default it is byte-identical to master, and with ebs_csi_restrict_tagging_to_create = false the only difference is the missing ec2:CreateAction condition on the ec2:CreateTags statement.

@somaz94
somaz94 marked this pull request as ready for review June 26, 2026 02:33
@github-actions

Copy link
Copy Markdown

This PR has been automatically marked as stale because it has been open 30 days
with no activity. Remove stale label or comment or this PR will be closed in 10 days

@github-actions github-actions Bot added the stale label Jul 27, 2026
@somaz94

somaz94 commented Jul 27, 2026

Copy link
Copy Markdown
Author

Still relevant — CI is green.

@github-actions github-actions Bot removed the stale label Jul 28, 2026
variable "ebs_csi_volume_tagging" {
description = "Determines whether to allow the EBS CSI driver to tag existing volumes/snapshots by removing the `ec2:CreateAction` condition on `ec2:CreateTags`. Required for `VolumeAttributesClass` tag modifications; disabled by default as it broadens tagging permissions"
type = bool
default = false

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this default would automatically remove permissions which makes it a breaking change - must be true for backwards compatibility and users will have to opt into disabling

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for reviewing, and for merging master in.

I want to make sure I'm not talking past you, so I rendered the actual policy document three ways against this branch (attach_ebs_csi_policy = true, terraform plan → terraform show -json → the aws_iam_policy body). The variable's polarity is the opposite of what the name suggests at a glance:

1. master vs this PR at the default (ebs_csi_volume_tagging = false) — byte-identical, zero diff:

$ diff <(jq -S . master-policy.json) <(jq -S . pr-default-false-policy.json)
$ echo $?
0

The dynamic "condition" block uses for_each = var.ebs_csi_volume_tagging ? [] : [1], so at the default it still emits the same ec2:CreateAction condition master emits unconditionally:

{
  "Action": "ec2:CreateTags",
  "Condition": { "StringEquals": { "ec2:CreateAction": ["CreateVolume", "CreateSnapshot"] } },
  "Effect": "Allow",
  "Resource": ["arn:aws:ec2:*:*:volume/*", "arn:aws:ec2:*:*:snapshot/*"]
}

2. master vs this PR with ebs_csi_volume_tagging = true — the condition is what gets removed:

-      "Condition": {
-        "StringEquals": {
-          "ec2:CreateAction": [
-            "CreateVolume",
-            "CreateSnapshot"
-          ]
-        }
-      },

So false is the existing, narrower behavior and true is the opt-in that broadens ec2:CreateTags to already-existing volumes/snapshots (which is what VolumeAttributesClass tag modification needs). Defaulting to true would relax the policy for every current user on upgrade rather than preserve it — I think that's the inverse of what you were guarding against.

That said, your underlying requirement — the default must be the backwards-compatible value, and any change must be opt-in — is exactly right, and it's satisfied today. If the concern is that a false default reads like it's taking something away, I'm happy to flip the variable's sense so the default is literally true:

variable "ebs_csi_restrict_tagging_to_create" {
  description = "Determines whether `ec2:CreateTags` is restricted to resource-creation via the `ec2:CreateAction` condition. Set to `false` to allow the EBS CSI driver to tag existing volumes/snapshots, which `VolumeAttributesClass` tag modifications require"
  type        = bool
  default     = true
}

Same rendered policy at the default, same opt-in semantics, and the default is true for backwards compatibility. Just say which you'd prefer and I'll push it — happy to go either way.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed it to ebs_csi_restrict_tagging_to_create with default = true, so the default renders exactly the same policy as master and nothing changes for existing users. If you need the driver to tag existing volumes (e.g. for VolumeAttributesClass), you opt out by setting it to false. Merged master in too, so it should be ready for another look.

@somaz94

somaz94 commented Aug 20, 2026

Copy link
Copy Markdown
Author

@bryantbiggs following up on the open thread here — I don't want to re-argue it, just to get a decision from you so it can move.

The short version of my Jul 29 reply: the default (ebs_csi_volume_tagging = false) renders byte-identical to master, so the backwards-compatibility requirement you raised is already met — true is the opt-in that broadens ec2:CreateTags, not the other way round.

You may still find that a false default reads like it removes something. If so, I offered to flip the variable's polarity so the default is literally true, which gets the same behavior with the more intuitive spelling. I'm happy either way — I just need to know which you'd prefer before touching it.

Also flagging that this repo's stale bot marks at 30 days of inactivity and closes 10 days later; last activity here was Jul 29, so it's due to be marked shortly. CI is green.

@github-actions

Copy link
Copy Markdown

This PR has been automatically marked as stale because it has been open 30 days
with no activity. Remove stale label or comment or this PR will be closed in 10 days

@github-actions github-actions Bot added the stale label Sep 19, 2026
@somaz94 somaz94 changed the title feat: Add ebs_csi_volume_tagging to allow EBS CSI tag modification on existing volumes feat: Add ebs_csi_restrict_tagging_to_create to allow EBS CSI tag modification on existing volumes Sep 22, 2026
@github-actions github-actions Bot removed the stale label Sep 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

EBS CSI Policy missing permissions for VolumeAttributesClass tagging EBS CSI Policy doesn't works with VolumeAttributesClass tagging

2 participants