1 year ago

#77451

test-img

DGS

Quarkus reactive postgres client IAM authentication token refresh

I am using Quarkus 2.5.1.Final to build one microservice. I am using hibernate reactive with postgres as database. At my organization we use AWS IAM auth tokens for database authentication. AWS IAM token is generated using amazon awssdk and passed as password to database. To generate IAM auth token I have created custom CredentialsProvider.

@Named("iam-ds-credential-provider")
public class IamDataSourceCredentialProvider implements CredentialsProvider {
...
@Override
public Map<String, String> getCredentials(String credentialsProviderName) {
...
    return Map.of(PASSWORD_PROPERTY_NAME, generatedAWSToken,
USER_PROPERTY_NAME, datasourceUsername);
}

application.properties

...
quarkus.datasource.db-kind=postgresql
quarkus.datasource.credentials-provider=custom
quarkus.datasource.credentials-provider-name=iam-ds-credential-provider
....

Our IAM auth tokens expire every 10 minutes. When server boots up, password/IAM auth token is cached somewhere in Quarkus framework. Connections created within first 10 minute work. After 10 minutes, new connections created try to use expired IAM auth token. Hence password authentication fails for these connections.

How can I refresh cached database credentials? Or how can i force postgres connection pool to get fresh password(IAM auth token) everytime? Or is there a way to intercept failed connection and then refresh password and retry connection?

Any help is much appreciated.

postgresql

amazon-iam

quarkus

reactive

0 Answers

Your Answer

Accepted video resources