Skip to content

fix: reload AWS credentials from disk on every RDS IAM token refresh - #438

Merged
tianzhou merged 1 commit into
mainfrom
claude/exciting-heisenberg-rqtyq4
Sep 21, 2026
Merged

tianzhou merged 1 commit into
mainfrom
claude/exciting-heisenberg-rqtyq4

Conversation

@tianzhou

Copy link
Copy Markdown
Member

Fixes #437. Supersedes #436 by also covering the no-profile path.

Problem

The AWS SDK caches the contents of ~/.aws/credentials and ~/.aws/config in a module-level map for the lifetime of the process (filePromises in @smithy/core/config, bypassed only by ignoreCache). DBHub regenerates the RDS IAM auth token every ~14 minutes with a fresh fromIni() 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 with PAM authentication failed for user "xxx" until the container is restarted.

Fix

generateRdsAuthToken now always builds an explicit credential provider with ignoreCache: true:

  • aws_profile set → fromIni({ profile, ignoreCache: true })
  • no profile → 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

  • Updated the profile test to assert ignoreCache: true and that the chain provider is not used.
  • Added a no-profile test asserting fromNodeProviderChain({ ignoreCache: true }) is passed to the signer and fromIni is not called.
  • vitest run src/utils/__tests__/aws-rds-signer.test.ts src/connectors/__tests__/manager.test.ts: 14 passed. pnpm run build passes.

🤖 Generated with Claude Code

https://claude.ai/code/session_01FyVzpWXWC2fW5FK3PjtNXJ


Generated by Claude Code

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
Copilot AI lite review requested due to automatic review settings September 21, 2026 07:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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: true for 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.

@tianzhou
tianzhou merged commit ca14e7a into main Sep 21, 2026
3 checks passed
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.

AWS IAM authentication fails after credentials are rotated

2 participants