You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 5 Next »

Status

Current state: "Under Discussion"

Discussion thread: here

JIRA: here

Please keep the discussion on the mailing list rather than commenting on the wiki (wiki discussions get unwieldy fast).

Motivation

It has been a common request to be able to customize SslFactory beyond the existing configuration options. For example, users want encrypted passwords, an alias to choose a certificate, OCSP support, etc. For these, alternative config options make the most sense because these are generic config options that are useful in many environments, so we should support these without having to write Java code.

There are situations where adding configuration options will never be able to satisfy the requirement. For example, the user may need to reuse an existing SSL implementation or share an implementation across multiple applications. For those cases, the simplest approach would be to support the customization of the SslFactory implementation.

A custom SslFactory implementation might also serve as a stop gap measure when a user needs an SSL feature immediately but the necessary configuration option is not yet available.

Of course it would be easy to simply change the Kafka source code and ship a customized distribution. The idea is you should be able to replace the implementation through configuration, without rebuilding a custom Kafka distribution or resorting to classpath tricks to shadow Kafka classes.

Public Interfaces

This KIP will introduce a new configuration option ssl.sslfactory.class to be added to SslConfigs. This will automatically add the new option to AdminClientConfig, ConsumerConfig and ProducerConfig.

A new public interface named SslFactory will be created. A default implementation named DefaultSslFactory will be included with Kafka. The implementation is private, but the class name will leak as the default value of ssl.sslfactory.class

An application developer can implement SslFactory and set ssl.sslfactory.class to the fully qualified class name to instruct Kafka to use this implementation instead of the default implementation.

Proposed Changes

A new configuration option will be added to SslConfigs:

public static final String SSL_SSLFACTORY_CLASS_CONFIG = "ssl.sslfactory.class";
public static final String SSL_SSLFACTORY_CLASS_DOC = "...";
public static final String DEFAULT_SSL_SSLFACTORY_CLASS = "org.apache.kafka.common.security.ssl.DefaultSslFactory";
config.define(SslConfigs.SSL_SSLFACTORY_CLASS_CONFIG, ConfigDef.Type.CLASS, SslConfigs.DEFAULT_SSL_SSLFACTORY_CLASS, ConfigDef.Importance.LOW, SslConfigs.SSL_SSLFACTORY_CLASS_DOC)

Currently, SslFactory is a class that is not part of the public API. This class will be renamed DefaultSslFactory to make the name SslFactory available for the new interface.

A new public interface named SslFactory will be created.

public interface SslFactory extends Reconfigurable {
   /* valid values are Mode.CLIENT or Mode.SERVER */
   public static final String SSL_MODE_CONFIG = "ssl.mode";

   /* valid values are Boolean.TRUE or Boolean.FALSE */
   public static final String SSL_VERIFY_KEYSTORE_USING_TRUSTSTORE_CONFIG = "ssl.verify.keystore.using.truststore";

   public SSLEngine createSslEngine(String peerHost, int peerPort);
}

The source code of SslFactory will contain javadoc comments to describe the interface and each declaration.

An implementation of SslFactory will be instantiated with a default constructor. The non-default constructors in DefaultSslFactory will be removed. The member clientAuthConfigOverride will also be removed. The default constructor of DefaultSslFactory does nothing and therefore can be omitted too.

DefaultSslFactory can no longer rely on constructor arguments. Instead it will receive these values as regular config options in configure((Map<String, ?> configs). This KIP introduces two new config keys ssl.mode and ssl.verify.keystore.using.truststore. The configure() method in DefaultSslFactory will be modified to initialize the mode from the ssl.mode config and the boolean keystoreVerifiableUsingTruststore from the ssl.verify.keystore.using.truststore config. The variable clientAuthConfig will always be initialized from the ssl.client.auth config. It is the caller's responsibility to override ssl.client.auth before calling configure() because it can no longer be overridden by a constructor argument.

In SaslChannelBuilder and SslChannelBuilder, the type of the member sslFactory will still be SslFactory but now it refers to the interface. Instead of calling the SslFactory constructor directly, we will call a new method createSslFactory(). This method will be duplicated in both channel builders.

createSslFactory() will alter (a copy of?) the configs to contain the values for what used to be passed as arguments in the SslFactory constructor. The SSL mode will be stored with the key ssl.mode; if not null clientAuthConfigOverride will be stored with the key ssl.client.auth overwriting the value already there; keystoreVerifiableUsingTruststore will be stored with the key ssl.verify.keystore.using.truststore.

createSslFactory() will call the default constructor of the pluggable SSL Interface by calling Class.newInstance() followed by a call to configure() to pass the configs.

EchoServer calls SslFactory directly and will no longer compile. This is an internal test so backwards compatibility does not apply. We will update EchoServer to call DefaultSslFactory directly instead.

Compatibility, Deprecation, and Migration Plan

Because SslFactory was not a public API, this KIP is considered backwards compatible. Applications that called SslFactory directly will have to be updated but that's the risk taken when calling private APIs.

The default value for the new config ssl.sslfactory.class is org.apache.kafka.common.security.ssl.DefaultSslFactory which selects the existing implementation.

The SslFactory implementation is instantiated by the SslChannelBuilder or the SaslChannelBuilder which will hide all the changes.

EchoServer calls SslFactory directly, but that's an internal test. We will update EchoServer as part of this KIP.

Rejected Alternatives

Kafka could define a new configuration option to hold an instance of SSLSocketFactory. This is similar to many Java libraries that accept an instance of SSLSocketFactory. This was rejected because Kafka tries to be language neutral. It was thought it would make it more difficult to support C and Python.

Kafka's naming convention does not use a special tag for interfaces. Accordingly, these interface names were rejected ISslFactory, SslFactoryIFace, SslFactoryInterface.

It was possible to preserve the name SslFactory for the default implementation and use the name PluggableSslFactory for the interface. Since SslFactory was not part of the public API, it was decided we could rename the class and reuse the nicer name for the interface.

The constants SSL_MODE_CONFIG and SSL_VERIFY_KEYSTORE_USING_TRUSTSTORE_CONFIG are not user configurable and therefore must not appear in SslConfigs as ConfigDefs. Declaring the constants in SslConfigs without a ConfigDef would just cause confusion.

The only call to SslFactory.sslContext() is in EchoServer which does not count because it is an internal test. We decided to leave the sslContext() method out of the interface.

Kafka is not consistent to name configs that hold class names. Compare [partitioner.class, interceptor.classes, principal.builder.class, sasl.server.callback.handler.class, sasl.client.callback.handler.class, sasl.login.class] versus [key.deserializer, value.deserializer, key.serializer, value.serializer]. It appears the serializer/deserializer configs are a special case. Therefore the name ssl.sslfactory.class was selected instead of ssl.sslfactory

We could require the Pluggable SSL Factory implementation to have the same 3-argument constructor as the old SslFactory. We find the arguments clientAuthConfigOverride and keystoreVerifiableUsingTruststore are somewhat arbitrary for a general pluggable interface. We prefer to use a default constructor for the pluggable SSL Factory implementation.

We need the ability to send custom configuration options to the PluggableSslFactory implementation. This will be covered in another KIP.


  • No labels