AWS Big Data Blog
Federating single sign-on access to your Amazon Redshift cluster with PingIdentity
Single sign-on (SSO) enables users to have a seamless user experience while accessing various applications in the organization. If you’re responsible for setting up security and database access privileges for users and tasked with enabling SSO for Amazon Redshift, you can set up SSO authentication using ADFS, PingIdentity, Okta, Azure AD or other SAML browser based Identity Providers.
With federation, you can centralize management and governance of authentication and permissions by managing users and groups within the enterprise identity provider (IdP) and use them to authenticate to Amazon Redshift. For more information about the federation workflow using IAM and an identity provider, see Federate Database User Authentication Easily with IAM and Amazon Redshift.
This post shows you how to set up PingOne as your IdP. I provide step-by-step guidance to set up a trial account at pingidentity.com, build users and groups within your organization’s directory, and enable federated SSO into Amazon Redshift to maintain group-level access controls for your data warehouse.
Solution overview
The steps in this post are structured into the following sections:
- IdP (PingOne) groups configuration – Create groups and assign users to logical groups in PingOne.
- IdP (PingOne) application configuration – Create PingOne application(s) and configure AWS Identity and Access Management (IAM) roles, and groups allowed to be passed to Amazon Redshift.
- IAM SAML federation configuration – Setup a role that allows PingOne to access Amazon Redshift by establishing a trust relationship between PingOne IdP and AWS.
- Amazon Redshift groups and privileges setup – Setup groups within the Amazon Redshift database to match the PingOne groups. You also authorize these groups to access certain schemas and tables.
- Amazon Redshift server and client setup and test SSO – Finally, configure SQL client tools to use your enterprise credentials and sign in to Amazon Redshift.
The process flow for federated authentication is shown in the following diagram and steps:
- The user logs in using a JDBC/ODBC SQL client.
- The IdP authenticates using the corporate user name and password, and returns a SAML assertion.
- The client uses AWS SDK to call AWS Security Token Service (AWS STS) to assume a role with SAML.
- AWS STS returns temporary AWS credentials.
- The client uses the temporary AWS credentials to get temporary cluster credentials.
- The client connects to Amazon Redshift using the temporary credentials.
Setting up PingOne provider groups and users
Before you get started, sign up for a free trial of PingOne for Enterprise. You then create the users and groups, and assign the users to the groups they belong to and are authorized to access.
You create groups and users in the PingOne user directory. You can set up the groups according to the read/write access privileges or by business functions in your organization to control access to the database objects.
In this post, we set up groups based on ReadOnly
and ReadWrite
privileges across all functions.
- After you have a PingOne account, log in to the PingOne admin dashboard.
- Choose Setup from the menu bar.
- On the Identity Repository tab, choose Connect to an Identity Repository.
- For Select an Identity Repository, you will see options for PingOne Directory, Active Directory, PingFederate and others. Choose PingOne Directory and go to Next.
After you connect to the PingOne repository, you should see the status CONFIGURED
.
You can now create your groups and assign users.
- Choose Users from the menu bar.
- On the User Directory tab, choose Groups.
- Choose Add Group.
- For Name, enter
readonly
. - For Directly Applied Role, select No Access.
- Choose Save.
- Repeat these steps for your
readwrite
group. - To create the users, choose Users from the menu bar.
- On the User Directory tab, choose Users.
- Choose Add Users.
For this post, we create two users, Bob and Rachel.
- Under Group Memberships, for Memberships, select the group to add your user to.
For this post, we add Bob to readonly
and Rachel to readwrite
.
- Choose Add.
- Choose Save.
- Repeat these steps to create both users.
Configuring your IdP (PingOne) application
The next step is to set up the applications in the IdP for Amazon Redshift. Because we decided to control access through two groups, we create two applications.
- On the PingOne dashboard, choose Applications from the menu bar.
- On the My Applications tab, choose SAML.
- Choose Add Application.
- Choose New SAML Application.
- For Application Name, enter
AmazonRedshiftReadOnly
. - Choose Continue to Next Step.
- On the Application Configuration page, for Assertion Consumer Service (ACS), enter
http://localhost:7890/redshift/
. - For Entity ID, enter
urn:amazon:webservices
. - For Signing, select Sign Assertion.
- For Signing Algorithm, choose RSA_SHA256.
- Choose Continue to Next Step.
- On the SSO Attribute Mapping page, add the following application attributes:
Application Attribute | Identity Bridge | As Literal |
https://thinkwithwp.com/SAML/Attributes/Role |
|
True |
https://thinkwithwp.com/SAML/Attributes/RoleSessionName | Email |
|
https://redshift.amazon.com/SAML/Attributes/AutoCreate | true |
True |
https://redshift.amazon.com/SAML/Attributes/DbUser | Email |
|
https://redshift.amazon.com/SAML/Attributes/DbGroups |
Choose Advanced and for Function, choose ExtractByRegularExpression. For Expression, enter This regular expression is to remove the Refer to the PingIdentity documentation for more details on parsing the memberof attribute in PingOne. |
- Choose Continue to Next Step.
- On the Group Access page, add the groups that this application can access.
This adds the users who are members of that group so they can SSO to the application.
- On the Review Setup page, for SAML Metadata, choose Download.
- Save the file as
ping-saml-readonly.xml
.
You use this file later to import the metadata to create the PingOne IdP.
- Record the URL for Initiate Single Sign-On (SSO).
You use this URL to set up the SQL client for federated SSO.
- Choose Finish.
- Repeat these steps to create the second application,
AmazonRedshiftReadWrite
, with the following changes:- On the SSO Attribute Mapping page, use the IAM role name
pingreadwriterole
and IdP namepingreadwriteprov
. - Save the SAML metadata file as
ping-saml-readwrite.xml
.
- On the SSO Attribute Mapping page, use the IAM role name
You should now see the two application names on the My Applications tab.
Configuring IAM SAML federation
To set up your IAM SAML configuration, you create the IAM IdP and the roles and policies for the groups.
Setting up the IAM SAML IdP
You set up the IAM IdP and the roles used in the PingOnereadonly
and PingOnereadwrite
applications to establish a trust relationship between the IdP and AWS. You need to create two IAM IdPs, one for each application. Complete the following steps:
- On the IAM console, under Access management, choose Identity providers.
- Choose Create Provider.
- For Provider Type, choose SAML.
- For Provider name, enter
pingreadonlyprov
. - For Metadata Document, choose the metadata XML file you downloaded from the
AmazonRedshiftReadOnly
application.
- Repeat these steps to create the provider
pingreadwriteprov
.- Choose the metadata XML file you downloaded from the
AmazonRedshiftReadWrite
application.
- Choose the metadata XML file you downloaded from the
You now have two IdP providers: pingreadonlyprov
and pingreadwriteprov
.
Creating the IAM role and policy for the groups
You control access privileges to database objects for specific user groups by using IAM roles. In this section, you create separate IAM roles with policies to map to each of the groups defined in PingOne. These roles allow the user to access Amazon Redshift through the IdP.
You use the same role names that you used to set up applications in PingOne: pingreadonlyrole
and pingreadwriterole
.
Before you create the role, create the policies with the appropriate joingroup
privileges.
- On the IAM console, under Access Management, choose Policies.
- Choose Create policy.
- On the JSON tab, enter the following code to create the two policies.
- Replace <cluster> with your cluster name and <dbname> with your database name.
The only difference between the two policies is the Action- redshift:JoinGroup
section:
“JoinGroup”: pingreadonlypolicy
allows users to join thereadonly
group“JoinGroup”: pingreadwritepolicy
allows users to join thereadwrite
group
The group membership lasts only for the duration of the user session, and there is no CreateGroup
permission because you need to manually create groups and grant DB privileges in Amazon Redshift.
The following code is the pingreadonlypolicy
policy:
The following code is the pingreadwritepolicy
policy:
- On the IAM console, choose Roles.
- Choose Create role.
- For Select type of trusted entity, choose SAML 2.0 federation.
- For SAML provider, choose the provider you created.
- Select Allow programmatic access only.
- For Attribute, choose SAML:aud.
- For Value, enter
http://localhost:7890/redshift/
.
- Select pingreadonlypolicy for the first role and pingreadwritepolicy for the second role.
- Enter a name and description for each role.
The following screenshot shows your new roles: pingreadonlyrole
and pingreadwriterole
.
Setting up your groups and privileges in Amazon Redshift
In this section, you create the database groups in Amazon Redshift. These group names should match the group names you used when you set up your PingOne groups. Then you assign privileges to the groups to access the database objects including schemas and tables. User assignment to groups is done only one time in PingOne; you don’t assign users to groups in Amazon Redshift.
- Log in to your Amazon Redshift cluster with an admin account using the admin database credentials.
- Use the following scripts to create groups that match the IdP group names and grant the appropriate permissions to tables and schemas:
Setting up your Amazon Redshift server and client and testing SSO
In these final steps, you set up your client tools to use your enterprise credentials and sign in to Amazon Redshift.
Configuring the JDBC SQL Client using SQL Workbench/J
If you haven’t installed the JDBC driver, you can download the Amazon Redshift JDBC driver from the console. You then set up a new connection to your cluster using your PingOne IdP credentials.
- Create two new connection profiles,
Redshift-ReadOnly
andRedshift-ReadWrite
. - For URL, enter
jdbc:redshift:iam://<cluster endpoint>
.
IAM authentication requires using the JDBC driver with the AWS SDK included or making sure the AWS SDK is within your Java classpath.
You don’t need to enter a user name or password in JDBC setting. PingIdentity prompts you to log in on the web browser.
- Choose Extended Properties to define the SSO parameters for
loging_url
andplugin_name
.
- In the Edit extended properties section, enter the following properties and values:
Property | Value |
login_url | https://sso.connect.PingOne.com/sso/sp/initsso?saasid= |
plugin_name | com.amazon.redshift.plugin.BrowserSamlCredentialsProvider |
listen_port | 7890 |
idp_response_timeout | 60 |
The login_url
is the URL from the PingOne AmazonRedshift
applications you set up earlier. Choose the SSO URL from the RedshiftReadOnly
application for the readonly
connection and the SSO URL from RedshiftReadWrite
application for the readwrite
connection.
The configuration in your extended properties screen should look like the screenshot below:
- Choose OK.
Testing SSO authentication and access privileges
When you log in from the SQL client, you’re redirected to the browser to sign in with your PingOne user name and password.
Log in as user bob
with the IdP password.
This user has access to SELECT
all tables in the finance
schema and not INSERT/UPDATE access. You can enter the following statements to test your access.
The following query shows the results from the finance.revenue
table:
When you run an INSERT statement, you get the message that you’re not authorized to insert data:
You can repeat these steps for the user rachel
, who has access to read and write (INSERT) data into the finance schema.
Configuring the ODBC client
To configure your ODBC client, complete the following steps.
- Open the ODBC Data source administrator from your desktop.
- On the System DSN tab, choose Add.
- For Server, enter your Amazon Redshift ODBC endpoint.
- For Port, enter
5439
. - For Database, enter your database name.
- For Auth Type, choose Identity Provider: Browser SAML to use browser-based authentication.
- For Cluster ID, enter your cluster ID.
- For Preferred Role, enter your IAM role ARN.
- For Login URL, enter your PingOne login URL from the application configuration (
https://sso.connect.PingOne.com/sso/sp/initsso?saasid=<saasid>&idpid=<idpid>
).
- For Listen port, enter
7890
(default). - For Timeout, enter
60
.
Summary
In this blog post, I walked you through a step-by-step guide to configure and use PingOne as your IdP and enabled federated SSO to an Amazon Redshift cluster. You can follow these steps to setup federated SSO for your organization and manage access privileges based on read/write privileges or by business function and passing group membership defined in your PingOne IdP to your Amazon Redshift cluster.
About the Authors
Rajesh Francis is a Sr. Analytics Specialist Solutions Architect at AWS. He specializes in Amazon Redshift and works with customers to build scalable Analytic solutions.