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

Add support for SSL, SASL_PLAIN, and SASL_SSL listeners in kafka brokers. #28

Merged
merged 54 commits into from Dec 13, 2018

Conversation

Crim
Copy link
Collaborator

@Crim Crim commented Dec 11, 2018

This PR adds support to configure the test brokers to use SSL, SASL_PLAIN, or SASL_SSL authentication methods. By default if no explicit authentication scheme is defined, it will fall back to the previous behavior of using PLAIN.

While the underlying KafkaTestServer supports being configured with multiple authentication schemes/listeners, the exposed Test resources only support a single instance. I believe additional thought needs to be given around how to expose connection details when multiple listener types are available. Likely this would result in breaking changes to the API, so it's been pushed off until the need for this is required.

Example for configuring SSL enabled brokers

When configuring to use SSL, the end user will need to supply paths to their own trust and key stores, as well as passwords. The ones included in these tests are dummy stores created just to validate behavior programatically, and have no use outside of those tests.

    /**
     * We have two node embedded kafka cluster that gets started when this test class is initialized.
     *
     * It's automatically started before any methods are run via the @ClassRule annotation.
     * It's automatically stopped after all of the tests are completed via the @ClassRule annotation.
     *
     * This example we start a cluster with
     *  - 2 brokers (defaults to a single broker)
     *  - configure the brokers to disable topic auto-creation.
     *  - enables SSL authentication with a test/dummy key and trust stores.
     */
    @ClassRule
    public static final SharedKafkaTestResource sharedKafkaTestResource = new SharedKafkaTestResource()
        // Start a cluster with 2 brokers.
        .withBrokers(2)
        // Disable topic auto-creation.
        .withBrokerProperty("auto.create.topics.enable", "false")
        // Register and configure SSL authentication on cluster.
        .registerListener(new SslListener()
        .useSslForInterBrokerProtocol()
        .withKeyStoreLocation(SharedKafkaTestResourceWithSslTest.class.getClassLoader().getResource("kafka.keystore.jks").getFile())
        .withKeyStorePassword("password")
        .withTrustStoreLocation(SharedKafkaTestResourceWithSslTest.class.getClassLoader().getResource("kafka.truststore.jks").getFile())
        .withTrustStorePassword("password")
        .withKeyPassword("password")
    );

Example for configuring SASL_PLAIN enabled brokers

When configuring to use SASL, because of how Kafka reads in JAAS configuration files via an environment variable, the end user will need to start the JVM with the argument: -Djava.security.auth.login.config=path/to/jaas.conf

   /**
     * We have a two node kafka cluster that gets started when this test class is initialized.
     *
     * It's automatically started before any methods are run via the @ClassRule annotation.
     * It's automatically stopped after all of the tests are completed via the @ClassRule annotation.
     *
     * This example we start a cluster with
     *  - 2 brokers (defaults to a single broker)
     *  - configure the brokers to disable topic auto-creation.
     *  - Enable SASL_PLAIN authentication, using username 'kafkaclient' and password 'client-secret'
     */
    @ClassRule
    public static final SharedKafkaTestResource sharedKafkaTestResource = new SharedKafkaTestResource()
        // Start a cluster with 2 brokers.
        .withBrokers(2)
        // Disable topic auto-creation.
        .withBrokerProperty("auto.create.topics.enable", "false")
        // Register and configure SASL PLAIN authentication on cluster.
        .registerListener(new SaslPlainListener()
        .withUsername("kafkaclient")
        .withPassword("client-secret")
    );

Example for configuring SASL_SSL enabled brokers

SASL_SSL is basically a combination of SSL + SASL_PLAIN and also requires the JVM argument -Djava.security.auth.login.config=path/to/jaas.conf

@Crim Crim requested a review from stanlemon December 11, 2018 08:21
@Crim
Copy link
Collaborator Author

Crim commented Dec 11, 2018

@stanlemon would you mind code reviewing this when you have a moment?

@@ -99,7 +105,7 @@
</dependency>
</dependencies>
<configuration>
<argLine>-Xmx2048M</argLine>
<argLine>-Xmx5120M</argLine>
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems like a lot...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

hah ya, trying to sort out the OOM errors in travis CI. Odd that it runs without issue locally all the way thru the test suite.

Copy link
Contributor

Choose a reason for hiding this comment

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

Smells like a memory leak somewhere.

/**
* Defines which listener has been set to be configured on the brokers.
*/
private BrokerListener registeredListener = new PlainListener();
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be final?

Copy link
Contributor

Choose a reason for hiding this comment

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

Disregard, I see now.

* Test a multi-node cluster instance with various listeners.
* @param listeners The listeners to register.
*/
// @ParameterizedTest
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this temporary?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yea, more trying to figure out the source of the OOM on travis :/

Copy link
Contributor

@stanlemon stanlemon left a comment

Choose a reason for hiding this comment

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

Seems pretty straightforward.

@Crim Crim merged commit 4c527af into master Dec 13, 2018
@Crim Crim deleted the sp/sasl branch December 13, 2018 02:01
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.

None yet

2 participants