confluent-kafka-go icon indicating copy to clipboard operation
confluent-kafka-go copied to clipboard

Implement callback for SASL PLAIN credentials

Open josvisser66 opened this issue 2 years ago • 1 comments

Introduction

This PR is the sibling of https://github.com/edenhill/librdkafka/pull/3955 which adds a feature to librdkafka that allows the specification of a callback to obtain the SASL PLAIN credentials.

The Golang implementation works as follows:

func credsCallback() (string, string, error) {
        // Magic here.
        return username, password, nil
}

func main() {
        c, err := kafka.NewConsumer(&kafka.ConfigMap{
                "bootstrap.servers": "pkc-XXXXXX.confluent.cloud:9092",
                "group.id":          "myGroup",
                "auto.offset.reset": "earliest",
                "sasl.mechanism":    "PLAIN",
                "security.protocol": "SASL_SSL",
                "plain.creds.cb":    credsCallback,
        })

Whenever librdkafka needs the credentials it calls (through some intermediaries) the Golang callback specified in the "plain.creds.cb" key and uses whatever it gets back from there.

Implementation details

There is some excitement in this PR because of the way the C/Go bridge works and the consequences of that. The PR provides a single callback function for all Golang Kafka clients (in C) which then branches out to the "right" one for this particular Kafka client (using the pointer address of the Kafka client structure as a key in a map). There is a drawback to this approach, which is that we can only update that map when we know that pointer address and this means that there is a short coverage gap where the client could call the callback and not get any results. Testing so far seems to indicate that this is not a big problem.

josvisser66 avatar Sep 06 '22 20:09 josvisser66

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Sep 06 '22 20:09 CLAassistant

We decided on another approach.

josvisser66 avatar Nov 04 '22 18:11 josvisser66