aws / aws-msk-iam-auth

Enables developers to use AWS Identity and Access Management (IAM) to connect to their Amazon Managed Streaming for Apache Kafka (Amazon MSK) clusters.
Apache License 2.0
142 stars 65 forks source link

How IAM supports multiple credential within one single project? #124

Closed FORRESTLWL closed 1 year ago

FORRESTLWL commented 1 year ago

We have a scenario that there are 2 kafkas source need to be connected in our project with different IAM credentials. But according to your credential provider chain, it seems that it only support 1 single credential at one time. I'm wondering if there is anyway that I can achieve this? Sth like: Kafka1 config -> load credential 1 Kafka2 config -> load credential 2

sidyag commented 1 year ago

In order to do this, you will need to create 2 different configuration files, and use them to create 2 different Kafka clients.

For instance:

client1.properties

# Sets up TLS for encryption and SASL for authN.
security.protocol = SASL_SSL

# Identifies the SASL mechanism to use.
sasl.mechanism = AWS_MSK_IAM

# Binds SASL client implementation. Uses the specified profile name to look for credentials.
sasl.jaas.config = software.amazon.msk.auth.iam.IAMLoginModule required awsProfileName="profile1";

# Encapsulates constructing a SigV4 signature based on extracted credentials.
# The SASL client bound by "sasl.jaas.config" invokes this class.
sasl.client.callback.handler.class = software.amazon.msk.auth.iam.IAMClientCallbackHandler

client2.properties

# Sets up TLS for encryption and SASL for authN.
security.protocol = SASL_SSL

# Identifies the SASL mechanism to use.
sasl.mechanism = AWS_MSK_IAM

# Binds SASL client implementation. Uses the specified profile name to look for credentials.
sasl.jaas.config = software.amazon.msk.auth.iam.IAMLoginModule required awsProfileName="profile2";

# Encapsulates constructing a SigV4 signature based on extracted credentials.
# The SASL client bound by "sasl.jaas.config" invokes this class.
sasl.client.callback.handler.class = software.amazon.msk.auth.iam.IAMClientCallbackHandler

And use the following Kafka cli commands to consume messages from topic:

kafka-console-consumer.sh --bootstrap-server $bootstrap-server --topic test_topic --consumer.config <enter filename here>