fbpx

Control the naming of individual IAM function sessions easily

AWS Identity and Access Management (IAM) now includes a brand new sts:RoleSessionName condition element for the AWS Security Token Services (AWS STS), that means it is easy for AWS accounts administrators to regulate the naming of person IAM role sessions. IAM roles assist you to grant usage of AWS resources and solutions through the use of dynamically generated short-expression credentials. Each instantiation of an IAM part, and the associated group of short-term credentials, is called an IAM role program. Each IAM role session is identified by way of a role session title uniquely. You can now utilize the new condition to regulate how IAM principals and apps name their role periods when they presume an IAM role, and depend on the role session title to monitor their actions when seeing AWS CloudTrail logs easily.

How can you name a job session?

There are various ways to name a job session, and it depends upon the technique used to assume the IAM role. In some full cases, AWS units the role session in your stead. For instance, for Amazon Elastic Compute Cloud (Amazon EC2) example profiles, AWS models the role session title to the instance user profile ID. By using the AssumeRolewithSAML API to assume an IAM function, AWS sets the part session name worth to the attribute supplied by the identity service provider, which your administrator described. In other cases, the role is supplied by you session title when assuming the IAM role. For instance, when assuming an IAM function with APIs such as for example AssumeRole or AssumeRoleWithWebIdentity, the role session name is really a required input that you set when coming up with the API request parameter.

What is really a condition element?

A condition can be an optional IAM policy element. You may use a disorder to specify the situations under that your IAM plan grants or denies permissions. A disorder is included by way of a condition key, operator, and worth for the condition.

There are two forms of conditions: service-specific conditions and global conditions. Service-specific conditions are particular to certain actions within an AWS service. For instance, specific EC2 actions assistance the ec2:InstanceType problem. All AWS service activities support global conditions.

That I&rsquo now;ve explained this is of a job session name and this is of a condition aspect in an IAM plan, let me introduce the brand new condition, sts:RoleSessionName.

sts:RoleSessionName condition

The sts:RoleSessionName is really a service-specific condition that you utilize with the AssumeRole API action, within an IAM policy to regulate what is set because the role session name. You may use any string operator, such as for example StringLike, when using this problem.

Condition CrucialDescriptionOperator(s)Valuests:RoleSessionNameUniquely identifies a program when IAM principals, federated identities, and programs assume exactly the same IAM role.All string operatorsString of upper-situation and lower-case alphanumeric character types with no spaces. It could include underscores or the following characters: =,.@-IAM policy element variables could be set as ideals.

In this post, I’ll walk you through two types of how to utilize the sts:RoleSessionName condition. In the initial example, become familiar with how exactly to require IAM customers to create their aws:username as their role program name when they believe an IAM part in your AWS accounts. In the next example, become familiar with how to need IAM principals to select from a pre-selected group of role session titles when they presume an IAM function in your AWS accounts.

The examples shared in this article describe a scenario where you have pricing information that is stored within an Amazon DynamoDB data source in your AWS account, and you also desire to share the pricing information with members from your own marketing department, that are in another AWS account. Furthermore, you want to make use of your AWS CloudTrail logs to monitor the activities of users from the marketing section every time they access the prices data. This write-up will highlight how to accomplish that by doing the next:

  1. Dedicate an IAM part in your AWS take into account the advertising department.
  2. Define the role trust policy for the IAM function, to specify who is able to assume the IAM part.
  3. Use the brand new sts:RoleSessionName situation in the function trust plan to define the permitted role session name ideals for the devoted IAM role.

When people from the marketing division try to assume the IAM part in your AWS accounts, AWS may verify that their function session name will not conflict with the IAM part trust plan, before authorizing the assume-role action. The brand new sts:RoleSessionName condition offers you manage of the role program name. With this particular control, when you look at the AWS CloudTrail logs, now you can depend on the role program name for just about any of the next information:

  • To determine the IAM app or principal that assumed an IAM role.
  • The justification why the IAM principal or application assumed an IAM role.
  • To track what carried out by the IAM software or even principal with the assumed IAM role.

Instance 1 – Require IAM users to create their aws:username as their role program name when they believe an IAM function in your AWS accounts

When an IAM consumer assumes an IAM part within your AWS account, it is possible to require them to create their aws:username as the function session name. With this particular requirement, you can depend on the role program name to recognize the IAM consumer who performed an activity with the IAM part.

The scenario is continued by this exemplory case of sharing pricing information with members of the marketing department inside your organization, who are in another AWS account. John is really a known person in the marketing department, he could be an IAM consumer in the advertising AWS accounts and his aws:username is john_s. For John to gain access to the pricing information in your AWS accounts, you develop a dedicated IAM function for the marketing section first, called marketing. John shall assume the advertising IAM role to gain access to the pricing information within your AWS account.

Next, you set up a two-way trust between your advertising AWS account as well as your AWS accounts. The administrator of the marketing AWS account will have to grant John sts:AssumeRole permission having an IAM policy, in order that John can presume the marketing IAM part in your AWS accounts. The following is really a sample plan to grant John assume-role permission. Make sure to replace together with your account number.



    "Version": "2012-10-17",
    "Statement": [
        
            "Sid": "AssumeRole",
            "Effect": "Allow",
            "Action": "sts:AssumeRole",
            "Source": "arn:aws:iam:::role/advertising"
        
    ]

You develop a role trust plan for the marketing IAM role then, which permits members of the marketing division to assume the IAM role. The next is really a sample policy to produce a role trust plan for the advertising IAM role. Make sure to replace together with your account number.



      "Version": "2012-10-17",
      "Statement": [
        
          "Effect": "Allow",
          "Principal": 
            "AWS": "arn:aws:iam:::root"
          ,
          "Action": "sts:AssumeRole",
          "Condition": 
            "StringLike": 
              "sts:RoleSessionName": "$aws:username"
            
          
        
      ]
    

In the function trust policy above, you utilize the sts:RoleSessionName condition to make sure that members of the advertising department set their aws:username as their role program name if they assume the advertising IAM part. If John tries to assume the marketing IAM function and will not set his part session name to john_s, aWS won’t authorize the ask for then. When John pieces the role session title to his aws:username, AWS shall permit him to assume the marketing IAM role. The following is really a sample CLI control to believe an IAM function. Replace together with your account number.


aws sts assume-part --role-arn arn:aws:iam:::function/marketing --role-session-name john_s

In the AWS CLI command above, John assumes the marketing and advertising IAM part and sets the function session name to john_s. John then calls the get-caller-identity API to verify he assumed the marketing IAM role. The next is confirmation that John assumed the advertising IAM role successfully.



    "UserId": " AIDACKCEVSQ6C2EXAMPLE:john_s",
    "Accounts": "",
    "Arn": "arn:aws:sts:::assumed-role/advertising/john_s"

AWS CloudTrail captures any motion that John performs with the marketing IAM role, and you will identify John&rsquo easily;s sessions within your AWS CloudTrail logs by looking for any Amazon Reference Title (ARN) with John’s aws:username (that is john_s) because the role session title. The next is an exemplory case of AWS CloudTrail occasion details that presents the role session title. Replace together with your account number.



"assumedRoleUser": 
            "assumedRoleId": "AIDACKCEVSQ6C2EXAMPLE:john_s",
            "arn": "arn:aws:sts:::assumed-role/advertising/john_s"
        

Illustration 2 – Require IAM principals to pick from a pre-selected group of role session brands when they presume an IAM part in your AWS accounts

You can even define the acceptable role session names an IAM principal or even application can use if they assume an IAM role in your AWS account. With this particular requirement, you make sure that IAM principals and apps that assume IAM functions in your AWS accounts work with a pre-approved role program name that you could easily understand.

Expanding on the prior example, in the next scenario, you’ve got a new AWS accounts having an Amazon DynamoDB data source that stores competitive evaluation data. You don’t want associates of the marketing section to possess direct access to the new AWS account. You’ll achieve this by requesting your advertising partners to very first assume the advertising IAM function in your various other AWS account with prices info, and from that AWS accounts, assume the Analyst IAM part in the brand new AWS account to gain access to the competitive analysis information. Also, you need your marketing companions to pick from a pre-defined group of role session titles: “marketing-marketing campaign”, “product-growth” and “some other”, that will identify their reason behind accessing the competitive evaluation data.

