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

[BUG] Sasl not working due to error in code #77

Closed
dbfun opened this issue Feb 16, 2022 · 1 comment · Fixed by #78
Closed

[BUG] Sasl not working due to error in code #77

dbfun opened this issue Feb 16, 2022 · 1 comment · Fixed by #78
Assignees
Labels
bug Something isn't working

Comments

@dbfun
Copy link

dbfun commented Feb 16, 2022

Describe the bug

Can't send message if listener uses SSL. Log message contains hint "connecting to a SSL listener?":

%7|1645035197.078|FAIL|rdkafka#producer-1| [thrd:msk-as01kafka-t:9093/bootstrap]: msk-as01kafka-t:9093/bootstrap: Disconnected while requesting ApiVersion: might be caused by incorrect security.protocol configuration (connecting to a SSL listener?) or broker version is < 0.10 (see api.version.request) (after 70ms in state APIVERSION_QUERY) (_TRANSPORT)

To Reproduce
Steps to reproduce the behavior:

  1. Run PHPUnit test with SSL Kafka listener:
<?php

namespace Tests\Feature\Kafka;

use Junges\Kafka\Config\Sasl;
use Junges\Kafka\Facades\Kafka;
use Junges\Kafka\Message\Message;
use Tests\TestCase;

class KafkaProtocolTest extends TestCase
{
    public function testKafkaProtocol(): void
    {
        $topic = env('TOPIC_NAME', 'ORDERS');
        $user = env('KAFKA_USER');
        $password = env('KAFKA_PASSWORD');

        $message = new Message(
            topicName: $topic,
            body: ['key' => 'value'],
        );

        $sasl = new Sasl(
            username: $user,
            password: $password,
            mechanisms: 'PLAIN',
            securityProtocol: 'SASL_SSL'
        );

        $producer = Kafka::publishOn($topic)
            ->withSasl($sasl)
            ->withMessage($message);
        $producer->withDebugEnabled(true);

        // return false
        $this->assertTrue($producer->send());
    }
}

This test fails because Sals authentication failed.

Expected behavior
This test passed.

How to fix it

Patch ProducerBuilder:

private function build(): Producer
{
    $conf = new Config(
        broker: $this->broker,
        topics: [$this->getTopic()],
        // This line has been added:
        securityProtocol: $this->saslConfig ? $this->saslConfig->getSecurityProtocol() : null,
        sasl: $this->saslConfig,
        customOptions: $this->options,
    );

    return app(Producer::class, [
        'config' => $conf,
        'topic' => $this->topic,
        'serializer' => $this->serializer,
    ]);
}

Desktop (please complete the following information):

  • OS: Debian 11 in Docker
  • mateusjunges/laravel-kafka: v1.6.1
  • laravel/framework: v8.83.1
@mateusjunges
Copy link
Owner

Hey @dbfun i just patched a fix for this bug. Will be released within the next hour. Thanks for reporting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants