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

(aws-iam): (stack tags are not set for awsiam.CfnManagedPolicy) #30982

Open
kylos101 opened this issue Jul 30, 2024 · 6 comments
Open

(aws-iam): (stack tags are not set for awsiam.CfnManagedPolicy) #30982

kylos101 opened this issue Jul 30, 2024 · 6 comments
Labels
@aws-cdk/aws-iam Related to AWS Identity and Access Management bug This issue is a bug. effort/medium Medium work item – several days of effort needs-cfn This issue is waiting on changes to CloudFormation before it can be addressed. p2

Comments

@kylos101
Copy link

Describe the bug

Stack tags are not added to IAM policies, they are added to roles.

I add them to my stack like so:

for tag, value := range cfg.Tags {
  awscdk.Tags_Of(stack).Add(jsii.String(tag), jsii.String(value), &awscdk.TagProps{
	  ApplyToLaunchedInstances: jsii.Bool(true),
  })
}

As a workaround, I tried explicitly adding them to policies like so, but, to no avail:

for _, policy := range policies {
  for tag, value := range cfg.Tags {
	  awscdk.Tags_Of(policy).Add(jsii.String(tag), jsii.String(value), &awscdk.TagProps{
		  ApplyToLaunchedInstances: jsii.Bool(true),
	  })
  }
}

It seems like it may potentially be a gap or limit, I do not see tags available here (although Tags can be set in the AWS console for Policies).

Expected Behavior

Stack tags are applied to managed policies

Current Behavior

Stack tags are not applied to managed policies

Reproduction Steps

See above sample code

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.147.3 (build 32f0fdb)

Framework Version

No response

Node.js Version

v20.8.0

OS

Ubuntu 22.04.4 LTS

Language

Go

Language Version

1.22

Other information

I'm using these lib versions:

github.com/aws/aws-cdk-go/awscdk/v2 v2.129.0
github.com/aws/aws-sdk-go v1.48.1
github.com/aws/aws-sdk-go-v2 v1.23.1
@kylos101 kylos101 added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jul 30, 2024
@github-actions github-actions bot added the @aws-cdk/aws-iam Related to AWS Identity and Access Management label Jul 30, 2024
@ashishdhingra ashishdhingra self-assigned this Jul 30, 2024
@ashishdhingra
Copy link
Contributor

ashishdhingra commented Jul 30, 2024

@kylos101 Good afternoon. Per CloudFormation guide, AWS::IAM::Policy and AWS::IAM::ManagedPolicy resources do not support Tags property (as opposed to AWS::IAM::Role). I'm unable to see any UI in AWS Console which allows to associate tags with an IAM Policy. Could you please point to documentation/resource which specifies associating tags with an IAM Managed Policy?

Thanks,
Ashish

@ashishdhingra ashishdhingra added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed needs-triage This issue or PR still needs to be triaged. labels Jul 30, 2024
@kylos101
Copy link
Author

Hi @ashishdhingra , thank you so much for the prompt reply!

In the AWS Console, I see a field for tags like so:
image

This is infact the policy we created with CloudFormation and CfnManagedPolicy.

And I can add tags here:
image

@ashishdhingra
Copy link
Contributor

This appears to be limitation of CloudFormation. The IAM policy schema at https://github.com/cdklabs/awscdk-service-spec/tree/main/sources/CloudFormationSchema/us-east-1 also doesn't appear to support Tags property and has taggable flag(s) set to false.

I would open ticket with CloudFormation team for their inputs.

@ashishdhingra ashishdhingra added needs-cfn This issue is waiting on changes to CloudFormation before it can be addressed. effort/small Small work item – less than a day of effort labels Jul 30, 2024
@ashishdhingra
Copy link
Contributor

Internal ticket created for CloudFormation team: P145169283

@ashishdhingra ashishdhingra added effort/medium Medium work item – several days of effort and removed effort/small Small work item – less than a day of effort labels Jul 30, 2024
@ashishdhingra ashishdhingra removed their assignment Jul 30, 2024
@ashishdhingra ashishdhingra removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Jul 30, 2024
@ashishdhingra
Copy link
Contributor

ashishdhingra commented Jul 30, 2024

@kylos101 Got an update from CloudFormation team:

This is a known limitation of the AWS::IAM::ManagedPolicy resource (The AWS::IAM::Policy resource creates an inline policy for a IAM role/user and is not able to be tagged). There is an ongoing GitHub issue to bring tagging support to this resource to CloudFormation. CDK functionality is limited to what CloudFormation may do, so there is no native CDK solution to work around this issue.

You may potentially use the AwsCustomResource construct to run the TagPolicy API on your IAM policy to work around this.

We could keep this issue open until CloudFormation support is added, after which it would be automatically pushed to CDK L1 construct.

@robertd
Copy link
Contributor

robertd commented Oct 4, 2024

You may potentially use the AwsCustomResource construct to run the TagPolicy API on your IAM policy to work around this.

Ah... I love the "just monkey-patch it" response from the CFN team 🤣

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-iam Related to AWS Identity and Access Management bug This issue is a bug. effort/medium Medium work item – several days of effort needs-cfn This issue is waiting on changes to CloudFormation before it can be addressed. p2
Projects
None yet
Development

No branches or pull requests

3 participants