First, you set up a two-way rely on. You grant the marketing IAM function sts:AssumeRole permission having an IAM policy. The next is a sample plan to grant the marketing IAM part assume-role permission. Make sure to replace together with your account number.



    "Version": "2012-10-17",
    "Statement": [
        
            "Sid": "AssumeRole",
            "Effect": "Allow",
            "Action": "sts:AssumeRole",
            "Useful resource": "arn:aws:iam:::function/Analyst"
        
    ]

Next, a role is established by you trust policy for the Analyst IAM role. In the role believe in plan, you set the marketing IAM part as the Principal, to restrict who is able to access the Analyst IAM function. Then you utilize the sts:RoleSessionName problem to define the appropriate role session names: marketing-campaign, other and product-development. The following is really a role trust plan to limit the set of acceptable role program names. Replace together with your account number.


        
      "Version": "2012-10-17",
      "Statement": [
        
          "Effect": "Allow",
          "Principal": 
             "AWS": " arn:aws:iam:::part/marketing"          
             ,
          "Action": "sts:AssumeRole",
          "Condition": 
            "StringLike": 
              "sts:RoleSessionName": [
                "marketing-campaign",
                "product-development",
                "other"
              ]
            
          
        
      ]
    

If John from the marketing and advertising department wants to accessibility the competitive analysis information, and he’s got assumed the advertising IAM function as shown in illustration #1, he then can assume the Analyst IAM part in the brand new AWS account utilizing the marketing IAM function. For to authorize the assume-role request AWS, when he assumes the Analyst IAM role, the role should be set by him session name to 1 of the pre-defined values. The following is really a sample CLI order to assume the Analyst IAM part. Replace together with your account number.


aws sts assume-function --role-arn arn:aws:iam:::part/Analyst --role-session-name marketing-campaign

In the CLI command above, John assumes the Analyst IAM role, utilizing the advertising IAM role. He sets the role program name to marketing-campaign also, that is an allowed function session name. John after that calls the get-caller-identity API to verify he effectively assumed the Analyst IAM part. The following log outcomes show the advertising IAM role effectively assumed the Analyst IAM function with the role program name as marketing-campaign.



    "UserId": " AIDACKCEVSQ6C2EXAMPLE:marketing-campaign",
    "Accounts": "",
    "Arn": "arn:aws:sts:::assumed-role/Analyst/marketing-campaign"

AWS CloudTrail captures any actions performed with the Analyst IAM part. By viewing the function session brands in your AWS CloudTrail logs, it is simple to identify the good explanations why your marketing companions accessed the competitive evaluation data.


"assumedRoleUser": 
            "assumedRoleId": "AIDACKCEVSQ6C2EXAMPLE:marketing-campaign",
            "arn": "arn:aws:sts:::assumed-role/Analyst/marketing-campaign"
        

Conclusion

In this article, I demonstrated how AWS account administrators may use the sts:RoleSessionName condition to regulate what IAM principal names their program if they assume an IAM part. You are distributed by this manage increased confidence to depend on the role program name, when looking at AWS CloudTrail logs, to recognize who performed an activity with an IAM function, or get extra context for just why an IAM principal assumed an IAM part.

For more information concerning the sts:RoleSessionName condition, and for plan examples, see Available Keys for AWS STS within the AWS IAM User Guideline.

When you have feedback concerning this post, submit remarks in the Comments section below. Should you have questions concerning this post, start a brand new thread on the Amazon Identity and Access Management forum.

Want a lot more AWS Security how-to articles, news, and show announcements? Stick to us on Twitter.

Writer

Derrick Oigiagbe

Derrick is really a Senior Product Supervisor for Access and Identification Management service from AWS. To his profession at Amazon prior, he obtained his MBA from the Carnegie Mellon’s Tepper College of Company. Derrick spent his earlier career as a technologies consultant for Summa Technology (recently obtained by CGI). In his free time, Derrick enjoys actively playing travelling and soccer.