Skip to content

Support for MSK AWS IAM auth#8049

Merged
n1ru4l merged 10 commits into
graphql-hive:mainfrom
mish-elle:msk-iam-auth
May 27, 2026
Merged

Support for MSK AWS IAM auth#8049
n1ru4l merged 10 commits into
graphql-hive:mainfrom
mish-elle:msk-iam-auth

Conversation

@mish-elle

Copy link
Copy Markdown
Contributor

Background

Self-hosters running Hive on AWS with Amazon MSK (Managed Streaming for Apache Kafka) currently have no way to use IAM-based authentication for Kafka connections. This forces them to use static credentials.

This PR adds opt-in MSK AWS IAM authentication support for the services that communicates to Kafka/MSK: usage and usage-ingestor. In addition, the KAFKA_BROKER previously only accepted a single broker address. This PR also updates it to accept a comma-separated list of brokers. This functionality is already supported in the KafkaJS library.

This PR is part of the following issue. We will have separate PRs for each IAM support to help decrease the scope per PR.

Description

The MSK token generation logic happens in service-common/src/iam-msk.ts's createMskIamTokenProvider() function. This generates a short-lived SigV4 token using aws-msk-iam-sasl-signer-js. The services use this provider to authenticate to Kafka via the OAUTHBEARER SASL mechanism when IAM auth is enabled. KafkaJS supports an oauthBearerProvider to take a function for dynamic passwords so it will handle the token refreshes.

New environmental variables introduced

Variable Required Description
AWS_REGION No Default AWS region for the service used for all AWS connections
KAFKA_AWS_IAM_AUTH_ENABLED No Set to 1 to enable IAM authentication
KAFKA_AWS_REGION No Optional override for the Kafka broker region (defaults to AWS_REGION)

Credential Flow for MSK

---
title: MSK / Kafka (Long-lived Connection)
---
flowchart TD
    A[Resolve Kafka SASL] --> B{AWS_REGION set?}
    B -->|Yes| C{KAFKA_AWS_IAM_AUTH_ENABLED = true?}
    C -->|Yes| D[✅ OAUTHBEARER + SigV4 token<br/>Region: KAFKA_AWS_REGION ?? AWS_REGION]
    C -->|No / not set| E{Explicit SASL mechanism?<br/>plain / scram-sha-*}
    B -->|No| E
    E -->|Yes| F[✅ Use username + password]
    E -->|No| G[✅ No SASL]
Loading

Checklist

  • Input validation
  • Output encoding
  • Authentication management
  • Session management
  • Access control
  • Cryptographic practices
  • Error handling and logging
  • Data protection
  • Communication security
  • System configuration
  • Database security
  • File management
  • Memory management
  • Testing

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This PR implements AWS IAM authentication for MSK across the usage and usage-ingestor services. Key changes include a new MSK token provider utility, updated Zod environment schemas, and support for comma-separated Kafka broker lists. Feedback identifies a typo in the changeset file and recommends trimming whitespace when parsing the broker list to prevent potential connection errors.

Comment thread .changeset/silly-flowers-yell.md Outdated
Comment thread packages/services/usage-ingestor/src/ingestor.ts Outdated
Comment thread packages/services/usage/src/usage.ts Outdated
@dotansimha dotansimha requested review from dotansimha and n1ru4l May 18, 2026 06:56
Comment thread packages/services/service-common/package.json Outdated
Comment thread packages/services/usage-ingestor/src/environment.ts
Comment thread packages/services/usage-ingestor/src/ingestor.ts Outdated
Comment thread packages/services/usage-ingestor/src/environment.ts Outdated
Comment thread packages/services/usage-ingestor/src/ingestor.ts
Comment thread packages/services/service-common/src/iam-msk.ts Outdated
Comment thread packages/services/service-common/src/iam-msk.spec.ts
Comment thread .changeset/silly-flowers-yell.md Outdated
@dotansimha dotansimha mentioned this pull request May 18, 2026
- Add environment validation: require KAFKA_SSL=1 and AWS region when IAM is enabled
- Add non-happy-path tests for createMskIamTokenProvider (error propagation,
  undefined token, token refresh)
- Remove unnecessary type cast in createMskIamTokenProvider
- Upgrade aws-msk-iam-sasl-signer-js from 1.0.0 to 1.0.3
- Trim whitespace in comma-separated KAFKA_BROKER addresses
- Improve changeset documentation
@mish-elle

Copy link
Copy Markdown
Contributor Author

Also the CI pipelines fail because of the pnpm-lock file. We're downgrading dependencies and not building a few packages, due to constraints in our environment. Is it possible for a code maintainer to help us generate the pnpm-lock file?

@n1ru4l n1ru4l mentioned this pull request May 26, 2026

@n1ru4l n1ru4l left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

i added a few comments that should be addressed + CI and linting is failing currently. Can you please address these?

Comment thread packages/services/usage/src/environment.ts Outdated
Comment thread packages/services/service-common/src/iam-msk.spec.ts Outdated
Comment thread packages/services/usage-ingestor/src/environment.ts

@n1ru4l n1ru4l left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Legit! Thank you for helping out!

@n1ru4l n1ru4l requested a review from dotansimha May 27, 2026 08:53
@n1ru4l n1ru4l merged commit 548a597 into graphql-hive:main May 27, 2026
46 of 47 checks passed
@n1ru4l n1ru4l mentioned this pull request May 29, 2026
14 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants