Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The client doesn't work with custom credentials #16

Open
fredrikaubert opened this issue Oct 3, 2019 · 0 comments
Open

The client doesn't work with custom credentials #16

fredrikaubert opened this issue Oct 3, 2019 · 0 comments

Comments

@fredrikaubert
Copy link

When creating a AmazonSQSSecureClient with a custom aws credentials you get an exception when trying to send a message:
com.amazonaws.services.kms.model.AWSKMSException: The security token included in the request is invalid (Service: AWSKMS; Status Code: 400; Error Code: UnrecognizedClientException;

Relevant stacktrace snippet:
at no.cantara.aws.sqs.KMSCryptoUtil.generateDataKey(KMSCryptoUtil.java:118) at no.cantara.aws.sqs.KMSCryptoUtil.encrypt(KMSCryptoUtil.java:106) at no.cantara.aws.sqs.AmazonSQSSecureClient.deflate(AmazonSQSSecureClient.java:212) at no.cantara.aws.sqs.AmazonSQSSecureClient.sendMessage(AmazonSQSSecureClient.java:152)

It seems to be caused by the getAWSKMS-method in KMSCryptoUtil where DefaultAWSCredentialsProviderChain is hardcoded:

private static AWSKMS getAWSKMS(final Region region) {
        if (!REGION.containsKey(region)) {
            AWSKMSClient client = new AWSKMSClient(new DefaultAWSCredentialsProviderChain());
            client.setRegion(region);
            REGION.put(region, client);
        }
        return REGION.get(region);
    }

The the client is created this way(Kotlin):

val credentials = BasicAWSCredentials(accessKey, secretKey )
val credentialsProvider = AWSStaticCredentialsProvider(credentials)
val sqsClient = AmazonSQSSecureClient.create(credentialsProvider, region, kmsCmkId, s3Bucket );

When providing the same credentials as environment variables everything works as expected.

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

No branches or pull requests

1 participant