Using IAM Identity Center and MFA Enforcement for AWS User Management
Introduction
This guide covers IAM Identity Center (formerly SSO) and MFA Enforcement (requiring two-factor authentication).
IAM Identity Center (SSO) is a centralized access management service. It lets you manage user identities and permissions across all your AWS accounts and business apps in one place. When combined with MFA Enforcement, you create a high-security barrier while keeping the login experience smooth for your team.
Key Benefits
- Single Sign-On (SSO) Experience: Employees only need to remember one password to access all AWS resources via a custom portal.
- Maximum Security with MFA: Even if a password is leaked, attackers can't get in without the physical device or MFA app.
- Reduced Operational Risk: No more managing long-term Access Keys (which are easily leaked). These are replaced by short-lived, auto-expiring temporary tokens.
The Workflow
- Create a Resource Stack: Define permissions and groups, then assign permissions to those groups.
- Create Users: Use IAM Identity Center to add users; they will receive an invitation via email.
- User Setup: The user sets up their MFA and logs in via SSO to use their assigned permissions.
- Centralized Control: Admins can easily grant, revoke, or disable accounts from a single dashboard.
Why is this the "Gold Standard" for security?
- Stress-free Admin: No need to manually create passwords, send keys, or manage secret files.
- Empowered Users: Users manage their own personal info and MFA devices.
- Instant Revocation: If an employee leaves, just disable them in the Identity Center. They immediately lose access to all accounts and roles.
- Total Safety: No Access Keys are left lying around on hard drives or any repository.
Step-by-Step Instructions
First, create the file lib/sso-policy-group-stack.ts with the following content:
Explain:
- sessionDuration: "PT2H" stands for a Period of Time of 2 hours. You can configure this duration flexibly depending on the sensitivity of the tasks the user is permitted to perform:
- PT15M (15 minutes): For extremely sensitive operations (e.g., Deleting Databases, Root Access).
- PT8H (8 hours): Sufficient for a standard office shift.
- PT12H (12 hours): The typical maximum duration for developers working throughout the day.
- devPermissionSet: I’m creating a policy that allows full access to AWS S3, but only if the account has MFA enabled.
- devGroup & CfnAssignment: This creates a group and assigns the policy to it. Now, you just need to add a user to this group, and they will automatically inherit these permissions.
- To find your ssoInstanceArn and identityStoreId, run this command:
Next, update your bin/aws-cdk.ts file:
Managing Users
After deploying the stack to AWS, go to the IAM Identity Center console to create a User. Make sure to assign them to the correct User Group.
Once created, the user will receive an email. They should follow the link to set their password, set up MFA, and log in.
To work with AWS via the terminal, the user first needs to configure SSO:
- SSO session name: This is the username you have created.
- SSO start URL: You can find this value in IAM Identity Center > AWS access portal URLs. Alternatively, using the IdentityStoreId (which I showed you how to retrieve above), the URL will follow this format: https://{IdentityStoreId}.awsapps.com/start
- Profile name: You can set this value to anything you like. When using the AWS CLI later, you will specify this profile to execute commands.
In the future, the user just needs to log back in using the created profile:
- After logging in via SSO, AWS does not save your Access Keys into a .env file. Instead:
- Root SSO Token: Stored in ~/.aws/sso/cache/ (as a JSON file). This token has a long duration (typically several days).
- Temporary Credentials: When you want to use AWS, simply specify the correct profile you created. AWS will automatically use the Root Token to exchange it for a temporary Access Key/Secret Key, which is then stored in RAM or a short-term cache.
Now, the user can access services they have permission for:
Happy coding!
Comments
Post a Comment