fix: reload AWS credentials from disk on every RDS IAM token refresh - #438
Merged
Merged
Conversation
The AWS SDK caches the contents of ~/.aws/credentials and ~/.aws/config in a module-level map for the lifetime of the process. DBHub regenerates the RDS IAM auth token every ~14 minutes with a fresh fromIni() call, but that call hits the cache, so credentials rotated externally (e.g. refreshed STS credentials written by a sidecar) were never picked up and auth eventually failed with "PAM authentication failed" until restart. Pass ignoreCache: true to fromIni() and, when no aws_profile is set, to an explicit fromNodeProviderChain() so the default chain's ini step also re-reads the files. Fixes #437 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FyVzpWXWC2fW5FK3PjtNXJ
Contributor
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The implementation matches the stated fix and includes tests for both credential-loading paths.
Review effort: Lite
Findings: None
What changed in this PR
Updates RDS IAM token generation to reload AWS credentials from disk on every refresh, including the default credential chain.
Changes:
- Uses
ignoreCache: truefor profile and no-profile credential providers. - Adds coverage for both provider paths.
| File | Description |
|---|---|
src/utils/aws-rds-signer.ts |
Disables AWS credential caching during token generation. |
src/utils/__tests__/aws-rds-signer.test.ts |
Tests profile and default-chain behavior. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #437. Supersedes #436 by also covering the no-profile path.
Problem
The AWS SDK caches the contents of
~/.aws/credentialsand~/.aws/configin a module-level map for the lifetime of the process (filePromisesin@smithy/core/config, bypassed only byignoreCache). DBHub regenerates the RDS IAM auth token every ~14 minutes with a freshfromIni()call, but each call hits that cache, so credentials rotated externally (e.g. refreshed STS credentials written by a sidecar) are never picked up. Auth eventually fails withPAM authentication failed for user "xxx"until the container is restarted.Fix
generateRdsAuthTokennow always builds an explicit credential provider withignoreCache: true:aws_profileset →fromIni({ profile, ignoreCache: true })fromNodeProviderChain({ ignoreCache: true }), so the default chain's ini step also re-reads the files. Env-var and instance-metadata users are unaffected.Cost is one extra file read per token refresh.
Tests
ignoreCache: trueand that the chain provider is not used.fromNodeProviderChain({ ignoreCache: true })is passed to the signer andfromIniis not called.vitest run src/utils/__tests__/aws-rds-signer.test.ts src/connectors/__tests__/manager.test.ts: 14 passed.pnpm run buildpasses.🤖 Generated with Claude Code
https://claude.ai/code/session_01FyVzpWXWC2fW5FK3PjtNXJ
Generated by Claude Code