Skip to content

Commit 18f66c4

Browse files
vlademVlad Volodkin
andauthored
Enable credentials caching with --profile flag (#1398)
Add a caching layer to the profile credentials provider, enabled by `--profile` flag. This change should provide a fix/mitigation for #1358. ### Does this change impact existing behavior? Yes, credentials will be cached for up to 15 minutes, when `--profile` flag is used. ### Does this change need a changelog entry? Does it require a version change? Yes, added. Version `1.17.0` is the correct one for this change. --- By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and I agree to the terms of the [Developer Certificate of Origin (DCO)](https://developercertificate.org/). --------- Signed-off-by: Vlad Volodkin <[email protected]> Co-authored-by: Vlad Volodkin <[email protected]>
1 parent 764f431 commit 18f66c4

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

mountpoint-s3-crt/src/auth/credentials.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ use std::fmt::Debug;
44
use std::ptr::NonNull;
55

66
use mountpoint_s3_crt_sys::{
7-
aws_credentials_provider, aws_credentials_provider_acquire, aws_credentials_provider_chain_default_options,
8-
aws_credentials_provider_new_anonymous, aws_credentials_provider_new_chain_default,
7+
aws_credentials_provider, aws_credentials_provider_acquire, aws_credentials_provider_cached_options,
8+
aws_credentials_provider_chain_default_options, aws_credentials_provider_new_anonymous,
9+
aws_credentials_provider_new_cached, aws_credentials_provider_new_chain_default,
910
aws_credentials_provider_new_profile, aws_credentials_provider_new_static,
1011
aws_credentials_provider_profile_options, aws_credentials_provider_release,
1112
aws_credentials_provider_static_options,
@@ -105,14 +106,31 @@ impl CredentialsProvider {
105106

106107
// SAFETY: aws_credentials_provider_new_profile makes a copy of bootstrap
107108
// and contents of profile_name_override.
109+
// SAFETY: aws_credentials_provider_new_cached increments the reference counter of
110+
// profile_provider.
108111
let inner = unsafe {
109112
let inner_options = aws_credentials_provider_profile_options {
110113
bootstrap: options.bootstrap.inner.as_ptr(),
111114
profile_name_override: options.profile_name_override.as_aws_byte_cursor(),
112115
..Default::default()
113116
};
114117

115-
aws_credentials_provider_new_profile(allocator.inner.as_ptr(), &inner_options).ok_or_last_error()?
118+
let profile_provider =
119+
aws_credentials_provider_new_profile(allocator.inner.as_ptr(), &inner_options).ok_or_last_error()?;
120+
121+
let inner_options = aws_credentials_provider_cached_options {
122+
source: profile_provider.as_ptr(),
123+
refresh_time_in_milliseconds: 900_000, // Same as `aws_credentials_provider_new_chain_default`, 15 minutes
124+
..Default::default()
125+
};
126+
127+
let cached_provider =
128+
aws_credentials_provider_new_cached(allocator.inner.as_ptr(), &inner_options).ok_or_last_error()?;
129+
130+
// transfer ownership
131+
aws_credentials_provider_release(profile_provider.as_ptr());
132+
133+
cached_provider
116134
};
117135

118136
Ok(Self { inner })

mountpoint-s3/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
## Unreleased
22

3+
### Other changes
4+
35
* Allow changing log level dynamically with `USR2` signal. See [Changing logging verbosity at runtime](https://github.com/awslabs/mountpoint-s3/blob/main/doc/LOGGING.md#changing-logging-verbosity-at-runtime) for more details. ([#1367](https://github.com/awslabs/mountpoint-s3/pull/1367))
6+
* Enable caching of credentials when `--profile` CLI argument is used. ([#1398](https://github.com/awslabs/mountpoint-s3/pull/1398))
47

58
## v1.16.2 (April 9, 2025)
69

0 commit comments

Comments
 (0)