Configure AWS SSO ABAC for EC2 Techniques and instances Manager Program Manager
In this blog post, You are showed by me how to configure AWS Single Sign-On to define attribute-based access control (ABAC) permissions to manage Amazon Elastic Compute Cloud (Amazon EC2) instances and AWS Systems Manager Session Manager for federated users. This combination allows you to control access to specific Amazon EC2 instances based on users’ attributes. I show you how defined AWS SSO identity source attributes like department and login can be used, and how custom attributes like SSMSessionRunAs can be used to pass these attributes into Amazon Web Services (AWS) from an external identity provider (IdP) using SAML 2.0 assertion.
AWS SSO added support for ABAC to enable you to create fine-grained permissions for your workforce in AWS using user attributes. Using user attributes as tags in AWS helps you simplify the process of creating fine-grained permissions in AWS and enables you to ensure that your workforce has access only to the AWS resources with matching tags.
The new feature works with any supported AWS SSO identity source. You are walked by this post through the steps to enable attributes for access control, create permission sets and manage assignments when using a supported external IdP as your identity source.
Solution overview
The following architecture diagram—Figure 1—presents an overview of the solution.
In the example in Figure 1, Bob and alice are users who each have the attributes
login, department, and SSMSessionRunAs. These attributes are created and updated in the external directory—Okta in this example—under those users’ profiles. The first two attributes are synchronized by using& automatically;nbsp;System for Cross-domain Identity Management (SCIM) protocol between AWS Okta and SSO and configured within AWS SSO settings. The third custom attribute is passed directly from Okta into the AWS accounts as a new SAML assertion.
Both users are using the same AWS SSO custom permission set that allows them to launch a new Amazon EC2 instance with proper tags enforcement. Based on those tags, they can start, stop, and restart the EC2 instance if they are in the same department, and to terminate it if they are the owner. Also, they can connect using Session Manager if they’re in the same department. Users can sign in to those instances using the Linux OS user defined in the attribute SSMSessionRunAs.
Prerequisites
To perform the steps to use AWS SSO attributes for ABAC, you must have deployed AWS SSO for your < already;a href=”https://aws.amazon.com/organizations/” target=”_blank” rel=”noopener noreferrer”>AWS Organizations and have connected with an external identity source using SCIM and SAML protocols. For more information, see Checklist: Configuring ABAC in AWS using AWS SSO.
You need two test users for testing and implementing the solution. You can use two existing users, or create new users named Bob and Alice to match the solution and testing described in the following sections.
Implement the solution
The basic steps to implement the solution are:
-
- Confirm in AWS SSO settings that you have defined an external IdP, authentication via SAML 2.0, and provisioning via SCIM protocol.
-
- Enable attributes for access control and define the two supported attributes: login and department.
-
- Create a new user attribute in the Okta Directory.
-
- Edit and confirm the users’ attributes defined in the Okta Directory profile.
-
- Configure the SAML attribute statement in the Okta AWS SSO application.
-
- Create a new permission set using an ABAC policy.
-
- Create an AWS account assignment to the users using the permission set created in the previous step.
Confirm AWS SSO configuration
In this first step, you confirm that AWS SSO has been configured properly. Go to AWS SSO console SSO settings to check that the configuration of your identity source, authentication, and provisioning is as follows:
Identity source: External Identity Provider
Authentication: SAML 2.0
Provisioning: SCIM
-
- Confirm authentication is working as expected, by going to your user portal URL in a new browser instance (to ensure your user authentication doesn’t overwrite your existing authentication). The user portal offers a single place to access all the assigned AWS accounts, roles, and applications. For example, it should look like https://exampledomain.awsapps.com/start. You access it once, the process redirects the request to your external provider for authentication automatically, and returns the user to the < then;a href=”https://docs.aws.amazon.com/singlesignon/latest/userguide/using-the-portal.html” target=”_blank” rel=”noopener noreferrer”>AWS SSO user portal.
-
- To confirm provisioning, go to the AWS SSO console and choose Users from the right panel. You should see your Okta users assigned to the AWS SSO application being synchronized by SCIM protocol. Select any user to see the Created by SCIM and Updated by SCIM information for that user.
Enable AWS SSO attributes for access control
In this step, you enable ABAC and configure AWS SSO attributes then. The < is used by this solution;strong>Attributes for access control page in the AWS Management Console to enter the value and key pairs.
To enable attributes for access control
-
- Open the AWS SSO console.
-
- Choose Settings.
-
- On the Settings page, under Identity source, next to Attributes for access control, select Enable. As shown in Figure 2.
ABAC is enabled once, you can select the attributes to be synchronized. For this use case, select login and department.
To select your attributes using the AWS SSO console
-
- Open the AWS SSO console.
-
- Choose Settings.
-
- On the Settings page, under Identity source, next to Attributes for access control, choose View details.
-
- On the Attributes for access control page, notice the Key and Value columns. This is where you will be mapping the attribute from your identity source to an attribute that AWS SSO passes as a session tag. Set the first value and key pair by entering login as the key and $path:userName as the value. Set the second value and key pair to department and $path:enterprise.department. The settings are shown in Figure 3 below.
-
- Choose Save changes.
Create a new attribute in Okta Directory
In this third step, you create the new custom attribute SSMSessionRunAs.
To create a new user attribute
-
- Open the Okta console.
-
- Under Directory, choose Profile Editor.
-
- Choose Edit Profile for Okta User (default).
-
- Under Attributes, choose Add Attribute as follows:
Data type: Select String
Display Name: Enter SSMSessionRunAs
Variable Name: Enter SSMSessionRunAs
Attribute Length: Select Less than and enter 10 (max).
- Under Attributes, choose Add Attribute as follows:
-
- Choose Save.
Edit and confirm users’ attributes defined in Okta Directory profile
That you have the new attribute < now;span>SSMSessionRunAs created, go to the users’ profiles to enter the Department and SSMSessionRunAs values for both users.
To edit and confirm users’ attributes
-
- Open the Okta console.
-
- Under Directory, choose People.
-
- Select user Bob.
-
- Under Profile tab choose Edit as follows:For the key Department, enter blue as the value.For the key SSMSessionRunAs, enter bob as the value.
-
- Choose Save.
-
- Repeat steps 1 through 5 for Alice. For the key Department, enter amber as the value and for SSMSessionRunAs, enter alice as the value.
-
- Confirm that the attributes of both users are defined in the external directory as follows:Username (login): bob@example.com
First name (firstName): Bob
Last name (lastName): Rodriguez
Display name (displayName): Bob
Department (department): blue
SSMSessionRunAs (SSMSessionRunAs): bobUsername (login): alice@example.com
First name (firstName): Alice
Last name (lastName): Rosalez
Display name (displayName): Alice
Department (department): amber
SSMSessionRunAs (SSMSessionRunAs): alice
- Confirm that the attributes of both users are defined in the external directory as follows:Username (login): bob@example.com
Configure SAML attribute statement in Okta AWS SSO application
The attribute SSMSessionRunAs isn’t available as an attribute within AWS SSO. However, it can be included by you by defining SAML attribute statements, which are inserted into the SAML assertions.
To create a new SAML attribute
-
- Open the Okta Application console.
-
- Choose AWS Single Sign-on application.
-
- On the Sign On tab, choose Edit Settings.
-
- Under SAML 2.0 Attributes Statements enter the following:
-
- For Name, enter https://aws.amazon.com/SAML/Attributes/AccessControl:SSMSessionRunAs
-
- For Name format, select URI Reference
-
- For Value, enter user.SSMSessionRunAs
-
- Under SAML 2.0 Attributes Statements enter the following:
-
- Choose Save.
Create a new permission set using an ABAC policy
In this step, you create a permissions policy that determines who can access your AWS resources based on the configured attribute value. When you enable ABAC and specify attributes, AWS SSO passes the attribute value of the authenticated user into AWS Identity and Access Management (IAM) for use in policy evaluation.
To create a permission set
-
- Open the AWS SSO console.
-
- Choose AWS accounts.
-
- Select the Permission sets tab.
-
- Choose Create permission set.
- On the Create new permission set page, choose Create a custom permission set.
-
- Choose Next: Details.
-
- Under Create a custom permission set, enter a true name that will identify this permission set in AWS SSO. This name will also appear as an IAM role in the user portal for any users who have access to it. For this solution, name it myCustomPermissionSetEC2SSM.
- Choose Create a custom permissions policy and paste in the following ABAC policy document:
- Choose Next: Tags.
- Review the selections you made, and choose& then;nbsp;Create.
-
Test EC2 operations
-
- Open the Amazon EC2 console:
For this example, when opening the Amazon EC2 console there are already three running EC2 instances to test the ABAC policy that have been created with proper tags explained in the following step. From the top menu, you can also confirm the federated login AWSReservedSSO_myCustomPermissionSetEC2SSM_9e80ec498218bbea/bob@example.com that represents the AWS SSO managed role and the user as shown in Figure 8.
- Open the Amazon EC2 console:
- Launch a new EC2 instance:
Start testing the ABAC policy by launching a new EC2 instance. This action is authorized only when you fill in the three required tags: Name, Owner, and Department.-
- From the Amazon EC2 console, choose Launch Instances .
-
- Set the AMI , for this example select an Ubuntu-based OS.
-
- Set the Instance Type , a t2.micro will work.
-
- Configure the EC2 instance. Choose an IAM role to allow Systems Manager to manage the new EC2 instance. In this case, you have to create the IAM role EC2UbuntuSSMRole with the AWS managed policy AmazonEC2RoleforSSM attached in advanced with proper IAM permissions since the user Bob is not allow to do so. Then, you must use the user data to create the OS Ubuntu user—Bob—that you need to log in to the EC2 instance by using Session Manager. You can copy and paste the following to create the user “Bob”: #!/bin/bash
sudo useradd -m bob
- Configure the EC2 instance. Choose an IAM role to allow Systems Manager to manage the new EC2 instance. In this case, you have to create the IAM role EC2UbuntuSSMRole with the AWS managed policy AmazonEC2RoleforSSM attached in advanced with proper IAM permissions since the user Bob is not allow to do so. Then, you must use the user data to create the OS Ubuntu user—Bob—that you need to log in to the EC2 instance by using Session Manager. You can copy and paste the following to create the user “Bob”: #!/bin/bash
-
- Add storage using the default settings.
- Add tags. From the ABAC policy created, you can confirm that tag key Name can be anything as the condition StringLike is indicated with a wildcard (
-
). The tag keys Owner and Department have to match the principal session tags passed through federation. In this case, enter bob@example.com as the key Owner , and blue as the Department enter, as shown in Figure 9.
-
- Configure security groups. When configuring security groups, you can choose an existing security group that doesn’t allow any inbound traffic to the SSH port. Since when using Session Manager you connect to the EC2 instance through an API that is going to be an outbound connection. This way you can safely leave close the security group inbound rules.
- launch and
- Review. It shall ask you about selecting or creating a key pair. You don’t need one, because you’re using Session Manager. Proceed without creating or selecting a new SSH key pair. When launching the EC2 instance with the correct tag values and keys, the success is got by you message shown in Figure 10.
If there are any missing tag keys or the values aren’t correct, the action shall be denied as shown in Figure 11. For more information, you can decode the authorization error message using the API DecodeAuthorizationMessage .
-
- Stop, reboot, and terminate EC2 instances.
The next tests are to be stop, reboot, and terminate the EC2 instances. In the ABAC policy you defined that only users who have the same department value as the resource can perform the first two actions. You can terminate and EC2 instance only if you are an owner. To stop, reboot, and terminate instances, open the EC2 Console, choose Instances, and select the instance you want to affect. Choose Instance state and choose the action you want to test: Stop instance, Reboot instance or Terminate instance.Trying to stop the EC2 instance amber-instance where Department is amber is shown in Figure 12.The action should fail as shown in Figure 13.
Only when the department value of the EC2 instance is blue is it possible to stop or reboot the instance as shown in Figure 14.
Only when the owner who launched the EC2 instance matches with the federated login is it possible to terminate the instance. Trying to terminate an EC2 instance that was launched by anyone other than the owner will lead to a failed action as shown in Figure 15.
-
- Try to modify tags. Because ABAC policies rely on tags, you cannot modify tags after the resources have been created. This is set in the ABAC policy statement AllowCreateTagsOnRunInstance in Create a new permission set using an ABAC policy. If you try to modify any tag values or keys on existing resources, the noticeable changes will be denied. For example, if you try to modify the owner of a tag on an existing EC2 instance, you get the “Failed to update tags” error message as shown in Figure 16.
-
- Connect to the EC2 instance using Session Manager.
-
- Test logging in to the EC2 instance by choosing the new instance and choosing Connect as shown in Figure 17.
-
- Choose the < then;strong>Session Manager tab and choose Connect as shown in Figure 18.
This will open a new tab in the browser redirecting to a Systems Manager session where you can confirm that the Ubuntu OS user is Bob as shown in Figure 19.
Note: By default, sessions are launched using the credentials of a system-generated account named ssm-user that is created on a managed instance. However, you can launch sessions using any OS user by enabling the < instead;em>run as feature in SSM. To learn more about this, see Enable run as support for macOS and Linux instances in the Systems Manager Session Manager user guide.
- Choose the < then;strong>Session Manager tab and choose Connect as shown in Figure 18.
-
- Performing the same action in an EC2 instance with a different Department tag will lead to a denied action as shown in Figure 20. This is because the < is allowed by the ABAC policy;span>StartSession action only when the Department key matches the Department value in the EC2 instance.
-
-
Conclusion
In this blog post, you learned how to use AWS SSO with the two methods of passing attributes to AWS account using session tags for ABAC. You also learned how to build policies with tags as conditions to simplify and reuse custom permission sets. You have seen working examples with services like EC2, and Systems Manager Session Manager. To learn more about ABAC policies, SAML session tags, and how to pass session tags in federation, see IAM tutorial: Use SAML session tags for ABAC and Passing session tags using AssumeRoleWithSAML.
If you have feedback about this post, submit comments in the Comments section below.
Want more AWS Security news? Follow us on Twitter.
-
You must be logged in to post a comment.