Skip to content

Add dynamic credentials providers for cloud IAM support#126

Open
richardhenry wants to merge 2 commits intodahomey-technologies:mainfrom
richardhenry:dynamic-auth-providers
Open

Add dynamic credentials providers for cloud IAM support#126
richardhenry wants to merge 2 commits intodahomey-technologies:mainfrom
richardhenry:dynamic-auth-providers

Conversation

@richardhenry
Copy link
Copy Markdown
Contributor

@richardhenry richardhenry commented Mar 7, 2026

This PR adds the ability to provide credentials dynamically which is useful for cloud IAM authentication where the token/password expires. Otherwise rustis will attempt to reconnect using expired credentials.

Here's an example of how this works:

use rustis::{
    client::{Client, Credentials, CredentialsContext, WithCredentialsProvider},
    commands::ConnectionCommands,
    Result,
};

async fn fetch_iam_token(_ctx: &CredentialsContext) -> Result<String> {
    todo!("Call your cloud SDK or metadata service here")
}

#[tokio::main]
async fn main() -> Result<()> {
    let client = Client::connect(
        "rediss://cache.example.com:6379".with_credentials_provider(|ctx| async move {
            let token = fetch_iam_token(&ctx).await?;
            Ok(Credentials::for_default_user(token))
        }),
    )
    .await?;

    let _: String = client.ping("hello").await?;
    Ok(())
}

Intended to be compatible with sentinel, pooling, and backwards compatible (only additions to existing API).

Includes tests (green) and docs.

I was originally patching around this in my application, but it made things a lot more complicated. Implementing this at the library level is a lot less code than at the application level (and can be well tested, etc).

Responsible AI usage: Codex helped me make some of these changes and write the docs, but I carefully reviewed everything and am using this fork already in my running app.

@richardhenry richardhenry changed the title Add dynamic credentials providers for reconnects Add dynamic credentials providers for cloud IAM support Mar 7, 2026
@richardhenry richardhenry marked this pull request as ready for review March 20, 2026 01:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant