AWS Big Data Blog
Modernize Amazon Redshift authentication by migrating user management to AWS IAM Identity Center
Amazon Redshift is a powerful cloud-based data warehouse that organizations can use to analyze both structured and semi-structured data through advanced SQL queries. As a fully managed service, it provides high performance and scalability while allowing secure access to the data stored in the data warehouse. Organizations worldwide rely on Amazon Redshift to handle massive datasets, upgrade their analytics capabilities, and deliver valuable business intelligence to their stakeholders.
AWS IAM Identity Center serves as the preferred platform for controlling workforce access to AWS tools, including Amazon Q Developer. It allows for a single connection to your existing identity provider (IdP), creating a unified view of users across AWS applications and applying trusted identity propagation for a smooth and consistent experience.
You can access data in Amazon Redshift using local users or external users. A local user in Amazon Redshift is a database user account that is created and managed directly within the Redshift cluster itself. Amazon Redshift also integrates with IAM Identity Center, and supports trusted identity propagation, so you can use third-party IdPs such as Microsoft Entra ID (Azure AD), Okta, Ping, OneLogin, or use IAM Identity Center as an identity source. The IAM Identity Center integration with Amazon Redshift supports centralized authentication and SSO capabilities, simplifying access management across multi-account environments. As organizations grow in scale, it is recommended to use external users for cross-service integration and centralized access management.
In this post, we walk you through the process of smoothly migrating your local Redshift user management to IAM Identity Center users and groups using the RedshiftIDCMigration utility.
Solution overview
The following diagram illustrates the solution architecture.
The RedshiftIDCMigration utility accelerates the migration of your local Redshift users, groups, and roles to your IAM Identity Center instance by performing the following activities:
- Create users in IAM Identity Center for every local user in a given Redshift instance.
- Create groups in IAM Identity Center for every group or role in a given Redshift instance.
- Assign users to groups in IAM Identity Center according to existing assignments in the Redshift instance.
- Create IAM Identity Center roles in the Redshift instance matching the groups created in IAM Identity Center.
- Grant permissions to IAM Identity Center roles in the Redshift instance based on the current permissions given to local groups and roles.
Prerequisites
Before running the utility, complete the following prerequisites:
- Enable IAM Identity Center in your account.
- Follow the steps in the post Integrate Identity Provider (IdP) with Amazon Redshift Query Editor V2 and SQL Client using AWS IAM Identity Center for seamless Single Sign-On (specifically, follow Steps 1–8, skipping Steps 4 and 6).
- Configure the IAM Identity Center application assignments:
- On the IAM Identity Center console, choose Application Assignments and Applications.
- Select your application and on the Actions dropdown menu, choose Edit details.
- For User and group assignments, choose Do not require assignments. This setting makes it possible to test Amazon Redshift connectivity without configuring specific data access permissions.
- Configure IAM Identity Center authentication with administrative access from either Amazon Elastic Compute Cloud (Amazon EC2) or AWS CloudShell.
The utility will be run from either an EC2 instance or CloudShell. If you’re using an EC2 instance, an IAM role is attached to the instance. Make sure that the IAM role used during the execution has the following permissions (if not, create a new policy with those permissions and attach it to the IAM role):
- Amazon Redshift permissions (for serverless):
- Amazon Redshift permissions (for provisioned):
- Amazon Simple Storage Service (Amazon S3) permissions:
- Identity store permissions:
Artifacts
Download the following utility artifacts from the GitHub repo:
- idc_redshift_unload_indatabase_groups_roles_users.py – A Python script to unload users, groups, roles and their associations.
- redshift_unload.ini – The config file used in the preceding script to read Redshift data warehouse details and Amazon S3 locations to unload the files.
- idc_add_users_groups_roles_psets.py – A Python script to create users and groups in IAM Identity Center, and then associate the users to groups in IAM Identity Center.
- idc_config.ini – The config file used in the preceding script to read IAM Identity Center details.
- vw_local_ugr_to_idc_urgr_priv.sql – A script that generates SQL statements that perform two tasks in Amazon Redshift:
- Create roles that exactly match your IAM Identity Center group names, adding a specified prefix.
- Grant appropriate permissions to these newly created Redshift roles.
Testing scenario
This test case is designed to offer practical experience and familiarize you with the utility’s functionality. The scenario is structured around a hierarchical nested roles system, starting with object-level permissions assigned to technical roles. These technical roles are then allocated to business roles. Finally, business roles are granted to individual users. To enhance the testing environment, the scenario also incorporates a user group.The following diagram illustrates this hierarchy.
Create datasets
Set up two separate schemas (tickit
and tpcds
) in a Redshift database using the create schema command. Then, create and populate a few tables in each schema using the tickit and tpcds sample datasets.
Specify the appropriate IAM role Amazon Resource Name (ARN) in the copy commands if necessary.
Create users
Create users with the following code:
Create business roles
Create business users with the following code:
Create technical roles
Create technical roles with the following code:
Create groups
Create groups with the following code:
Grant rights to technical roles
To grant rights to the technical roles, use the following code:
Grant technical roles to business roles
To grant the technical roles to the business roles, use the following code:
Grant business roles to users
To grant the business roles to users, use the following code:
Grant rights to groups
To grant rights to the groups, use the following code:
Add users to groups
To add users to the groups, use the following code:
Deploy the solution
Complete the following steps to deploy the solution:
- Update Redshift cluster or serverless endpoint details and Amazon S3 location in
redshift_unload.ini
:- cluster_type =
provisioned
orserverless
- cluster_id =
${cluster_identifier}
(required ifcluster_type
isprovisioned
) - db_user =
${database_user}
- db_name =
${database_name}
- host =
${host_url}
(required ifcluster_type
isprovisioned
) - port =
${port_number}
- workgroup_name =
${workgroup_name}
(required ifcluster_type
isserverless
) - region =
${region}
- s3_bucket =
${S3_bucket_name}
- roles =
roles.csv
- users =
users.csv
- role_memberships =
role_memberships.csv
- cluster_type =
- Update IAM Identity Center details in
idc_config.ini
:- region =
${region}
- account_id =
${account_id}
- identity_store_id =
${identity_store_id}
(available on the IAM Identity Center console Settings page) - instance_arn =
${iam_identity_center_instance_arn}
(available on the IAM Identity Center console Settings page) - permission_set_arn =
${permission_set_arn}
- assign_permission_set =
True
orFalse
(True
ifpermission_set_arn
is defined) - s3_bucket =
${S3_bucket_name}
- users_file =
users.csv
- roles_file =
roles.csv
- role_memberships_file =
role_memberships.csv
- region =
- Create a directory in CloudShell or on your own EC2 instance with connectivity to Amazon Redshift.
- Copy the two .ini files and download the Python scripts to that directory.
- Run
idc_redshift_unload_indatabase_groups_roles_users.py
either from CloudShell or your EC2 instance:python idc_redshift_unload_indatabase_groups_roles_users.py
- Run
idc_add_users_groups_roles_psets.py
either from CloudShell or your EC2 instance:python idc_add_users_groups_roles_psets.py
- Connect your Redshift cluster using the Amazon Redshift query editor v2 or preferred SQL client, using superuser credentials.
- Copy the SQL in the
vw_local_ugr_to_idc_urgr_priv.sql
file and run it in the query editor to create thevw_local_ugr_to_idc_urgr_priv
view. - Run following SQL command to generate the SQL statements for creating roles and permissions:
For example, consider the following existing grants:
These grants are converted to the following code:
- Review the statements in the
idc_based_grants
column.
This might not be a comprehensive list of permissions, so review them carefully. - If everything is correct, run the statements from the SQL client.
When you have completed the process, you should have the following configuration:
- IAM Identity Center now contains newly created users from Amazon Redshift
- The Redshift local groups and roles are created as groups in IAM Identity Center
- New roles are established in Amazon Redshift, corresponding to the groups created in IAM Identity Center
- The newly created Redshift roles are assigned appropriate permissions
If you encounter an issue while connecting to Amazon Redshift with the query editor using IAM Identity Center, refer to Troubleshooting connections from Amazon Redshift query editor v2.
Considerations
Consider the following when using this solution:
- At the time of writing, creating permissions in AWS Lake Formation is not in scope.
- IAM Identity Center and IdP integration setup is out of scope for this utility. However, you can use the view
vw_local_ugr_to_idc_urgr_priv.sql
to create roles and grant permissions to the IdP users and groups passed through IAM Identity Center. - If you have permissions given directly to local user IDs (not using groups or roles), you must change that to a role-based permission approach for IAM Identity Center integration. Create roles and provide permissions using roles instead of directly giving permissions to users.
Clean up
If you have completed the testing scenario, clean up your environment:
- Remove the new Redshift roles that were created by the utility, corresponding to the groups established in IAM Identity Center.
- Delete the users and groups created by the utility within IAM Identity Center.
- Delete the users, groups, and roles specified in the testing scenario.
- Drop the
tickit
andtpcds
schemas.
You can use the FORCE parameter when dropping the roles to remove associated assignments.
Conclusion
In this post, we showed how to migrate your Redshift local user management to IAM Identity Center. This transition offers several key advantages for your organization, such as simplified access management through centralized user and group administration, a streamlined user experience across AWS services, and reduced administrative overhead. You can implement this migration process step by step, so you can test and validate each step before fully transitioning your production environment.
As organizations continue to scale their AWS infrastructure, using IAM Identity Center becomes increasingly valuable for maintaining secure and efficient access management, including Amazon SageMaker Unified Studio for an integrated experience for all your data and AI.