Cloud Service Authentication in OpenDAL#
OpenDAL authenticates cloud storage requests by delegating to the reqsign crate. Each backend holds a signer and one or more credential loaders that implement provider-specific signing algorithms. Before every outbound request, the backend calls its sign() or sign_query() method which (1) loads a credential, (2) mutates the request headers or query string, and (3) forwards the signed request.
The pattern is uniform across providers: build credentials β sign request β strip any headers the provider rejects (e.g., the HOST header on GCS ).
Provider Overview#
| Backend | Credential type | Loader | Signer | Anonymous support |
|---|---|---|---|---|
| S3 | AwsCredential | AwsCredentialLoad (trait) | AwsV4Signer | Optional |
| GCS | GoogleToken / GoogleCredential | GoogleTokenLoader / GoogleCredentialLoader | GoogleSigner | Optional |
| Azure Blob | AzureStorageCredential | AzureStorageLoader | AzureStorageSigner | No |
Google Cloud Storage (GCS)#
GcsCore carries two separate loaders because GCS uses different credentials for different operations :
GoogleTokenLoaderβ fetches OAuth2 access tokens for standard JSON-API requests (async, with exponential-backoff retry).GoogleCredentialLoaderβ loads raw service-account credentials for presigned URL generation via the XML API (sync).
load_token(): If a static token string was configured, wraps it directly as a GoogleToken. Otherwise calls token_loader.load() with retry. Returns None only when allow_anonymous is set; otherwise returns a ConfigInvalid error.
sign(): Calls load_token() β signer.sign(req, &token). Used for all normal API calls.
sign_query(): Calls load_credential() β signer.sign_query(req, duration, &cred). Used only for presigned (query-signed) URLs via the XML API.
Configuration Options#
Configured through GcsConfig / GcsBuilder:
| Field | Purpose |
|---|---|
token | Static OAuth2 token; takes precedence over all other credential sources |
credential | Base64-encoded service-account JSON |
credential_path | Path to a service-account JSON file |
service_account | Service account name for GCE VM metadata server token fetch |
scope | OAuth2 scope (default: devstorage.read_write) |
allow_anonymous | Permit unsigned requests (public buckets, emulators) |
disable_vm_metadata | Skip the GCE metadata server |
disable_config_load | Skip environment/well-known-file loading |
The builder assembles a GoogleCredentialLoader from content/path first, then wraps it in a GoogleTokenLoader with scope and service-account settings .
AWS S3#
S3Core stores a boxed AwsCredentialLoad trait object, enabling any custom credential loader to be injected . An AtomicBool (credential_loaded) tracks whether credentials were successfully fetched at least once; subsequent failures are treated as errors rather than silent anonymous fallbacks .
The builder wires up the loader chain in backend.rs :
- Custom loader β any type implementing
AwsCredentialLoad, injected viacustomized_credential_load(). - Assume-role β
AwsAssumeRoleLoaderwith optional external ID, backed by STS. - Default loader β
AwsDefaultLoader, sourcing credentials from environment variables,~/.aws/credentials, or EC2 instance metadata (which can be disabled).
Signing uses AWS Signature Version 4 via AwsV4Signer .
Azure Blob Storage#
AzblobCore holds AzureStorageLoader and AzureStorageSigner . Credentials are mandatory β load_credential() returns an error if nothing is found .
Supported credential types, configured via AzureStorageConfig :
- Account key β HMAC-SHA256 shared-key authentication.
- SAS token β pre-signed token passed as a query parameter.
- Environment variables are the primary source; the loader is created with
AzureStorageLoader::new(config_loader).
sign() prepends the required x-ms-version: 2022-11-02 header before delegating to the signer .
Key Entry Points for Deeper Investigation#
| File | What to look at |
|---|---|
core/src/services/gcs/core.rs | GCS load_token, sign, sign_query |
core/src/services/gcs/backend.rs | GCS credential/token loader construction |
core/src/services/gcs/config.rs | GcsConfig auth fields |
core/src/services/s3/core.rs | S3 load_credential, sign |
core/src/services/s3/backend.rs | S3 loader chain assembly |
core/src/services/azblob/core.rs | Azure load_credential, sign |
core/src/services/azblob/backend.rs | Azure config & loader setup |