Skip to content

Refresh expired token in AuthClient calls - #126

Merged
belltoy merged 1 commit into
masterfrom
fix/auth-client-token-refresh
Oct 19, 2026
Merged

belltoy merged 1 commit into
masterfrom
fix/auth-client-token-refresh

Conversation

@belltoy

@belltoy belltoy commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

Summary

AuthClient called the tonic stub directly, so it skipped the token refresh every other client gets from ClientCaller::do_call. It could not use ClientCaller because ClientCaller held an AuthClient to authenticate. ClientCaller now authenticates with the raw stub, which breaks the cycle.

 ClientCaller
-  auth_client: AuthClient            // needed to refresh the token
+  auth_client: RawAuthClient         // plain tonic stub, no refresh

 AuthClient
-  inner: PbAuthClient
+  inner: ClientCaller<PbAuthClient>
   auth_enable / auth_disable / role_* / user_*
-    self.inner.xxx(req)
+    self.inner.do_call(req, xxx_impl)    // refreshes an expired token
   authenticate
     self.inner.inner_mut().authenticate(..)  // stays raw: it is how a token is obtained

Evidence

  • Before: with with_auto_token_refresh(true), user_list() after the token expired (etcd 3.7.2, ETCD_AUTH_TOKEN_TTL=2):
    test_auth_refresh_token FAILED
    Error: GRpcStatus(Status { code: Unauthenticated, message: "etcdserver: invalid auth token", .. })
    
    After: test_auth_refresh_token passes. It now also calls user_list() and auth_client().role_list() after the token expired. cargo test and cargo clippy --all-targets -D warnings pass locally on 3.7.2.

Merge Danger

Door: two-way

Blast Radius: AuthClient

AuthClient::new now takes a ClientCallerBuilder. It is pub(crate), so there is no public API change. Auth calls only retry when with_auto_token_refresh(true) is set and credentials exist, same as the other clients. Not tested on etcd 3.5 / 3.6 or a multi-node cluster; CI covers those.

🤖 Generated with Claude Code

AuthClient called the tonic stub directly, so with auto token refresh
enabled an expired token still failed role_*/user_*/auth_enable/
auth_disable with Unauthenticated, unlike every other client.

ClientCaller used an AuthClient to authenticate, which made it
impossible for AuthClient to use a ClientCaller. Make ClientCaller
authenticate with the raw auth stub instead, and route every AuthClient
method except authenticate through do_call. authenticate stays raw since
it is the call that obtains a token.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@belltoy
belltoy merged commit 0863cc9 into master Oct 19, 2026
28 checks passed
@belltoy
belltoy deleted the fix/auth-client-token-refresh branch October 19, 2026 11:41
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