rs-ali-sts
Alibaba Cloud STS (Security Token Service) SDK for Rust.
Provides both async and sync (blocking) clients covering all 4 STS API operations:
assume_role— Assume a RAM role to obtain temporary security credentialsassume_role_with_saml— SAML-based SSO role assumptionassume_role_with_oidc— OIDC-based SSO role assumptionget_caller_identity— Query the identity of the current caller
Features
- Async and Blocking — Choose between async (
Client) or sync (blocking::Client) - Builder Pattern — Ergonomic request construction with
try_build()for fallible builds - Credential Chain — Automatic credential resolution from environment or profile files
- Clock Skew Correction — Automatic adjustment for local clock drift
- Concurrent Request Limiting — Built-in semaphore for async client
- Security First — Credentials redacted in debug output, HTTPS POST, rustls TLS
Requirements
- Rust 1.93+ (edition 2024)
Installation
Add to your Cargo.toml:
[]
= "0.1.2"
# For async usage, add a tokio runtime:
= { = "1", = ["rt-multi-thread", "macros"] }
To use the synchronous (blocking) client:
[]
= { = "0.1", = ["blocking"] }
Quick Start
Async (recommended)
use ;
async
Blocking (sync)
use Client;
use ;
Credential Resolution
The SDK supports multiple ways to provide credentials. Client::from_env() tries them in order:
1. Explicit credential
let client = new?;
2. Environment variables
let client = from_env?; // Reads from environment
3. Profile file (~/.alibabacloud/credentials)
[default]
access_key_id = LTAI5t...
access_key_secret = your-secret
[production]
access_key_id = LTAI5tprod...
access_key_secret = prod-secret
// Uses default chain: Environment -> Profile (default)
let client = from_env?;
Builder Pattern
All request types support the builder pattern with two build methods:
// build() - panics if required fields are missing
let request = builder
.role_arn
.role_session_name
.build;
// try_build() - returns Result, useful for dynamic input
let request = builder
.role_arn
.role_session_name
.try_build?; // Returns Err if fields are missing
API Reference
AssumeRole
let request = builder
.role_arn
.role_session_name
.policy // Optional
.duration_seconds // Optional: 900-43200
.external_id // Optional: cross-account
.build;
let resp = client.assume_role.await?;
// resp.credentials.access_key_id
// resp.credentials.access_key_secret
// resp.credentials.security_token
// resp.credentials.expiration
AssumeRoleWithSAML
let request = builder
.saml_provider_arn
.role_arn
.saml_assertion
.build;
let resp = client.assume_role_with_saml.await?;
AssumeRoleWithOIDC
let request = builder
.oidc_provider_arn
.role_arn
.oidc_token
.role_session_name // Optional
.build;
let resp = client.assume_role_with_oidc.await?;
GetCallerIdentity
let resp = client.get_caller_identity.await?;
println!;
println!;
Configuration
use Duration;
use ;
let config = default
.with_endpoint // VPC endpoint
.with_timeout
.with_connect_timeout
.with_max_concurrent_requests
.with_signature_version;
let client = with_config?;
Error Handling
use StsError;
match client.assume_role.await
| Error Variant | Description |
|---|---|
HttpClient |
Network/connection error |
Http |
Non-JSON HTTP response |
Api |
Alibaba Cloud API error (with request_id, code) |
Validation |
Request validation error |
Credential |
Credential resolution failure |
Signature |
Signature computation error |
Config |
Configuration error |
Security Features
| Feature | Description |
|---|---|
| Credential Redaction | access_key_secret and security_token shown as **** in debug output |
| HTTPS POST | Credentials never appear in URLs |
| rustls TLS | Pure Rust TLS, no OpenSSL dependency |
| UUID v4 Nonce | Prevents replay attacks |
| HMAC-SHA1 | Signature algorithm (compatible with Alibaba Cloud STS) |
| File Permission Check | Warns on insecure credential file permissions (Unix) |
License
Licensed under the MIT License.