redshift-iam
A Rust library for authenticating to Amazon Redshift using SAML-based single sign-on (SSO) or IAM temporary credentials. Inspired by the Amazon Redshift Python driver.
Overview
The authentication flow has three stages:
- SAML assertion —
PingCredentialsProviderlogs in to a PingFederate IdP and retrieves a SAML assertion. This step is optional. - IAM credentials — The assertion is exchanged for temporary AWS credentials via STS
AssumeRoleWithSAML. - Redshift credentials — The temporary AWS credentials are used to call
GetClusterCredentials, obtaining a short-lived Redshift username/password. - Query —
Redshiftconnects using those credentials and executes queries, returning ArrowRecordBatches.
The query execution is only enabled if you include read_sql feature. Otherwise, you can get the connection_string and execute queries via other crates.
Usage
use HashMap;
use SecretString;
use *;
let password = new;
// 1. Obtain a SAML assertion from PingFederate and exchange it for AWS credentials
let ping_provider = new;
let aws_credentials = ping_provider
.get_credentials
.unwrap;
// 2. Exchange AWS credentials for Redshift cluster credentials
let = new
// .set_region("eu-west-1") // optional, default: us-east-1
.auth;
// 3. Connect and query
let conn = new;
let batches = conn.execute.unwrap;
API
PingCredentialsProvider
Authenticates against a PingFederate IdP and retrieves temporary AWS credentials via SAML.
new
| Method | Description |
|---|---|
get_credentials(role_arn) |
Full sync flow: SAML -> STS -> returns sts::types::Credentials |
user() |
Returns the configured username |
do_verify_ssl_cert() |
Returns true unless ssl_insecure is set |
ssl_insecure: bool (pub field) |
Set to true to skip TLS verification |
IamProvider
Exchanges temporary AWS credentials for Redshift cluster credentials.
new
| Method | Description |
|---|---|
auth(aws_credentials) |
Calls GetClusterCredentials, returns (username, password) |
set_region(region) |
Builder method to set the AWS region (default: us-east-1) |
region() |
Returns the configured region |
Redshift
Executes SQL queries against a Redshift cluster, returning Arrow RecordBatches.
new
| Method | Description |
|---|---|
execute(query) |
Runs the query and returns Vec<RecordBatch> |
connection_string() |
Returns the URL-encoded connection string as a SecretString |
Port defaults to 5439 if None is passed.
Custom SAML providers
You are not limited to PingFederate. Any type that implements the SamlProvider trait can be
passed directly to the async get_credentials free function:
use ;
let aws_credentials = get_credentials
.await
.unwrap;
The SamlProvider trait requires:
| Item | Description |
|---|---|
async fn get_saml_assertion(&self) -> String |
Returns the base64-encoded SAML assertion |
The live integration test (cargo test test_live_connection -- --ignored) reads credentials from the environment:
| Variable | Description |
|---|---|
IDP_HOST |
PingFederate hostname |
USER |
Redshift / IdP username |
PWD |
Password |
ROLE_ARN |
IAM role ARN to assume |
CLUSTER |
Redshift cluster identifier |
HOST |
Redshift cluster hostname |
DATABASE |
Database name |
Running tests
# Unit and mock-based tests only
# Include the live integration test (requires env vars above)
HOST=... DATABASE=... USER=... PWD=... CLUSTER=... ROLE_ARN=... IDP_HOST=... \