Skip to content

Make auth_refresh_lead_time configurable#1216

Open
rslota wants to merge 1 commit intoex-aws:mainfrom
v7labs:configurable-auth-refresh-lead-time
Open

Make auth_refresh_lead_time configurable#1216
rslota wants to merge 1 commit intoex-aws:mainfrom
v7labs:configurable-auth-refresh-lead-time

Conversation

@rslota
Copy link
Copy Markdown
Contributor

@rslota rslota commented Mar 20, 2026

Summary

The @refresh_lead_time in AuthCache controls how far in advance of credential expiry a refresh is triggered. The hardcoded value of 300,000ms (5 min) means presigned URLs signed with temporary credentials (instance role / ECS task role) can have as little as ~5 minutes of effective validity — AWS rejects requests once the embedded X-Amz-Security-Token expires, regardless of X-Amz-Expires.

This makes the lead time configurable via application env:

config :ex_aws, auth_refresh_lead_time: 7_500_000  # 2h 5min

Defaults to 300_000 (5 min), preserving existing behaviour.

Motivation

When generating presigned S3 URLs that must remain valid for hours (e.g. upload URLs for long-running sessions), the 5-minute refresh window means a URL signed just before credential refresh becomes invalid almost immediately. By allowing consumers to increase the lead time, credentials are refreshed early enough to guarantee sufficient remaining validity on the security token.

Changes

  • lib/ex_aws/config/auth_cache.ex: Replace hardcoded @refresh_lead_time with Application.compile_env(:ex_aws, :auth_refresh_lead_time, 300_000)

No other files changed. No behaviour change for existing users.

The `@refresh_lead_time` in AuthCache controls how far in advance of
credential expiry a refresh is triggered. The previous hardcoded value
of 300_000ms (5 min) means presigned URLs signed with temporary
credentials could have as little as ~5 minutes of effective validity,
since AWS rejects requests when the embedded security token expires
regardless of X-Amz-Expires.

This makes the lead time configurable via:

    config :ex_aws, auth_refresh_lead_time: 7_500_000  # 2h 5min

allowing consumers that generate long-lived presigned URLs to ensure
credentials are always refreshed early enough.

Defaults to 300_000ms (5 min), preserving existing behaviour.
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