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

AwsKmsCryptographicMaterialsProvider - __attrs_post_init__ overrides custom regional clients #124

Closed
Szasza opened this issue Sep 16, 2019 · 2 comments
Assignees
Labels

Comments

@Szasza
Copy link

Szasza commented Sep 16, 2019

Hi Team,

I would like to report an issue regarding the regional client injection into the AwsKmsCryptographicMaterialsProvider.

Package version used: v1.1.1

Anything unusual about your environment or deployment: The environment is a local development environment, docker-compose is used with two services: a python:3.7.4-buster container for running the Python code, and a nsmithuk/local-kms container for a local KMS mock.

Bug reproduction steps:

  1. Set up a local KMS mock container. You can use it either as a docker-compose service or as a standalone container. REGION is to be set to us-west-2.

  2. Set up a key in the local mock container as per the usage notes using the following YAML:

Keys:
  - Metadata:
      KeyId: bc436485-5092-42b8-92a3-0aa8b93536dc
    BackingKeys:
      - 5cdaead27fe7da2de47945d73cd6d79e36494e73802f3cd3869f1d2cb0b5d7a9

Aliases:
  - AliasName: alias/testing
    TargetKeyId: bc436485-5092-42b8-92a3-0aa8b93536dc
  1. Create a small piece of code which does for example an item insert using EncryptedTable, with the following configuration:
aws_cmk_id = 'arn:aws:kms:us-west-2:111122223333:key/bc436485-5092-42b8-92a3-0aa8b93536dc'
client = boto3.session.Session().client('kms', region_name='us-west-2', endpoint_url='http://kms-service:8080')
aws_kms_cmp = AwsKmsCryptographicMaterialsProvider(key_id=aws_cmk_id, regional_clients={'us-west-2': client})

Please feel free to replace http://kms-service:8080 with the appropriate URL based on your local environment.

  1. After the above a call to the EncryptedTable helper should use the client which was created in step 3, but that's not the case, the AwsKmsCryptographicMaterialsProvider's _regional_clients attribute is empty, and it falls back to the base KMS client and tries to reach out to AWS.

I was able to mitigate the issue by deleting lines 218-220 from material_providers/aws_kms.py's __attrs_post_init__ function:

self._regional_clients = (
    {}
)  # type: Dict[Text, botocore.client.BaseClient]  # noqa pylint: disable=attribute-defined-outside-init

but I am unsure if this is the correct solution.

Any help regarding the above is much appreciated.

@Szasza Szasza changed the title Regional client injection not working Regional client injection doesn't work Sep 16, 2019
@Szasza Szasza changed the title Regional client injection doesn't work AwsKmsCryptographicMaterialsProvider - Regional client injection doesn't work Sep 16, 2019
@mattsb42-aws mattsb42-aws changed the title AwsKmsCryptographicMaterialsProvider - Regional client injection doesn't work AwsKmsCryptographicMaterialsProvider - __attrs_post_init__ overrides custom regional clients Sep 16, 2019
@mattsb42-aws
Copy link
Member

Thanks for the bug report!

You are correct; it looks like those lines are overriding any values provided. I'll have to add some tests to verify, but I think that simply deleting that assignment is the correct fix here.

@mattsb42-aws mattsb42-aws self-assigned this Sep 17, 2019
@Szasza
Copy link
Author

Szasza commented Sep 17, 2019

@mattsb42-aws my pleasure, and thank you for the quick response and the feedback, it is much appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants