Skip to content

[SVC-672] Build AWS Session in BrokerConnection#5

Merged
ebuttiero merged 2 commits into
masterfrom
svc_672_build_session
Jan 17, 2022
Merged

[SVC-672] Build AWS Session in BrokerConnection#5
ebuttiero merged 2 commits into
masterfrom
svc_672_build_session

Conversation

@ebuttiero
Copy link
Copy Markdown

@ebuttiero ebuttiero commented Jan 14, 2022

In this PR:

  • The AWS Session is built when the BrokerConnection needs it.
  • The sasl_aws_msk_iam_session parameter was removed.
  • A new sasl_aws_msk_iam_role_arn parameter was added: When this parameter has a value, the role indicated is assumed and the credentials to use to create a Session object are those provided by the assumed role.
  • It was not necessary to design and implement a mechanism to renew tokens. When the BrokerConnection needs to establish a new connection, it will get a fresh session object.
  • The region_name was not included in the creation of Session objects or STS clients. Also, the default session object is created without any parameter (region, aws_access_key_id, etc). We should provide these parameters as environment variables.

The following Alexandria image was built including this version of the library, in case you wan't to run some tests:

quay.io/reciprocity/alexandria:2022-01-14_17-43-39_svc_672_upgrade_kafka_connection_build_4a1ed9e

Comment thread kafka/conn.py Outdated
return self._try_authenticate_scram(future)
elif self.config['sasl_mechanism'] == 'AWS_MSK_IAM':
return self._try_authenticate_aws_msk_iam(future, self.config["sasl_aws_msk_iam_session"])
return self._try_authenticate_aws_msk_iam(future, self.config["sasl_aws_msk_iam_role_arn"])
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

config is initialized in init, so there should be no need to pass it as a parameter.

Comment thread kafka/conn.py Outdated
aws_access_key_id=credentials['AccessKeyId'],
aws_secret_access_key=credentials['SecretAccessKey'],
aws_session_token=credentials['SessionToken'],
)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should go into a separate private method or nested method, but that is a personal preference, not a requirement :)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finally, I moved the entire Session creation logic to a private method.

@ebuttiero ebuttiero merged commit c0a3c5e into master Jan 17, 2022
@ebuttiero ebuttiero deleted the svc_672_build_session branch January 17, 2022 17:21
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

Successfully merging this pull request may close these issues.

2 participants