Skip to content

feat: support kafka auth mechanism scram-sha-512 - #134

Merged
lehainam-dev merged 1 commit into
main-kafkafrom
feat/support-kafka-sasl-scram-512
Aug 10, 2026
Merged

lehainam-dev merged 1 commit into
main-kafkafrom
feat/support-kafka-sasl-scram-512

Conversation

@lehainam-dev

Copy link
Copy Markdown
Member

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds support for Kafka SASL/SCRAM-SHA-512 authentication by wiring a SCRAM client implementation into the Kafka publisher and exposing a mechanism selector via configuration/CLI.

Changes:

  • Introduces an xdg-go/scram → Sarama SCRAMClient adapter plus a handshake test.
  • Adds SASLMechanism to Kafka publisher config and CLI flag plumbed into app startup.
  • Updates Go module dependencies to include github.com/xdg-go/scram (and indirect deps).

Reviewed changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
pkg/publisher/kafka/scram.go Adds SCRAM client adapter used by Sarama for SCRAM auth.
pkg/publisher/kafka/scram_test.go Adds end-to-end SCRAM-SHA-512 conversation test against a real scram server.
pkg/publisher/kafka/kafka.go Wires SCRAM-SHA-512 into Sarama config based on SASLMechanism.
pkg/publisher/kafka/config.go Extends publisher config with SASLMechanism.
internal/app/flags.go Adds --kafka-sasl-mechanism / KAFKA_SASL_MECHANISM flag.
internal/app/app.go Passes SASL mechanism from CLI into Kafka publisher config.
go.mod Adds github.com/xdg-go/scram dependency (plus indirect deps).
go.sum Records module checksums for the new dependencies.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +3 to +23
import (
"github.com/xdg-go/scram"
)

// XDGSCRAMClient adapts xdg-go/scram to sarama's SCRAMClient interface.
// Step and Done are satisfied via the embedded *scram.ClientConversation.
type XDGSCRAMClient struct {
*scram.Client
*scram.ClientConversation
scram.HashGeneratorFcn
}

func (x *XDGSCRAMClient) Begin(userName, password, authzID string) error {
client, err := x.NewClient(userName, password, authzID)
if err != nil {
return err
}
x.Client = client
x.ClientConversation = x.NewConversation()
return nil
}
Comment on lines +39 to +46
if config.UseAuthentication && config.SASLMechanism == sarama.SASLTypeSCRAMSHA512 {
zap.S().Info("[kafka] using SASL/SCRAM-SHA-512 authentication")

c.Net.SASL.Mechanism = sarama.SASLTypeSCRAMSHA512
c.Net.SASL.SCRAMClientGeneratorFunc = func() sarama.SCRAMClient {
return &XDGSCRAMClient{HashGeneratorFcn: scram.SHA512}
}
}
Comment on lines +39 to +46
if config.UseAuthentication && config.SASLMechanism == sarama.SASLTypeSCRAMSHA512 {
zap.S().Info("[kafka] using SASL/SCRAM-SHA-512 authentication")

c.Net.SASL.Mechanism = sarama.SASLTypeSCRAMSHA512
c.Net.SASL.SCRAMClientGeneratorFunc = func() sarama.SCRAMClient {
return &XDGSCRAMClient{HashGeneratorFcn: scram.SHA512}
}
}
Comment thread internal/app/flags.go
Comment on lines +150 to +155
kafkaSASLMechanismFlag = &cli.StringFlag{
Name: "kafka-sasl-mechanism",
EnvVars: []string{"KAFKA_SASL_MECHANISM"},
Value: "",
Usage: "SASL mechanism for authenticating with kafka brokers. Supports: `SCRAM-SHA-512`, PLAIN (default)",
}
@lehainam-dev
lehainam-dev merged commit 1252716 into main-kafka Aug 10, 2026
5 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.

3 participants