Skip to content

S3 Encryption Client not using credentials of wrapped client #201

@ahmarsuhail

Description

@ahmarsuhail

Problem:

I have two AWS accounts, A and B. In my ~/.aws/credentials file, I have credentials for account B. While creating the wrapped clients to pass into S3EC, I am passing in credentials for account A. I am accessing a bucket in account A. Code:

  S3Client s3Client = S3Client.builder().region(Region.EU_WEST_1)
        .credentialsProvider(StaticCredentialsProvider.create(
            AwsBasicCredentials.create("xxxx", "xxxx")
        ))
        .build();

    S3AsyncClient s3AsyncClient = S3AsyncClient.builder().region(Region.EU_WEST_1)
        .credentialsProvider(StaticCredentialsProvider.create(
            AwsBasicCredentials.create("xxxx", "xxxx")
        ))
        .build();

    S3Client s3ECClient = S3EncryptionClient.builder()
             .kmsKeyId("xxxxx")
            .wrappedClient(s3Client)
            .wrappedAsyncClient(s3AsyncClient)
           .enableLegacyUnauthenticatedModes(true)
           .build();



    ResponseInputStream<GetObjectResponse> inputStream = s3ECClient.getObject(
        GetObjectRequest.builder()
        .bucket("xxxx")
        .key("xxxx").build());

This gives

software.amazon.encryption.s3.S3EncryptionClientException: User: arn:aws:iam::<ACCOUNT B USER> is not authorized to perform: kms:Decrypt on the resource associated with this ciphertext because the resource does not exist in this Region, no resource-based policies allow access, or a resource-based policy explicitly denies access

If I comment out the credentials in my ~/.aws/credentials, I get software.amazon.encryption.s3.S3EncryptionClientException: Unable to load credentials from any of the providers in the chain AwsCredentialsProviderChain

It works fine if put credentials of account A in my ~/.aws/credentials.

Solution:

Looks like S3EC is ignoring credentials passed in the wrapped clients and picking up credentials from the default credentials resolution chain. It should use credentials of the wrapped clients.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions