Skip to main content

Custom runtimes and WASM

Everything I/O-shaped in Reqsign flows through Context. Replace any slot to run on your own runtime, add instrumentation, sandbox capabilities — or compile to WebAssembly, which is just the strictest custom runtime of all.

The four traits​

TraitMethodUsed for
FileReadfile_read(path) -> Result<Vec<u8>>Config files, key files, token files
HttpSendhttp_send(Request<Bytes>) -> Result<Response<Bytes>>Metadata endpoints, STS/OIDC exchanges
Envvar(key), vars(), home_dir()Environment-based sources, path expansion
CommandExecutecommand_execute(cmd, args) -> Result<Output>CLI-backed sources (e.g. Azure CLI)

(Signatures abbreviated — see docs.rs/reqsign-core for the precise forms; all futures are MaybeSend.)

The ready-made components the facade uses are ordinary implementations of these traits: TokioFileRead, ReqwestHttpSend, TokioCommandExecute, plus OsEnv from reqsign-core. Mix them freely with your own.

Example: an instrumented HTTP sender​

use bytes::Bytes;
use reqsign::{Context, HttpSend, Result};
use reqsign_http_send_reqwest::ReqwestHttpSend;

#[derive(Debug)]
struct TracedHttpSend(ReqwestHttpSend);

impl HttpSend for TracedHttpSend {
async fn http_send(&self, req: http::Request<Bytes>)
-> Result<http::Response<Bytes>>
{
let uri = req.uri().clone();
let started = std::time::Instant::now();
let resp = self.0.http_send(req).await;
log::debug!("credential fetch {} took {:?}", uri, started.elapsed());
resp
}
}

let ctx = Context::new().with_http_send(TracedHttpSend(ReqwestHttpSend::default()));

Slots you do not provide stay as no-op stubs that error when used — a credential source that needs a missing capability fails loudly instead of silently returning nothing. The same pattern gives you test doubles: an Env over a HashMap, an HttpSend over canned responses — see Testing.

WASM​

Reqsign's core and a defined subset of providers compile for wasm32-unknown-unknown — signing from browsers, edge runtimes, and plugin sandboxes. CI verifies this exact set on every commit:

  • reqsign-core, reqsign-aws-core, reqsign-oauth2
  • Providers: AWS SigV4, AWS SigV4a, Azure Storage, GitHub, Aliyun OSS, Aliyun Drive, Backblaze B2, Baidu Netdisk, Cloudflare, Vercel Blob, Vercel Artifacts, Tencent COS, Dropbox, HTTP Message Signatures, Koofr, OneDrive, Upyun, Yandex Disk, Seafile (facade features aws, aws-v4a, azure, github, http-message-signatures, aliyun, aliyun-drive, b2, baidu-netdisk, cloudflare, vercel, tencent, dropbox, koofr, onedrive, oauth2, upyun, yandex-disk, seafile)

GitHub environment, static, and anonymous signing need no JavaScript clock. GitHub CLI discovery requires a CommandExecute adapter and is unavailable in bare WASM runtimes.

Cloudflare and Vercel environment, static, and header signing need no JavaScript clock.

Yandex Disk static credentials without an expiry and header signing need no JavaScript clock; expiring Yandex Disk credentials read it. Baidu Netdisk static query signing also needs no JavaScript clock. Seafile signing also needs no JavaScript clock. Koofr signing needs no JavaScript clock and ignores expires_in. HTTP Message Signatures signing needs a JavaScript clock and therefore a wasm-bindgen host.

These clock notes cover the named paths only and are not an exhaustive inventory: a compile-tested provider not named here may still read the clock on some runtime paths.

The provider matrix marks WASM status per provider; treat providers outside this set as unsupported there until the catalog says otherwise.

The Backblaze B2, Upyun, Yandex Disk, HTTP Message Signatures, OAuth 2.0, Dropbox, Aliyun Drive, and OneDrive crates enable Jiff's js feature for wasm32-unknown-unknown. B2 authorization-token lifetime checks, the Upyun default signer's Date, expiring Yandex Disk credentials, and HTTP Message Signatures signing read the clock from a wasm-bindgen JavaScript host such as a browser or Node. A bare WASM runtime without a JavaScript clock can compile the crates but is not a supported runtime for those paths; calling Timestamp::now traps there. CI exercises the public B2 signing, Upyun default-clock signing, expiring Yandex Disk signing, HTTP Message Signatures HMAC signing, Dropbox signing, OAuth2 mock-refresh, Aliyun Drive static and refresh, and OneDrive signing and refresh paths under wasm-bindgen-test in Node.

rustup target add wasm32-unknown-unknown
cargo build --target wasm32-unknown-unknown \
--no-default-features --features aws,azure

Two mechanics keep the crate WASM-clean: no direct filesystem, environment, or process access anywhere outside Context implementations, and trait futures that are MaybeSend — Send on native targets, relaxed on WASM.

Providing a browser runtime​

There is no filesystem and no OS environment in a browser, so provide what your credential sources actually need — usually just HTTP:

use bytes::Bytes;
use reqsign::{Context, HttpSend, Result, Signer};
use reqsign::aws::{RequestSigner, StaticCredentialProvider};

#[derive(Debug)]
struct FetchHttpSend; // wraps fetch() via wasm-bindgen

impl HttpSend for FetchHttpSend {
async fn http_send(&self, req: http::Request<Bytes>)
-> Result<http::Response<Bytes>>
{
todo!("drive the request through fetch()")
}
}

let ctx = Context::new().with_http_send(FetchHttpSend);
let signer = Signer::new(
ctx,
StaticCredentialProvider::new("AKIDEXAMPLE", "example-secret-key"),
RequestSigner::new("s3", "us-east-1"),
);

Static or externally-injected credentials are the norm on WASM — chains that read files or metadata endpoints have nothing to read in a browser.

Credentials in browsers

Anything delivered to a browser is readable by its user. Prefer granted, downscoped credentials or short-lived tokens minted by your backend over long-lived keys.