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

Add AWS MSK IAM authentication to Kafka scaler #5692

Merged
merged 1 commit into from
Apr 25, 2024

Conversation

adrien-f
Copy link
Contributor

@adrien-f adrien-f commented Apr 15, 2024

Following the discussion in #5531 and #5540, this adds the support for SASL OAuthBearer with MSK token provider to the Kafka scaler using sarama library.

I've added two new fields, saslTokenProvider (authParams or TriggerMetadata) and awsRegion (TriggerMetadata).

It is currently functional, to make it work, here's an example:

---
apiVersion: v1
kind: Secret
metadata:
  name: keda-kafka-secrets
  namespace: default
data:
  sasl: "oauthbearer"
  saslTokenProvider: "aws_msk_iam"
  tls: "enable"
---
apiVersion: keda.sh/v1alpha1
kind: TriggerAuthentication
metadata:
  name: keda-trigger-auth-kafka-credential
  namespace: default
spec:
  secretTargetRef:
  - parameter: sasl
    name: keda-kafka-secrets
    key: sasl
  - parameter: saslTokenProvider
    name: keda-kafka-secrets
    key: saslTokenProvider
  - parameter: tls
    name: keda-kafka-secrets
    key: tls
---
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
  name: kafka-scaledobject
  namespace: default
spec:
  scaleTargetRef:
    name: azure-functions-deployment
  pollingInterval: 30
  triggers:
  - type: kafka
    metadata:
      bootstrapServers: localhost:9092
      consumerGroup: my-group       # Make sure that this consumer group name is the same one as the one that is consuming topics
      topic: test-topic
      # Optional
      lagThreshold: "50"
      offsetResetPolicy: latest
      awsRegion: "eu-west-1"
    authenticationRef:
      name: keda-trigger-auth-kafka-credential

I am setting it as a draft while I continue going through the contributing process and pending implementation feedback!

Checklist

Fixes #5540

Relates to #5531

Copy link
Contributor

@dttung2905 dttung2905 left a comment

Choose a reason for hiding this comment

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

Hi @adrien-f , thanks for working on this. On a high level note, it think its good to me. Just a few notes from me.
In my opinion, awsRegion should not be a secret and hence should be in triggerMetadata. Wdyt?

pkg/scalers/kafka/kafka_scaler_oauth_token_provider.go Outdated Show resolved Hide resolved
@adrien-f
Copy link
Contributor Author

Hi @adrien-f , thanks for working on this. On a high level note, it think its good to me. Just a few notes from me. In my opinion, awsRegion should not be a secret and hence should be in triggerMetadata. Wdyt?

Hey @dttung2905, thanks for the review! Indeed, I was not sure where to put awsRegion, to me it's part of the authentication parameters more than the scaler itself, but I guess that's a change we could see later in GetAwsAuthorization and discuss in another issue. I'll move it back to the triggerMetadata.

@zroubalik
Copy link
Member

zroubalik commented Apr 17, 2024

/run-e2e kafka
Update: You can check the progress here

Copy link
Member

@zroubalik zroubalik left a comment

Choose a reason for hiding this comment

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

This is great! Thanks for the contribution. Could you please also open keda-docs PR to update documentation for this addition.

@JorTurFer @tomkerkhove imho would be great if we can run e2e test against AWS MSK instance

@JorTurFer
Copy link
Member

imho would be great if we can run e2e test against AWS MSK instance

This will be more complicated that we'd expect because IIRC, MSK instance has to run mandatory using private networking. This means that we have 2 options:

  • deploy an EKS cluster + MSK cluster
  • create private networks in both sides and establishing a peering between them. This allows us to use MSK from Azure and IAM is already supported

IDK which is the best option, probably we should check the cost in both cases to not consume more than the budget. I don't have time to do this either atm, but if any contributor is willing to add a PR to testing infra adding the required changes, I can review them

@dttung2905
Copy link
Contributor

@JorTurFer, it is indeed tricky to test , I totally agree

MSK instance has to run mandatory using private networking. This means that we have 2 options:

I just take a peak at the MSK ofifical doc, they do support exposing the broker publicly but you can't make it public at the creation stage

Amazon MSK gives you the option to turn on public access to the brokers of MSK clusters running Apache Kafka 2.6.0 or later versions. For security reasons, you can't turn on public access while creating an MSK cluster. However, you can update an existing cluster to make it publicly accessible. You can also create a new cluster and then update it to make it publicly accessible.

I don't think exposing the bootstrap server endpoint publicly is a good point ( security wise ) and we may still end up with either options as Jorge mentioned above ☝️

@zroubalik
Copy link
Member

OK, let's ignore this. Maybe AWS decide to sponsor this in the future :)

@adrien-f
Copy link
Contributor Author

I will get started on updating the documentation! Thanks a lot for the review 👍

@zroubalik
Copy link
Member

I will get started on updating the documentation! Thanks a lot for the review 👍

@adrien-f we plan to do a new release today or tomorrow morning. We can include this change as well, if you are able to provide docs soon.

Copy link
Member

@zroubalik zroubalik left a comment

Choose a reason for hiding this comment

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

Please add docs and Changelog

Fixes !5540

Signed-off-by: Adrien Fillon <adrien.fillon@manomano.com>
@adrien-f
Copy link
Contributor Author

Hello @zroubalik ! I've pushed kedacore/keda-docs#1381 and a changelog entry

@zroubalik
Copy link
Member

zroubalik commented Apr 25, 2024

/run-e2e kafka
Update: You can check the progress here

Copy link
Member

@zroubalik zroubalik left a comment

Choose a reason for hiding this comment

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

LGTM

@zroubalik zroubalik mentioned this pull request Apr 25, 2024
35 tasks
@zroubalik zroubalik merged commit 6681d5e into kedacore:main Apr 25, 2024
18 of 20 checks passed
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.

Support Kafka SASL MSK IAM authentication using sarama client
4 participants