Skip to content

feat: sso auth cache refresh#1188

Open
soisyourface wants to merge 9 commits intoex-aws:mainfrom
soisyourface:feat/sso_auth_cache_refresh
Open

feat: sso auth cache refresh#1188
soisyourface wants to merge 9 commits intoex-aws:mainfrom
soisyourface:feat/sso_auth_cache_refresh

Conversation

@soisyourface
Copy link

This builds on top of a solution proposed in #1100.
This adds writing out the updated credentials to the sso cache as well as a preemptive credential refresh to the auth cache genserver.

I used this locally to tun a long running(multiple hours) script against AWS with SSO credentials.

@soisyourface
Copy link
Author

Any thoughts on this?

@soisyourface
Copy link
Author

soisyourface commented Feb 3, 2026

Are all maintainers just crazy busy(which is, of course, fine) or is there another way to get this PR looked at? Did I miss something?
Link to #1100

@bernardd
Copy link
Contributor

"The maintainers" is me :) And yeah, Christmas break then the usual rush of work because the other half of the world didn't have as much of a break as me, and etc etc :)
I try to catch up on PRs etc and crank out a new version every 2-3 months at the longest. I'll get to this as soon as I can which should be in the next week or so. Thanks for the contribution :)

@soisyourface
Copy link
Author

oh, thanks @bernardd. didn't know you were all by your lonesome.
let me know how i can help ease your burden here. we very much enjoy ex_aws and use it heavily.

The SSO credentials API returns the `expiration` field as an integer in milliseconds. However, the `next_refresh_in` calculation assumed all integer expiration values were in seconds (similar to the output of `DateTime.to_unix/1`). This led to a massive calculation for the `send_after` delay value resulting in a GenServer crash with `ArgumentError: exceeds the maximum supported time value`.

This fix adjusts `next_refresh_in/1` to automatically detect and convert millisecond timestamps to seconds.
Instead of checking for a millisecond timestamp inside the AuthCache module, we now normalize the timestamp as soon as it's parsed from the AWS SSO API JSON payload. This is a cleaner 'anti-corruption layer' pattern that ensures all cache logic consistently interacts with timestamps in seconds.

Also added a dedicated test using a simulated JSON payload based on the official AWS SSO GetRoleCredentials API documentation to prevent regressions.
# AWS SSO returns expiration as an integer in milliseconds,
# but ex_aws auth cache expects it in seconds.
expiration_sec =
if is_integer(expiration) and expiration > 99_999_999_999 do
Copy link
Author

Choose a reason for hiding this comment

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

this makes me sad, and i'm hoping someone has a better solution.

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.

2 participants