Skip to content

Use session tags to propagate tags for resources

0

Hi there.

I'm trying to use AWS IAM Session Tags for a specific purpose. We already created an ECS Cluster and usually ECS Tasks are created for an internal purpose in our company. ECS Tasks are created by an application running in a EC2 Instance. In short, we want that ECS Tasks can be created with tags pre-defined on Assumed Role without specifying these tags again at ECS create tasks action, is that possible? Let me explain a little bit about how our infrastructure is configured.

EC2 Instance responsible by create ECS tasks has associated an IAM Role with permissions to assume a second IAM Role and pass session tags to it. The second IAM Role has only ECS Full Access AWS managed policy attached to it. After EC2 Instance assume the second IAM Role, the ECS Tasks should be created.

For knowledge, assume role with session tags and ECS create tasks actions are working correctly, but the tasks aren't being created with the tags in the session. I really would like to know if it's possible to makes ECS Tasks, or any other resources created using an IAM Role with session tags, inherit tags defined in session.

1 Answer
1
Accepted Answer

Session tags are key-value pair attributes that you can pass when assuming a role, but they don't automatically propagate to resources created using those temporary credentials. Session tags are primarily designed for access control purposes rather than resource tagging.

When you assume a role with session tags, those tags are valid only for the duration of the session and are used primarily for:

  1. Controlling access to resources based on the tags (Attribute-Based Access Control)
  2. Passing the tags to subsequent role assumption operations (when marked as transitive)

For your ECS tasks scenario, session tags won't automatically be applied to the ECS tasks you create. The session tags exist at the authentication/authorization level, not at the resource creation level.

If you want to automatically tag ECS tasks, you would need to:

  1. Explicitly include the tags in your ECS task creation API calls, or
  2. Use a different mechanism like tag policies or resource-specific tagging features

For Amazon EC2 instances that run as ECS container instances, there are specific methods to propagate tags from EC2 to ECS using the container agent configuration parameter ECS_CONTAINER_INSTANCE_PROPAGATE_TAGS_FROM, but this is specific to container instances and not applicable to ECS tasks created by an application.

In summary, while session tags are powerful for access control and can be passed transitively across role assumptions, they don't automatically propagate to resources created during the session.
Sources
Pass session tags in AWS STS - AWS Identity and Access Management
Adding tags to an Amazon ECS container instance - Amazon Elastic Container Service
Grant Pods access to AWS resources based on tags - Amazon EKS
Controlling access to and for IAM users and roles using tags - AWS Identity and Access Management
Tag - AWS Security Token Service

answered a year ago

AWS
SUPPORT ENGINEER

reviewed a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.