Skip to content

AWS Credentials Auto Refresh before expire from Spring boot

0

We have configured MSK Provisioned Cluster. I have done authentication from on-prem with Spring boot OAUTHBEARER with awsProfile. in jaas config

sasl.jaas.config = org.apache.kafka.common.security.oauthbearer.OAuthBearerLoginModule required awsProfileName="kafka-msk"; sasl.mechanism = OAUTHBEARER security.protocol= SASL_SSL sasl.login.callback.handler.class= software.amazon.msk.auth.iam.IAMOAuthBearerLoginCallbackHandler

And I am able to publish message successfully but, problem is after 1 hour Profile credentials (in credentials file) like Access Key, Access Secret were expired and can not able to publish messages.

How to refresh credentials automatically before expiring or do we need to get new credentials every messages publishing. Please help me how to auto refresh or any alternative solution.

2 Answers
5

How about using a Refreshable Credentials Provider, the AWS SDK for Java supports auto-refreshing credentials if you use a provider that supports it. However, the ProfileCredentialsProvider does not auto-refresh credentials if they are generated by an external process (like aws sso login or aws sts assume-role). Instead, consider: • Using DefaultCredentialsProvider, which checks multiple sources (including environment variables, EC2/ECS metadata, etc.). • Using ProcessCredentialsProvider if your profile uses credential_process to fetch credentials dynamically. If you're using aws sso or sts assume-role, configure your profile like this:

[profile kafka-msk]
credential_process = aws sso get-role-credentials --role-name ... --account-id ... --region ...

This allows the SDK to invoke the process automatically to refresh credentials.

EXPERT

answered a year ago

0

Hey,

Hope you're keeping well.

For long‑running Spring Boot MSK clients, you’ll need a credentials provider that can automatically refresh before expiry. ProfileCredentialsProvider only loads credentials once, so if your profile uses temporary STS or SSO tokens it will stop working after an hour. Instead, configure your AWS profile with credential_process or use DefaultCredentialsProvider, which will re‑resolve credentials from sources like SSO, STS, or environment variables on demand. If using SSO, run aws sso login beforehand and ensure your profile uses the SSO config so the SDK refreshes automatically. This way your Kafka producer can keep publishing without manual intervention.

Thanks and regards,
Taz

answered 8 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.