In this recipe, we will first enable the IAM Identity Center service (previously AWS SSO) and learn to create users and groups within IAM Identity Center. We will then create a permission set and assign a group to an AWS account along with that permission set. Finally, we will see how to log in to the AWS Management Console and AWS CLI from the AWS access portal using SSO.
SSO is a user authentication process that allows a user to access multiple applications or systems with one set of login credentials. This means that after logging in once, the user can access other AWS accounts and apps without needing to log in again for each system. This simplifies the user experience and enhances security by reducing the number of passwords a user must remember and maintain.
Getting ready
We need an AWS account with AWS organizations enabled. To set up AWS Organizations, we can follow the Multi-account management with AWS Organizations recipe from this chapter.
For working with CLI and IAM Identity Center, we need to install and configure AWS CLI V2 as discussed in the Technical requirements section in this chapter.
How to do it...
First, we will enable the IAM Identity Center. Then, we will create a group and a user and add that user to that group. After that, we will create a permission set and assign access for the group to an AWS account making use of the permission set.
Enabling the IAM Identity Center and creating users and groups
To enable IAM Identity Center and create a group and user, we can proceed with the following steps:
- Log in to AWS Management Console and go to IAM Identity Center.
If we have not enabled IAM Identity Center, we should see a screen like the following:
Figure 1.21 – The IAM Identity Center dashboard
- Click on Enable from the IAM Identity Center Dashboard as shown in Figure 1.21.
We should now be taken to the IAM Identity Center dashboard.
Figure 1.22 – The recommended setup steps for IAM Identity Center
- Click on Choose your identity source under Step 1 as shown in Figure 1.22.
- Leave the value for Identity Source as Identity Center directory.
- For Attributes for access control, click Enable.
- Click on Groups from the left sidebar and click on Create group as shown in the following figure:
Figure 1.23 – The IAM Identity Center sidebar and Groups page
- On the Create group page, within the Group details section, enter
awsseccbadmins
as the Group name and set AWS Sec Cookbook Admins group
under Description.
- Scroll down, leave the Add users to group section as-is without adding any users for now, and click on Create group.
- Click on Users from the left sidebar of IAM Identity Center dashboard and click on Add user.
- In the Primary information section, specify
awsseccbadmin1
under Username and under Password, select Send an email to this user with the password setup instructions. We can also generate a one-time password and share that with the user instead.
Figure 1.24 – The Specify user details page in IAM Identity Center
- Fill in the other fields within the Primary Information section, namely Email address, Confirm email address, First name, Last name, and Display name.
- Leave the other sections, namely Contact methods, Job-related information, Address, Preferences, and Additional attributes as-is. Click Next on the bottom-right side of the page.
- On the Add user to group page, select the
awsseccbadmins
group that we created earlier in this recipe and click Next.
- On the Review and add user page, review the details and click Add user. We should now see that the new user is added to the Users page.
- The newly added user needs to check the email and follow the instructions to accept the invitation and complete the password setup.
Figure 1.25 – The invitation email for the new user in IAM Identity Center
After completing the instructions, we should be logged in to the AWS access portal, where we can see the applications allocated to us. Currently, since we have not allocated any applications, we should see a You do not have any applications message.
Next, we will create a permission set.
Creating a permission set with an AWS managed policy
Follow the instructions to create a permission set that we can use while assigning access to AWS accounts in the next section:
- Click on Permission sets from the left sidebar as shown in Figure 1.23, and on the Permission sets page, click on Create permission set.
- Select Predefined permission set as the Permission set type, and for Select an AWS managed policy, select AdministratorAccess.
Figure 1.26 – Permission set type selection in IAM Identity Center
- Scroll down and click Next.
- On the Specify permission set details page, keep the value of Permission set name as
AdministratorAccess
and Session duration as 1 hour, add a meaningful description, leave values for other fields empty, and click Next.
- On the Review and create page, review everything and click on Create.
The new permission set should now appear on the Permission sets page.
Next, we will assign the awsseccbadmins
group to an AWS account.
Providing access to AWS accounts
We can provide access for a group to one or more AWS accounts as follows:
- Click on the AWS Accounts option from the left sidebar as shown in Figure 1.23 to go to the AWS accounts page.
- Select all the AWS accounts we want to give access to and click on Assign users or groups. I have selected the aws-sec-cookbook-1 account.
Figure 1.27 – The AWS accounts page in IAM Identity Center
- On the Select users and groups page, in the Groups tab, select the
awsseccbadmins
group that we created earlier in this recipe and click Next to go to the Assign permission sets page.
- On the Assign permission sets page, select the permission set for our group to the selected AWS account. Click Next to go to the Review and submit assignments page.
Figure 1.28 – Permission set selection in IAM Identity Center
- On the Review and submit assignments page, review everything and click on Submit.
- Log in to the AWS access portal using the AWS access portal URL of AWS Identity Center. We can get the URL from our Identity Center dashboard. It is also present in the invitation email sent to the user’s email address when the user was created.
You need to click on AWS Account (1) to see the newly assigned AWS account and then click on the account to get the options to log in to Management Console or Command line or programmatic access, making use of short-term credentials.
Figure 1.29 – The AWS access portal
- Click on Management console to log in to the AWS account assigned to us. Click on the drop-down menu next to our username to verify the account details.
We can follow the same steps to give access to one or more AWS accounts for users (instead of groups). However, it is a good practice to assign permissions to groups and add or remove users to those groups as needed.
Configuring SSO for AWS CLI with IAM Identity Center
In the previous section, we saw how to log in to the AWS Management Console using IAM Identity Center from the AWS access portal. In this section, we will learn how to configure AWS CLI V2 with IAM Identity Center:
- Log in to the AWS access portal as an IAM Identity Center user. We should see a screen like Figure 1.29.
- Click on Command line or programmatic access from the AWS access portal instead of the Management Console as we did in Step 7 of the Providing access to AWS accounts sub-section.
We should see a popup that lists different options along with the required steps to work with a CLI.
Figure 1.30 – The steps to work with AWS CLI when using IAM Identity Center
- Assuming that we have already installed AWS CLI V2, open the command prompt (or terminal), run the
aws configure sso
command, and follow the instructions shown in Figure 1.30. Provide SSO start URL and SSO region, and optionally a name for the SSO session, as shown in the following figure:
Figure 1.31 – Configuring SSO with AWS CLI V2
Once we have provided values for SSO session name, SSO start URL, SSO region, and SSO registration scopes, a browser will open for authorization. Please note that I have provided the customized SSO start URL instead of the default one as shown in Figure 1.30; both will work. The command prompt will resume once the authorization is complete.
- Verify by running the
aws s3 ls
command along with the profile name, as shown in Figure 1.31.
We only need to configure SSO once for a combination of AWS accounts and roles as explained in the How it works… section that follows. Once configured, we can make use of that profile to log in and log out using the aws sso login
and aws sso logout
commands respectively, as we will see next.
Logging in and out for SSO with IAM Identity Center in AWS CLI
We can log in to and out of the AWS account using a configured AWS CLI V2 profile as follows:
- Log in using the
aws sso login
command, providing the CLI profile name we already configured (as we saw in Figure 1.31). Execute the aws s3 ls
command, providing the same profile name, as follows:
Figure 1.32 – Logging into an AWS account from CLI using SSO
The aws sso login
command will open a browser for authorization similar to the aws configure sso
command. The command prompt will resume once the authorization is complete.
Important note
If we have multiple profiles or if we are not using the default profile, we will need to specify the profile when executing AWS CLI commands even after the SSO login. Also, if we try to use a profile for which we don’t have access, we will get an error that says that an error occurred (ForbiddenException
) when calling the GetRoleCredentials
operation: No access
.
- Log out using the
aws sso logout
command and execute the aws s3 ls
command, providing the same profile name as before.
Figure 1.33 – Logging out from the AWS account from CLI using SSO
How it works...
AWS IAM Identity Center is the successor to AWS SSO and helps us securely manage access centrally across multiple AWS accounts and applications. The IAM Identity Center is the suggested method for handling authentication and authorization on AWS. It is suitable for organizations big and small.
From the AWS IAM Identity Center dashboard, we can configure access to AWS accounts within an AWS Organization, numerous cloud applications such as Microsoft 365, salesforce, and so on, EC2 Windows instances, and even other SAML 2.0-enabled applications. Once configured, we only need to log in to the AWS access portal and then we can log in to all the configured AWS accounts and applications through SSO without providing any other additional credentials.
An Identity Provider (IdP) is a service that stores and verifies user identity. We can make use of an IdP to log in to multiple applications without providing additional credentials using SSO. We used the built-in IdP of the IAM Identity Center within our recipe. However, instead of the built-in IdP, we can also use one of the many supported IdPs such as Microsoft Entra ID (previously Active Directory or Azure AD), Okta, Ping Identity, Jump Cloud, and Google Workspace.
Within this recipe, while enabling IAM Identity Center, we also enabled attributes for access control. We can assign users to workloads in AWS based on existing attributes in the user’s identity source to control access to resources, and thus implement Attribute-Based Access Control (ABAC). ABAC is a method of regulating access based on attributes (characteristics or properties) associated with users, resources, or the environment. Unlike Role-Based Access Control (RBAC), which grants access based on the roles of users within an organization, ABAC uses a wide range of attributes, such as user location, time of access, and even sensitivity of the accessed resource. This allows for more flexible, context-aware, and policy-driven access control, enabling more granular and dynamic permission management.
We can assign varying permission levels to users or groups for different AWS accounts and applications using permission sets. For example, we can give developers complete access to developer accounts and read-only access to production accounts. We can select the predefined permission set option as we did in this recipe selecting one of the available AWS-managed policies or we can create a custom permission set.
The following screenshot from the IAM Identity Center lists down policies available currently when we select the predefined permission set option.
Figure 1.34 – Policies for the predefined permission set
With the custom permission set option, we can choose from an AWS-managed policy, a customer-managed policy, and an inline policy, and even optionally set a permissions boundary. We will see a custom permission set in the Creating customer-managed policies in IAM Identity Center recipe in Chapter 2.
In the recipe, our user had one permission set assigned to one AWS account. If we have users with multiple permission sets and access to multiple AWS accounts, we can choose the AWS account and the permission set to log in from the AWS access portal, as shown in the following figure:
Figure 1.35 – The AWS access portal with multiple AWS accounts and permissions
Even when configuring AWS SSO for CLI, we will be given options to select the AWS account and permission set. First, we will be asked to select the AWS account as follows:
Figure 1.36 – AWS CLI account selection
After we select the account, we will be given the option to choose the role (which is based on the permission set) if we have multiple roles available to choose from in the selected AWS account.
Figure 1.37 – AWS CLI role selection
There’s more...
We can administer IAM Identity Center from only the management account of the Organization or a member account registered as an IAM Identity Center delegated administrator. Otherwise, we will see an error message that looks like the following:
Figure 1.38 – An error message for a member account that is not a delegated administrator
We can make a member account as a delegated administrator as follows:
- Log in to the AWS Management Console of the management account of our organization and go to the IAM Identity Center dashboard.
- Click on Settings from the left sidebar of IAM Identity Center.
- Go to the Management tab.
- Find the Delegated administrator section and click on Register account. This will show us the organizational structure of our AWS Organization.
- Under the Organizational structure section, select the member account we want to make a delegated administrator and click on Register account.
We should see a message that the member account was registered successfully as an IAM Identity Center delegated administrator. It might take some time to grant administrative access to the member account.
We can customize the default AWS access portal URL (e.g., https://d-90679fa661.awsapps.com/start/) to one that uses a custom subdomain (e.g., https://awsseccb.awsapps.com/start) to make it more memorable for our users. For customizing the URL, we can click on the Customize button from the Settings summary section on the right side of the IAM Identity Center dashboard, as shown in Figure 1.22, and configure a custom subdomain. Once it has been customized, we won’t be able to change it again.
See also