fix(kafka): apply sts_header_overrides to MSK IAM SASL auth#6925
fix(kafka): apply sts_header_overrides to MSK IAM SASL auth#6925hozkaya2000 wants to merge 1 commit into
Conversation
Resolves opensearch-project#6923. Signed-off-by: Halit Ozkaya <hozkaya@amazon.com>
dlvenable
left a comment
There was a problem hiding this comment.
Thank you @hozkaya2000 for this contribution!
| properties.put(SASL_CLIENT_CALLBACK_HANDLER_CLASS, MskIamAuthCredentialsCallbackHandler.class.getName()); | ||
| properties.put(SASL_JAAS_CONFIG, "software.amazon.msk.auth.iam.IAMLoginModule required;"); | ||
| } else { | ||
| String baseIamAuthConfig = "software.amazon.msk.auth.iam.IAMLoginModule required " + |
There was a problem hiding this comment.
I'm a bit concerned about having split authentication approaches. We should always take the same authentication rather than make it a condition on STS header overrides.
| final Map<String, String> stsHeaderOverrides = awsConfig.getAwsStsHeaderOverrides(); | ||
| if (Objects.nonNull(stsHeaderOverrides) && !stsHeaderOverrides.isEmpty()) { | ||
| properties.put(SASL_CLIENT_CALLBACK_HANDLER_CLASS, MskIamAuthCredentialsCallbackHandler.class.getName()); | ||
| properties.put(SASL_JAAS_CONFIG, "software.amazon.msk.auth.iam.IAMLoginModule required;"); |
There was a problem hiding this comment.
You are loading this IAMLoginModule from the AWS MSK library. What prevents the MSK library from using the default credentials provider (from AWS SDK) directly instead of the callback handler? Might there be code paths that result in this bad path?
I'm wondering if there is a path to writing our own IAMLoginModule and not using the MSK one at all.
I noticed this line in IAMClientCallbackHandler:
provider = configEntry.map(c -> (AWSCredentialsProvider) new MSKCredentialProvider(c.getOptions()))
.orElse(DefaultAWSCredentialsProviderChain.getInstance());
It seems that this will return DefaultAWSCredentialsProviderChain.getInstance() which is not at all what we want.
There was a problem hiding this comment.
We also want to be sure that we don't use MSKCredentialProvider. From what I can tell this is used only by IAMClientCallbackHandler and IAMOAuthBearerLoginCallbackHandler.
There was a problem hiding this comment.
Maybe writing our own IAMLoginModule won't have an impact. From what I can tell this doesn't choose the mechanism to load credentials. I think it configures internal security providers.
| * <p>The header-aware provider is AWS SDK v2 while aws-msk-iam-auth 2.0.3 expects SDK v1 | ||
| * {@link AWSCredentials}, so the resolved temporary credentials are translated v2 to v1. | ||
| */ | ||
| public class MskIamAuthCredentialsCallbackHandler extends IAMClientCallbackHandler { |
There was a problem hiding this comment.
Could we extend from AuthenticateCallbackHandler and not use the AWS MSK library at all? This would also let us use only AWS SDK v2.
There was a problem hiding this comment.
I took another look at the AWS MSK library. It performs the bridge between AWS credentials and SASL. Most of this is in their internals package. We should keep all of that. It is not worth rewriting because it maps credentials to SASL networking interactions.
What we should be sure to do is fully change the way that we get those AWS credentials. I think you should make this implement AuthenticateCallbackHandler directly instead of using the IAMClientCallbackHandler sub-class. But you can copy a lot of the existing code from IAMClientCallbackHandler. We just need to be sure to not load credentials from the SDK except through our AWS plugin.
We will need to retain v1 to keep using their internals package.
|
dlvenable
left a comment
There was a problem hiding this comment.
I'm removing my "request changes" hold
Description
The Kafka plugin already applies the configured
sts_header_overridesto the STSAssumeRolecall used to fetch MSK bootstrap brokers, but not to the data-plane SASL (AWS_MSK_IAM) connection used for the actual consume/produce. That broker authentication delegates credential resolution to theaws-msk-iam-authlibrary's internal role assumption, which has no way to apply STS header overrides, so the configured headers are silently dropped for the broker connection.This change makes
sts_header_overridesapply consistently across all STSAssumeRolecalls the plugin performs for MSK:aws_msk_iam: roleis configured withsts_header_overrides, the SASL client callback handler is switched to a custom handler that resolves credentials from the same header-awareStsAssumeRoleCredentialsProvideralready used for bootstrap-broker discovery, and the JAAS config is set to default mode so the library does not perform its own (header-less) role assumption.aws-msk-iam-authexpects.Behavior is unchanged when no
sts_header_overridesare configured, and foraws_msk_iam: default.Issues Resolved
Resolves #6924
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.