Configuring Amazon Redshift with IAM Authentication
This article demonstrates how AWS-based customers can set up their worker node configuration so that the worker node can access Redshift databases using IAM-based authentication.
AWS Configuration
Cluster ARN
-
In the Amazon Redshift console, navigate to Clusters to select your desired cluster.
-
The details page for the given cluster will contain all the necessary data to form the Redshift ARN.
-
Choose the format option, db-user, in order to create a temporary credential using the AutoCreate option.
-
Update the
region,account-id, andcluster-namewith your respective values. -
For the dbuser-name, specify the user name that is used to log into the cluster database.
CODEarn:aws:redshift:<region>:<account-id>:dbuser:<cluster-name>/<dbuser-name> -
Additionally, you will need the ARN for the given database you wish to scan in the format:
CODEarn:aws:redshift:<region>:<account-id>:dbname:<cluster-name>/<database-name>
Create Policy
-
In the Amazon Redshift console, navigate to IAM > Policies > Create Policy.
-
Use the following JSON and provide your respective account values:
Note:DescribeCluster is also needed for scan process but this doesn't allow to have a different resource than "*"
JSON{ "Version": "2012-10-17", "Statement": [ { "Sid": "VisualEditor0", "Effect": "Allow", "Action": [ "redshift:GetClusterCredentials", "redshift:CreateClusterUser" ], "Resource": [ "arn:aws:redshift:<region>:<account-id>:dbuser:<cluster-name>/ot-service", "arn:aws:redshift:<region>:<account-id>:dbname:<cluster-name>/<database-name>" ] }, { "Sid": "VisualEditor1", "Effect": "Allow", "Action": "redshift:DescribeClusters", "Resource": "*" } ] } -
Select the cluster where your OneTrust
Attach Policy to Role
-
In the Amazon Elastic Kubernetes Service console, navigate to Clusters.
-
Select the cluster where your OneTrust worker node is deployed.
-
Go to the Compute tab to select the cluster's Node Groups.
-
In this Node Group details screen, go to the Details section to select the Node IAM Role ARN. You will be redirected to the IAM role page.
-
Click the Add Permissions button, then select Attach Policies.
-
Attach the policy you created in previous section. This worker node is now ready to scan the database.
OneTrust Vault Configuration
-
Navigate to the Redshift Vault Entry for your credential JSON.
-
Add the following JSON and update
cluster-name,region, anddatabase-namewith the values for your account.Note:The
AutoCreate=Trueproperty is required for the java JDBC to be able to create the temporary credentials.JSON{ "connectionUrl": "jdbc:redshift:iam://<cluster-name>:<region>/<database-name>?AutoCreate=true" }
Redshift Configuration
-
In the OneTrust application, run a catalog scan in the Data Discovery module. This will create the user "IAM:ot-service" on the Redshift database.
-
In the Amazon Redshift console, navigate to Clusters.
-
Select the cluster to which you are connecting.
-
Click the Query data button, then select Query in query editor.
-
Confirm the user was created using:
CODESELECT * FROM pg_user WHERE usename='IAM:ot-service'; -
Run the following command. Replace
schema-namewith the one you wish to scan. This will need to be performed for each schema on which you want to perform a catalog scan.CODEGRANT ALL ON ALL TABLES IN SCHEMA <schema_name> to "IAM:ot-service";
Troubleshooting
Resource Error
This error may show if the resource for DescribeClusters is different to a wildcard ("*")
2023-01-11 03:07:58.228 ERROR --- [ rdbms1-P-1] c.o.d.s.c.e.DataDiscoveryExceptionWrapper jobId=93b335b5-bd04-4a50-84b8-667e8512766d : Source:RDBMS Scanner ErrorCode:Connection Error SQL error code:0 state:99999 Exception:
java.sql.SQLException: IAM error retrieving temp credentials: User: arn:aws:sts::295935724398:assumed-role/autobots-nodegroup-role/i-078199dfa3cf998fc is not authorized to perform: redshift:DescribeClusters on resource: arn:aws:redshift:us-east-1:295935724398:cluster:redshift-cluster-dev because no identity-based policy allows the redshift:DescribeClusters action (Service: AmazonRedshift; Status Code: 403; Error Code: AccessDenied; Request ID: b74b28b0-281d-4112-b900-426c5df99cc1; Proxy: null)
Auth Error #1
Shows up when the dbuser ARN has an error for the redshift:CreateClusterUser permission
2023-01-11 15:42:19.350 ERROR --- [ rdbms1-P-1] c.o.d.s.c.e.DataDiscoveryExceptionWrapper jobId=c0a67d16-1fea-427e-a23c-dd9485b9d180 : Source:RDBMS Scanner ErrorCode:Connection Error SQL error code:0 state:99999 Exception:
java.sql.SQLException: IAM error retrieving temp credentials: User: arn:aws:sts::295935724398:assumed-role/autobots-nodegroup-role/i-078199dfa3cf998fc is not authorized to perform: redshift:CreateClusterUser on resource: arn:aws:redshift:us-east-1:295935724398:dbuser:redshift-cluster-dev/ot-service because no identity-based policy allows the redshift:CreateClusterUser action (Service: AmazonRedshift; Status Code: 403; Error Code: AccessDenied; Request ID: 16f5f316-5d9f-44c5-92fe-7f6f8c719e96; Proxy: null)
Auth Error #2
Similar to error #1, this appears when the ARN has an error resulting from the redshift:GetClusterCredentials permission.
2023-01-11 15:37:33.893 ERROR --- [ rdbms1-P-1] c.o.d.s.c.e.DataDiscoveryExceptionWrapper jobId=d9315883-1ab6-4dc6-b7d6-0a30cfe2ca09 : Source:RDBMS Scanner ErrorCode:Connection Error SQL error code:0 state:99999 Exception:
java.sql.SQLException: IAM error retrieving temp credentials: User: arn:aws:sts::295935724398:assumed-role/autobots-nodegroup-role/i-078199dfa3cf998fc is not authorized to perform: redshift:GetClusterCredentials on resource: arn:aws:redshift:us-east-1:295935724398:dbname:redshift-cluster-dev/test because no identity-based policy allows the redshift:GetClusterCredentials action (Service: AmazonRedshift; Status Code: 403; Error Code: AccessDenied; Request ID: 8a78880a-ec8c-4ac9-823d-394c2cd79c81; Proxy: null)
Connection URL Error
Usually because the connection URL has a syntax error.
2023-01-11 13:54:47.750 ERROR 78733 --- [ rdbms1-P-1] .o.d.s.c.e.DataDiscoveryExceptionWrapper : Source:RDBMS Scanner ErrorCode:Connection Error SQL error code:0 state:08001 Exception:
java.sql.SQLException: Cannot determine dialect. Please check the 'connectionUrl' property in credentials.
User Error
AutoCreate=true property is missing from the connection URL.
2023-01-11 13:57:00.732 ERROR 78861 --- [ rdbms1-P-1] c.o.d.s.r.c.s.p.ScanJobEventProcessor : JobId: 1 Failed processing. Code:[Connection Error] Source:[RDBMS Scanner] Message:[SQLException: FATAL: user "IAM:erikaalmeida" does not exist] Arguments:[[Dialect: redshift]] Date:[2023-01-11T16:57]
java.util.concurrent.CompletionException: com.onetrust.discovery.scanner.common.exceptions.DataDiscoveryException: SQLException: FATAL: user "IAM:erikaalmeida" does not exist