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
Requirements
- Rust 1.85+ (edition 2024)
Installation
Add to your Cargo.toml:
[]
= "0.1"
# For async usage, add a tokio runtime:
= { = "1", = ["rt-multi-thread", "macros"] }
To use the synchronous (blocking) client:
[]
= { = "0.1", = ["blocking"] }
Quick Start
Async (default)
use ;
async
Blocking (sync)
use Client;
use ;
Credential Resolution
The SDK supports three ways to provide credentials, and a chain provider that tries them in order.
1. Explicit credential
let client = new;
2. Environment variables
let client = from_env?;
3. Profile file
Create ~/.alibabacloud/credentials:
[default]
access_key_id = LTAI5t...
access_key_secret = your-secret
Client::from_env() automatically tries the default credential chain: Environment variables -> Profile file.
API Reference
AssumeRole
Obtain temporary credentials by assuming a RAM role.
let resp = client.assume_role.await?;
// resp.credentials.access_key_id
// resp.credentials.access_key_secret
// resp.credentials.security_token
// resp.credentials.expiration
// resp.assumed_role_user.arn
// resp.assumed_role_user.assumed_role_id
AssumeRoleWithSAML
Assume a role using a SAML assertion for enterprise SSO.
let resp = client.assume_role_with_saml.await?;
AssumeRoleWithOIDC
Assume a role using an OIDC token for SSO.
let resp = client.assume_role_with_oidc.await?;
GetCallerIdentity
Query the identity of the current caller (no additional parameters needed).
let resp = client.get_caller_identity.await?;
println!;
println!;
println!;
Custom Configuration
use Duration;
use ;
let config = default
.with_endpoint
.with_timeout;
let client = with_config;
Error Handling
All operations return rs_ali_sts::Result<T>, which wraps StsError:
use StsError;
match client.assume_role.await
| Variant | Description |
|---|---|
HttpClient |
Network / connection error (from reqwest) |
Http |
Unexpected HTTP response with non-JSON body |
Api |
Alibaba Cloud API business error (includes request_id, code, message) |
Credential |
Credential resolution failure |
Deserialize |
JSON deserialization error |
Signature |
Signature computation error |
Config |
Configuration / profile file parse error |
Security
- Credentials are redacted in
Debugoutput —access_key_secretandsecurity_tokenare printed as**** - Uses HTTPS POST to send requests — credentials never appear in URLs
- Uses rustls for TLS — pure Rust, no OpenSSL dependency
- Each request uses a UUID v4 nonce to prevent replay attacks
License
Licensed under the MIT License.