In right now’s data-driven world, securely accessing, visualizing, and analyzing information is crucial for making knowledgeable enterprise selections. Tens of hundreds of consumers use Amazon Redshift for contemporary information analytics at scale, delivering as much as 3 times higher price-performance and 7 occasions higher throughput than different cloud information warehouses. The Amazon Redshift Information API simplifies entry to your Amazon Redshift information warehouse by eradicating the necessity to handle database drivers, connections, community configurations, information buffering, and extra.
With the newly launched characteristic of Amazon Redshift Information API help for single sign-on and trusted id propagation, you may construct information visualization purposes that combine single sign-on (SSO) and role-based entry management (RBAC), simplifying person administration whereas imposing applicable entry to delicate data. As an illustration, a world sports activities gear firm promoting merchandise throughout a number of areas wants to visualise its gross sales information, which incorporates country-level particulars. To keep up the fitting stage of entry, the corporate needs to limit information visibility primarily based on the person’s position and area. Regional gross sales managers ought to solely see gross sales information for his or her particular area, similar to North America or Europe. Conversely, the worldwide gross sales executives require full entry to your entire dataset, protecting all nations.
On this publish, we dive into the newly launched characteristic of Amazon Redshift Information API help for SSO, Amazon Redshift RBAC for row-level safety (RLS) and column-level safety (CLS), and trusted id propagation with AWS IAM Id Middle to let company identities hook up with AWS providers securely. We exhibit combine these providers to create a knowledge visualization utility utilizing Streamlit, offering safe, role-based entry that simplifies person administration whereas ensuring that your group could make data-driven selections with enhanced safety and ease.
Resolution overview
We use a number of AWS providers and open supply instruments to construct a easy information visualization utility with SSO to entry information in Amazon Redshift with RBAC. The important thing elements that energy the answer are as follows:
- IAM Id Middle and trusted id propagation – IAM Id Middle can simplify person administration by enabling SSO throughout AWS providers. This permits customers to authenticate with their company credentials managed of their company id supplier (IdP) like Okta, offering seamless entry to the applying. We discover how trusted id propagation allows managing application-level entry management at scale and exercise logging throughout AWS providers, like Amazon Redshift, by propagating and sustaining id context all through the workflow.
- Exterior IdP – We use Okta as an exterior IdP to handle person authentication. Okta connects to IAM Id Middle, permitting customers to authenticate from exterior methods whereas sustaining centralized id administration inside AWS. This makes positive that person entry and roles are constantly maintained throughout each AWS providers and exterior instruments.
- Amazon Redshift Serverless workgroup, Amazon Redshift Information API, and Amazon Redshift RBAC – Amazon Redshift is a completely managed information warehouse service that enables for quick querying and evaluation of enormous datasets. On this answer, we use the Redshift Information API, which gives a easy and safe HTTP-based connection to Amazon Redshift, eliminating the necessity for JDBC or ODBC driver-based connections. The Redshift Information API is the beneficial methodology to attach with Amazon Redshift for net purposes. We additionally use RBAC in Amazon Redshift to exhibit entry restrictions on gross sales information primarily based on the area column, ensuring that regional gross sales managers solely see information for his or her assigned areas, whereas world gross sales managers have full entry.
- Streamlit utility – Streamlit is a extensively used open supply software that allows the creation of interactive information purposes with minimal code. On this answer, we use Streamlit to construct a user-friendly interface the place gross sales managers can view and analyze gross sales information in a visible, accessible format. The applying will combine with Amazon Redshift, offering customers with entry to the information primarily based on their roles and permissions.
The next diagram illustrates the answer structure for SSO with the Redshift Information API utilizing IAM Id Middle.
The person workflow for the information visualization utility consists of the next steps:
- The person (whether or not a regional gross sales supervisor or world gross sales supervisor) accesses the Streamlit utility, which is built-in with SSO to offer a seamless authentication expertise.
- The applying redirects the person to authenticate by way of Okta, the exterior IdP. Okta verifies the person’s credentials and returns an ID token to the applying.
- The applying makes use of the token issued by Okta to imagine a task and short-term AWS Id and Entry Administration (IAM) session credentials to name the IAM Id Middle
AssumeRoleWithWebIdentity
API and IAMAssumeRole
API in later steps. - The applying exchanges the Okta ID token for a token issued by IAM Id Middle by calling the IAM Id Middle
CreateTokenWithIAM
API utilizing the short-term IAM credentials from the earlier step. This token makes positive that the person is authenticated with AWS providers and is tied to the IAM Id Middle person profile. - The applying requests an identity-enhanced IAM position session utilizing the IAM Id Middle token by calling the
AssumeRole
- The applying makes use of the identity-enhanced IAM position session credentials to securely question Amazon Redshift for gross sales information. The credentials guarantee that solely approved customers can work together with the Redshift information.
- Because the question is processed, Amazon Redshift checks the id context offered by IAM Id Middle. It verifies the person’s position and group membership, similar to being part of the North American area or the worldwide gross sales supervisor group.
- Primarily based on the person’s id and group membership, and utilizing Amazon Redshift RBAC and row-level safety, Amazon Redshift makes an authorization choice. The teams for the illustration may be broadly categorized into the next classes:
- Regional gross sales managers will probably be granted entry to view gross sales information just for the particular nation or area they handle. As an illustration, the AMER North American Gross sales Supervisor will solely see gross sales information associated to North America. Equally, the entry management primarily based on EMEA and APAC areas will present row-level safety for the respective areas.
- The worldwide gross sales managers will probably be granted full entry to all areas, enabling them to view your entire world dataset.
The setup consists of two most important steps:
- Provision the sources for IAM Id Middle, Amazon Redshift and Okta:
- Allow IAM Id Middle and configure Okta because the IdP to handle person authentication and group provisioning.
- Create an Okta utility to authenticate customers accessing the Streamlit utility.
- Arrange an Amazon Redshift IAM Id Middle connection utility to allow trusted id propagation for safe authentication.
- Provision an Amazon Redshift Serverless
- Create the tables and configure RBAC inside the Redshift workgroup to implement row-level safety for various IAM Id Middle federated roles, mapped to IAM Id Middle teams.
- Obtain, configure, and run the Streamlit utility:
- Create a buyer managed utility in IAM Id Middle for the Redshift Information API shopper (Streamlit utility) to allow safe API-based queries and create the required IAM roles
- Configure the Streamlit utility.
- Run the Streamlit utility.
Stipulations
You must have the next stipulations:
Provision the sources for IAM Id Middle, Amazon Redshift, and Okta
On this part, we stroll by way of the steps to provision the sources for IAM Id Middle, Amazon Redshift, and Okta.
Allow IAM Id Middle and configure Okta because the IdP
Full the next steps to allow IAM Id Middle and configure Okta because the IdP to handle person authentication and group provisioning:
- Create the next customers and teams in Okta:
- Ethan World with e-mail
ethan@instance.com
, in groupexec-global
- Frank Amer with e-mail
frank@instance.com
, in groupamer-sales
- Alex Emea with e-mail
alex@instance.com
, in groupemea-sales
- Ming Apac with e-mail
ming@instance.com
, in groupapac-sales
- Ethan World with e-mail
- Create an IAM Id Middle occasion within the AWS Area the place Amazon Redshift goes to be deployed. A company occasion kind is beneficial.
- Configure Okta because the id supply and allow automated person and group provisioning. The customers and teams will probably be pushed to IAM Id Middle utilizing SCIM protocol.
The next screenshot exhibits the customers synced in IAM Id Middle utilizing SCIM protocol.
Create an Okta utility
Full the next steps to create an Okta utility to authenticate customers accessing the Streamlit utility:
- Create an OIDC utility in Okta.
- Copy and save the shopper ID and shopper secret wanted later for the Streamlit utility and the IAM Id Middle utility to attach utilizing the Redshift Information API.
- Generate the shopper secret and set sign-in redirect URL and sign-out URL to
http://localhost:8501
(we’ll host the Streamlit utility regionally on port 8501). - Below Assignments, Managed entry, grant entry to everybody.
- Create an OIDC IdP on IAM the console. The next screenshot exhibits an IdP created on the IAM console.
Arrange an Amazon Redshift IAM Id Middle connection utility
Full the next steps to create an Amazon Redshift IAM Id Middle connection utility to allow trusted id propagation for safe authentication:
- On the Amazon Redshift console, select IAM Id Middle connection within the navigation pane.
- Select Create utility.
- Title the applying
redshift-data-api-okta-app
. - Notice down the IdP namespace. The default worth
AWSIDC
is used for this publish. - Within the IAM position for IAM Id Middle entry part, it’s good to present an IAM position. You possibly can go to the IAM console and create an IAM position known as
RedshiftOktaRole
with the next coverage and belief relationship.RedshiftOktaRole
is utilized by the Amazon Redshift IAM Id Middle connection utility to handle and work together with IAM Id Middle.- The coverage connected to the position wants the next permissions:
- The position makes use of the next belief relationship:
- Depart Trusted Id propagation part unchanged, then select Subsequent. You could have the choice to decide on AWS Lake Formation or Amazon S3 Entry Grants to be used circumstances like utilizing Amazon Redshift Spectrum to question exterior tables in Lake Formation. In our use case, we solely use Amazon Redshift native tables so we don’t select both.
- Within the Configure shopper connections that use third-party IdPs part, select No.
- Assessment and select Create utility.
- When the applying is created, navigate to your IAM Id Middle connection
redshift-data-api-okta-app
and select Assign so as to add the teams that have been synced in IAM Id Middle utilizing SCIM protocol from Okta.
We are going to allow trusted id propagation and third-party IdP (Okta) on the client managed utility for the Redshift Information API in a later step as a substitute of configuring it within the Amazon Redshift connection utility.
The next screenshot exhibits the IAM Id Middle connection utility created on the Amazon Redshift console.
The next screenshot exhibits teams assigned to the Amazon Redshift IAM Id Middle connection for the managed utility.
Provision a Redshift Serverless workgroup
Full the next steps to create a Redshift Serverless workgroup. For extra particulars, discuss with Making a workgroup with a namespace.
- On the Amazon Redshift console, navigate to the Redshift Serverless dashboard.
- Select Create workgroup.
- Enter a reputation in your workgroup (for instance,
redshift-tip-enabled
). - Change the Base capability to eight RPU within the Efficiency and price management
- You possibly can configure community and safety primarily based in your digital personal cloud (VPC) and subnet you wish to create the workgroup.
- Within the Namespace part, create a brand new namespace in your workgroup. (For instance,
redshift-tip-enabled-namespace
). - Within the Database identify and password part, choose Customise admin person credentials and set the admin person identify and create a password. Notice them down to make use of in a later step to configure RBAC in Amazon Redshift.
- Within the Id Middle connections part, select Allow for the cluster possibility and choose the Amazon Redshift IAM Id Middle utility created within the earlier step (
redshift-data-api-okta-app
). - Affiliate an IAM position with the workgroup that has the next insurance policies connected. Make it the default position to make use of.
- Depart different settings as default and select Subsequent.
- Assessment the settings and create the workgroup.
Wait till the workgroup is obtainable earlier than persevering with to the subsequent steps.
Create the tables and configure RBAC inside the Redshift Serverless workgroup
Subsequent, you employ the Amazon Redshift Question Editor V2 on the Amazon Redshift console to connect with the workgroup you simply created. You create the tables and configure the Amazon Redshift roles akin to Okta teams for the teams in IAM Id Middle and use the RBAC coverage to grant customers privileges to view information just for their areas. Full the next steps:
- On the Amazon Redshift console, open the Question Editor V2.
- Select the choices menu (three dots) subsequent to the Redshift workgroup identify and select Edit connection.
- Choose Different methods to attach and use the database person identify and password to attach.
- Within the question editor, run the next code to create the gross sales desk and cargo the information from Amazon Easy Storage Service (Amazon S3):
IAM Id Middle will map the teams into the Redshift roles within the format of Namespace:IDCGroupName
. Due to this fact, create the position identify as AWSIDC:emea-sales
and so forth to match them with Okta group names synced in IAM Id Middle. The customers will probably be created robotically inside the teams as they log in utilizing SSO into Amazon Redshift.
Obtain, configure, and run the Streamlit utility
On this part, we stroll by way of the steps to obtain, configure, and run the Streamlit utility.
Create a buyer managed utility in IAM Id Middle for the Redshift Information API shopper
With a purpose to begin a trusted id propagation workflow and permit Amazon Redshift to make authorization selections primarily based on the customers and teams from IAM Id Middle (provisioned from the exterior IdP), you want an identity-enhanced IAM position session.
This requires a few IAM roles and a buyer managed utility in IAM Id Middle to deal with the belief relationship between the exterior IdP and IAM Id Middle and management entry for the Redshift Information API shopper, on this case, the Streamlit utility.
First, you create two IAM roles, then you definitely create a buyer managed utility for the Streamlit utility. Full the next steps:
- Create a short lived IAM position (we named it
IDCBridgeRole
) to alternate the token with IAM Id Middle (assuming you don’t have an current IAM id to make use of). This position will probably be assumed by the Streamlit utility withAssumeRoleWithWebIdentity
to get a short lived set of position credentials to name theCreateTokenWithIAM
andAssumeRole
APIs to get the identity-enhanced position session.- Connect the next coverage the position:
- Within the belief relationship, present your AWS account ID and IdP’s URL. The trusted principal to make use of is the Amazon Useful resource Title (ARN) of
oidc-provider
you created earlier.
- Create an IAM position with permissions to entry the Redshift Information API (we named it
RedshiftDataAPIClientRole
). This position will probably be assumed by the Streamlit utility with the improved identities from IAM Id Middle after which used to authenticate requests to the Redshift Information API.- Connect the AmazonRedshiftDataFullAccess AWS managed coverage. AWS recommends utilizing the precept of least privilege in your IAM coverage.
- Limit the belief relationship to the
IDCBridgeRole
ARN created within the earlier step), and supply your AWS account ID:
Now you may create the client managed utility.
- On the IAM Id Middle console, select Purposes within the navigation pane.
- Select Add utility.
- Select I’ve an utility I wish to setup, choose the OAuth 2.0 utility kind, and select Subsequent.
- Enter a reputation for the applying, for instance,
RedshiftStreamlitDemo
. - In Person and group project methodology, select Don’t require project. This implies all of the customers provisioned in IAM Id Middle from Okta can use their Okta credentials to sign up to the Streamlit utility. You possibly can alternatively choose the Require assignments possibility and decide the customers and teams you wish to permit entry to the applying.
- Within the AWS entry portal part, select Not seen, then select Subsequent.
- Within the Authentication with trusted token issuer part, choose Create trusted token issuer, then enter the Okta issuer URL and enter a reputation for the trusted token issuer.
- Within the map attribute, use the default e-mail to e-mail mapping between the exterior IdP attribute and IAM Id Middle attribute, then create the trusted token issuer.
- Choose the trusted token issuer you simply created.
- Within the Aud declare part, use the shopper ID of the Okta utility you famous earlier, then select Subsequent.
- Within the Specify utility credentials part, select Edit the applying coverage and use the next coverage:
- Select Submit.
After the applying is created, you may view it in on the IAM Id Middle.
- Select Purposes within the navigation pane, and find the Buyer managed purposes tab.
- Select the applying to navigate to the applying particulars web page.
- Within the Trusted purposes for id propagation part, select Specify trusted purposes and choose the setup kind as Particular person purposes and specify entry, then select Subsequent.
- Select Amazon Redshift because the service, then select Subsequent.
- Within the Utility that may obtain requests part, select the Amazon Redshift IAM Id Middle utility you created, then select Subsequent.
- Within the Entry Scopes to use part, examine the redshift:join
- Assessment after which select Belief utility.
Configure and run the Streamlit utility
Now that you’ve got the roles and the client managed utility in IAM Id Middle, you may create an identity-enhanced IAM position session, which is probably the most vital step to allow trusted id propagation. Following steps present an outline of Streamlit utility code to create the identity-enhanced IAM position session.
- Authenticate with and retrieve the
id_token
from the exterior IdP (Okta). - Name
CreateTokenWithIAM
utilizing the exterior IdP issuedid_token
to acquire an IAM Id Middle issuedid_token
. - Use
AssumeRoleWithWebIdentity
to acquire short-term IAM credentials (by assumingIDCBridgeRole
, defined later). - Extract the
sts:identity_context
from the IAM Id Middle issuedid_token
. - Assume the position
RedshiftDataAPIClientRole
with theAssumeRole
API and insert thests:identity_context
to acquire the identity-enhanced IAM position session credentials.
Now you need to use these credentials to make requests to the Redshift Information API, and Amazon Redshift will have the ability to use the id context for authorization selections.
At this level, you need to have all of the required sources for creating the Streamlit utility. Full the next steps to check the Streamlit utility:
- Obtain the Streamlit utility code and modify the configuration part of the code primarily based on the sources provisioned earlier:
We advocate internet hosting this utility on an Amazon Elastic Compute Cloud (Amazon EC2) occasion for manufacturing use circumstances, and utilizing AWS Secrets and techniques Supervisor for delicate data just like the CLIENT_ID
and CLIENT_SECRET
offered as configuration parameters within the code for simplicity.
For this instance, we use the Okta group URL (/oauth2/v1/
). You should use the client authorization servers as effectively, for instance, the default authorization server, however be sure all URLs are utilizing the identical authorization server. Consult with Authorization servers for extra details about authorization servers in Okta.
After you modify the script for the Streamlit utility, you may run it utilizing a Python digital atmosphere.
- Create a Python digital atmosphere. The applying has been examined efficiently with variations v3.12.8 and v3.12.2.
You might want to set up the next packages, that are required libraries for the Streamlit utility code you downloaded in your digital atmosphere:
streamlit
streamlit_oauth
boto3
pyjwt
pydeck
pandas
- You possibly can set up these libraries instantly utilizing the next command with the necessities file:
- Check the Streamlit utility within the Python digital atmosphere with the next command:
- Log in with the person ming@instance.com from the
apac-sales
group.
The identity-enhanced position session credentials will show on the highest of the web page after profitable authentication with Okta.
For the APAC area supervisor, you need to solely see the information from the nations within the Asia-Pacific area primarily based on the row-level safety filter you configured earlier.
- Log off and log again in with the worldwide govt person, ethan@instance.com from the
exec-global
You must see the information in all areas.
You possibly can attempt different regional customers’ logins and you need to see solely the information within the area they belong to.
Trusted id propagation deep dive
On this part, you stroll by way of the Python code of the Streamlit utility and clarify how trusted id propagation works. The next is an evidence of key components of the applying code.
most important()
The most important()
operate of the Streamlit utility implements the previous steps to get the identity-enhanced IAM position session utilizing the get_id_enhanded_session()
operate, which wraps the login to get the identity-enhanced position session credentials:
We use the Streamlit st.session_state
offered by Streamlit to retailer necessary session states, together with the authentication standing in addition to further data like person data and the AWS identity-enhanced position session credentials.
get_id_enhanced_session()
The get_id_enhanced_session()
operate code has three steps:
- We use the
id_token
(variable identify:jwt_token
) from Okta in JWT format to name theAssumeRoleWithWebIdentity
API to imagine the positionIDCBridgeRole
. It’s because the person doesn’t have any AWS credentials to work together with the IAM Id Middle API. For those who plan to host this utility in an AWS atmosphere with an IAM position out there, for instance, on an EC2 occasion, you need to use the position related to Amazon EC2 to make the decision to the IAM Id Middle APIs with out creatingIDCBridgeRole
, however be sure the EC2 position has the required permissions we specified forIDCBridgeRole
. - After now we have the credentials of the short-term position, we use them to make a name to the
CreateTokenWithIAM
API of IAM Id Middle. This API handles the alternate of tokens by taking within theid_token
from Okta and returning an IAM Id Middle issued token, which will probably be used later to get the identity-enhanced position session. For extra data, discuss with the CreateTokenWithIAM API reference. - Lastly, we extract the
sts:identity_context
from the IAM Id Middle issuedid_token
and cross it to the AWS Safety Token Service (AWS STS)AssumeRole
That is carried out by together with thests:identity_context
within theContextAssertion
parameter insideProvidedContexts
, together withProviderArn
set toarn:aws:iam::aws:contextProvider/IdentityCenter
.
assume_role_with_web_identity()
The assume_role_with_web_identity()
operate code is as follows. We initialize the STS shopper, decode the JWT token, after which assume the position with the net id.
create_token_with_iam()
The create_token_with_iam()
operate code is known as to get the id_token
from IAM Id Middle. The jwt_token
is the id_token
in JWT format issued by Okta; the id_token
is the IAM Id Middle issued id_token
.
Within the CreateTokenWithIAM
name, we cross the next parameters:
- clientId – The ARN of the IAM Id Middle utility for the Redshift Information API shopper
- grantType –
urn:ietf:params:oauth:grant-type:jwt-bearer
- assertion – The
id_token
(jwt_token
) issued by Okta
The idToken
issued by IAM Id Middle is returned.
assume_enhanced_role_session()
The assume_enhanced_role_session()
operate makes use of the ID token to imagine an identity-enhanced position session:
extract_identity_context_from_id_token()
The extract_identity_context_from_id_token()
operate extracts the sts:identity_context
:
Now you will have the identity-enhanced position session credentials to name the Amazon Redshift Information API.
execute_statement() and fetch_results()
The execute_statement()
and fetch_results()
features exhibit run Redshift queries and retrieve question outcomes with trusted id propagation for visualization:
Conclusion
On this publish, we confirmed create a third-party utility backed by analytics insights arriving from Amazon Redshift securely utilizing OIDC. With Redshift Information API help of IAM Id Middle integration, you may hook up with Amazon Redshift utilizing SSO from the IdP of your alternative. You possibly can lengthen this methodology to authenticate different AWS providers that help trusted id propagation, similar to Amazon Athena and Amazon QuickSight, enabling fine-grained entry management for IAM Id Middle customers and teams throughout your AWS ecosystem. We encourage you to arrange your utility utilizing IAM Id Middle integration and unify your entry management instantly out of your IdP throughout all IAM Id Middle supported AWS providers.
For extra data on AWS providers and purposes that help trusted id propagation, discuss with Trusted id propagation overview.
In regards to the Authors
Songzhi Liu is a Principal Huge Information Architect with the AWS Id Options group. On this position, he collaborates carefully with AWS clients and cross-functional groups to design and implement scalable information architectures, specializing in integrating massive information and machine studying options to boost id consciousness inside the AWS ecosystem.
Rohit Vashishtha is a Senior Analytics Specialist Options Architect at AWS primarily based in Dallas, Texas. He has over 19 years of expertise architecting, constructing, main, and sustaining massive information platforms. Rohit helps clients modernize their analytic workloads utilizing the breadth of AWS providers and ensures that clients get the perfect value/efficiency with utmost safety and information governance.
Fei Peng is a Senior Software program Growth Engineer working within the Amazon Redshift group, the place he leads the event of Redshift Information API, enabling seamless and scalable entry to cloud information warehouses.
Yanzhu Ji is a Product Supervisor within the Amazon Redshift group. She has expertise in product imaginative and prescient and technique in industry-leading information merchandise and platforms. She has excellent ability in constructing substantial software program merchandise utilizing net growth, system design, database, and distributed programming methods. In her private life, Yanzhu likes portray, images, and enjoying tennis.