Skip to content

feat: reload profile credentials when the shared credentials file changes - #6

Merged
quannhoang merged 1 commit into
masterfrom
feat/shared-credentials-rotation
Aug 10, 2026
Merged

feat: reload profile credentials when the shared credentials file changes#6
quannhoang merged 1 commit into
masterfrom
feat/shared-credentials-rotation

Conversation

@locle2302

Copy link
Copy Markdown
Collaborator

Problem

A mount started with --profile resolved its credentials once, at mount time, and kept them for the life of the process. When an external rotator rewrote ~/.aws/credentials and deactivated the old key, every read and write on the mount failed with 403 until goofys was restarted.

What changed

Profile mounts now go through sharedFileProvider, a credentials provider that watches the shared credentials file and re-resolves the profile when it changes.

  • Change detection compares size and mtime, sampled at most once every 10 seconds, and the fingerprint is captured before the file is read so a rotation landing mid-read is not mistaken for the version that was loaded.
  • Resolution runs through session.NewSessionWithOptions with shared config enabled, so role_arn, source_profile, credential_process and SSO profiles keep their full chain instead of being pinned to the raw static keys in ~/.aws/credentials. Expiry of any STS or SSO credentials underneath is honoured as well.
  • A failed reload (for example the rotator has the file truncated at that moment) keeps the previously loaded credentials and logs the failure instead of surfacing an I/O error on the mount. An unreadable or removed credentials file likewise keeps the credentials already in use, logged once.
  • Credentials are always returned for a profile mount, so a mount can no longer fall through to the process global s3Session that an earlier mount may have built for a different profile.

Mounts that pass explicit keys, that set RoleArn, or that rely on AWS_PROFILE / the implicit default profile are unchanged.

Testing

go test ./api/common/ passes. New coverage: rotation picked up through Get() without an explicit Expire(), a rotation that preserves the file's timestamp, a failed reload keeping the last known good credentials, a profile declared only in ~/.aws/config, and an unknown profile. The tests pin AWS_SHARED_CREDENTIALS_FILE, AWS_CONFIG_FILE, IMDS and ECS credential env vars, and save/restore the s3Session global so they stay hermetic and order independent.

…nges

A mount started with --profile resolved its credentials once, at mount
time, and kept them for the life of the process. When an external rotator
rewrote ~/.aws/credentials and deactivated the old key, every read and
write on the mount started failing with 403 until goofys was restarted.

Profile mounts now go through a credentials provider that watches the
shared credentials file (size and mtime, sampled at most once every 10
seconds off the signing path's fast path) and re-resolves the profile
whenever it changes. Resolution runs through a session with shared config
enabled, so role_arn, source_profile, credential_process and SSO profiles
keep their full chain instead of being pinned to the raw static keys, and
the expiry of any STS or SSO credentials underneath is honoured as well.

If a reload fails, for instance because the rotator has the file
truncated at that moment, the previously loaded credentials are kept and
the failure is logged rather than surfaced as an I/O error on the mount.
@locle2302 locle2302 self-assigned this Aug 10, 2026
@locle2302
locle2302 requested a review from giraffesyo August 10, 2026 15:19
@locle2302
locle2302 requested a review from ndminhvn August 10, 2026 15:53
@quannhoang
quannhoang merged commit ae35b70 into master Aug 10, 2026
1 check passed
@quannhoang
quannhoang deleted the feat/shared-credentials-rotation branch August 10, 2026 15:54
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.

3 participants