-
Notifications
You must be signed in to change notification settings - Fork 1.9k
aws_msk_iam: add AWS MSK IAM authentication support #11270
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
Open
kalavt
wants to merge
10
commits into
fluent:master
Choose a base branch
from
kalavt:feature/aws-msk-iam-clean
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
a06d4db
aws: implement core AWS MSK IAM authentication
kalavt feec450
aws: improve credential refresh for MSK IAM
kalavt f652ced
kafka: enhance Kafka core for AWS MSK IAM support
kalavt a91f4fb
in_kafka: add AWS MSK IAM authentication support
kalavt be28e57
out_kafka: add AWS MSK IAM authentication support
kalavt 6fc2978
aws: improve pointer safety in region extraction
kalavt ede4d37
examples: add MSK IAM auth configuration examples
kalavt 0963e68
build: fix kafka SASL dependency detection in cmake
kalavt f2ccc07
build: honor FLB_TLS setting for Kafka SSL support
kalavt eae6ca8
out_kafka: initialize topics list early to prevent crashes
kalavt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,216 @@ | ||
| # Fluent Bit Kafka Examples | ||
|
|
||
| This directory contains examples for using Fluent Bit with Apache Kafka, including support for AWS MSK (Managed Streaming for Apache Kafka) with IAM authentication. | ||
|
|
||
| ## Examples | ||
|
|
||
| ### 1. Basic Kafka Example (`kafka.conf`) | ||
|
|
||
| A simple example demonstrating Kafka input and output with a Lua filter. | ||
|
|
||
| **Features:** | ||
|
|
||
| - Kafka consumer input | ||
| - Lua filter for message transformation | ||
| - Kafka producer output | ||
|
|
||
| **Usage:** | ||
|
|
||
| ```bash | ||
| docker-compose up | ||
| ``` | ||
|
|
||
| ### 2. AWS MSK IAM Authentication (`kafka_msk_iam.conf`) | ||
|
|
||
| Comprehensive examples for AWS MSK with IAM authentication, covering various deployment scenarios. | ||
|
|
||
| **Scenarios covered:** | ||
|
|
||
| - Standard MSK cluster (auto-detected region) | ||
| - MSK via PrivateLink (explicit region) | ||
| - MSK Serverless (auto-detected region) | ||
| - VPC Endpoint (auto-detected region) | ||
|
|
||
| ## AWS MSK IAM Authentication | ||
|
|
||
| ### Overview | ||
|
|
||
| AWS MSK supports IAM authentication, which eliminates the need to manage separate credentials for Kafka. Fluent Bit seamlessly integrates with AWS MSK IAM authentication. | ||
|
|
||
| ### Configuration | ||
|
|
||
| Enable MSK IAM authentication by setting: | ||
|
|
||
| ```ini | ||
| rdkafka.sasl.mechanism aws_msk_iam | ||
| ``` | ||
|
|
||
| ### Region Detection | ||
|
|
||
| Fluent Bit can automatically detect the AWS region from standard MSK broker hostnames: | ||
|
|
||
| - `b-1.example.kafka.us-east-1.amazonaws.com` → region: `us-east-1` | ||
| - `boot-abc.kafka-serverless.us-west-2.amazonaws.com` → region: `us-west-2` | ||
| - `vpce-123.kafka.eu-west-1.vpce.amazonaws.com` → region: `eu-west-1` | ||
|
|
||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ### Custom DNS / PrivateLink | ||
|
|
||
| When using PrivateLink aliases or custom DNS names that don't contain `.amazonaws.com`, you **must** explicitly specify the region: | ||
|
|
||
| ```ini | ||
| [OUTPUT] | ||
| Name kafka | ||
| Match * | ||
| brokers my-privatelink-alias.internal.example.com:9098 | ||
| topics my-topic | ||
| rdkafka.sasl.mechanism aws_msk_iam | ||
| aws_region us-east-1 # REQUIRED for custom DNS | ||
| ``` | ||
|
|
||
| ### AWS Credentials | ||
|
|
||
| MSK IAM authentication uses the standard AWS credentials chain: | ||
|
|
||
| 1. Environment variables (`AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`) | ||
| 2. EC2 instance profile / ECS task role (recommended for production) | ||
| 3. AWS credentials file (`~/.aws/credentials`) | ||
|
|
||
| ### Required IAM Permissions | ||
|
|
||
| Your IAM role or user needs the following permissions: | ||
|
|
||
| ```json | ||
| { | ||
| "Version": "2012-10-17", | ||
| "Statement": [ | ||
| { | ||
| "Effect": "Allow", | ||
| "Action": [ | ||
| "kafka-cluster:Connect", | ||
| "kafka-cluster:DescribeCluster", | ||
| "kafka-cluster:ReadData", | ||
| "kafka-cluster:WriteData" | ||
| ], | ||
| "Resource": [ | ||
| "arn:aws:kafka:REGION:ACCOUNT:cluster/CLUSTER_NAME/CLUSTER_UUID", | ||
| "arn:aws:kafka:REGION:ACCOUNT:topic/CLUSTER_NAME/CLUSTER_UUID/*", | ||
| "arn:aws:kafka:REGION:ACCOUNT:group/CLUSTER_NAME/CLUSTER_UUID/*" | ||
| ] | ||
| } | ||
| ] | ||
| } | ||
| ``` | ||
|
|
||
| **Note:** The cluster UUID can be found via the AWS Console, the DescribeCluster API, or the AWS CLI (`aws kafka describe-cluster`). | ||
|
|
||
| **Note:** Adjust permissions based on your use case: | ||
|
|
||
| - Consumers need: `Connect`, `DescribeCluster`, `ReadData` | ||
| - Producers need: `Connect`, `WriteData` | ||
|
|
||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ## Configuration Parameters | ||
|
|
||
| ### Common Parameters | ||
|
|
||
| | Parameter | Description | Required | | ||
| | ------------------------ | ------------------------------------- | ------------------- | | ||
| | `brokers` | Comma-separated list of Kafka brokers | Yes | | ||
| | `topics` | Topic name(s) for input or output | Yes | | ||
| | `rdkafka.sasl.mechanism` | Set to `aws_msk_iam` for MSK IAM auth | For MSK IAM | | ||
| | `aws_region` | AWS region (auto-detected if not set) | Only for custom DNS | | ||
| | `group_id` | Consumer group ID | For input | | ||
|
|
||
| ### Additional librdkafka Parameters | ||
|
|
||
| You can pass any librdkafka configuration using the `rdkafka.` prefix: | ||
|
|
||
| ```ini | ||
| rdkafka.socket.timeout.ms 60000 | ||
| rdkafka.metadata.max.age.ms 180000 | ||
| rdkafka.request.timeout.ms 30000 | ||
| ``` | ||
|
|
||
| For a complete list of parameters, see the [librdkafka configuration documentation](https://github.com/confluentinc/librdkafka/blob/master/CONFIGURATION.md). | ||
|
|
||
| ## Testing | ||
|
|
||
| ### Local Kafka (Docker) | ||
|
|
||
| 1. Start the Kafka stack: | ||
|
|
||
| ```bash | ||
| cd examples/kafka_filter | ||
| docker-compose up -d | ||
| ``` | ||
|
|
||
| 2. Run Fluent Bit: | ||
|
|
||
| ```bash | ||
| fluent-bit -c kafka.conf | ||
| ``` | ||
|
|
||
| 3. Produce test messages: | ||
|
|
||
| ```bash | ||
| ./scripts/kafka-produce.sh | ||
| ``` | ||
|
|
||
| 4. Consume messages: | ||
| ```bash | ||
| ./scripts/kafka-consume.sh | ||
| ``` | ||
|
|
||
| ### AWS MSK | ||
|
|
||
| 1. Update `kafka_msk_iam.conf` with your MSK cluster details | ||
| 2. Ensure AWS credentials are configured | ||
| 3. Run Fluent Bit: | ||
| ```bash | ||
| fluent-bit -c kafka_msk_iam.conf | ||
| ``` | ||
|
|
||
| ## Troubleshooting | ||
|
|
||
| ### Authentication Failures | ||
|
|
||
| **Error:** `failed to setup MSK IAM authentication OAuth callback` | ||
|
|
||
| **Solutions:** | ||
|
|
||
| - For custom DNS/PrivateLink: Add `aws_region` parameter | ||
| - Verify AWS credentials are available | ||
| - Check IAM permissions | ||
|
|
||
| ### Region Detection Issues | ||
|
|
||
| **Error:** `failed to auto-detect region from broker address` | ||
|
|
||
| **Solution:** | ||
| Explicitly set the region: | ||
|
|
||
| ```ini | ||
| aws_region us-east-1 | ||
| ``` | ||
|
|
||
| ### Connection Timeouts | ||
|
|
||
| **Solution:** | ||
| Increase timeout values: | ||
|
|
||
| ```ini | ||
| rdkafka.socket.timeout.ms 60000 | ||
| rdkafka.metadata.max.age.ms 180000 | ||
| ``` | ||
|
|
||
| ## Additional Resources | ||
|
|
||
| - [Fluent Bit Kafka Documentation](https://docs.fluentbit.io/) | ||
| - [AWS MSK IAM Access Control](https://docs.aws.amazon.com/msk/latest/developerguide/iam-access-control.html) | ||
| - [librdkafka Configuration](https://github.com/confluentinc/librdkafka/blob/master/CONFIGURATION.md) | ||
|
|
||
| ## Support | ||
|
|
||
| For issues or questions: | ||
|
|
||
| - [Fluent Bit GitHub Issues](https://github.com/fluent/fluent-bit/issues) | ||
| - [Fluent Bit Slack Community](https://fluentbit.io/slack) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.