Interface ServerTlsCredentialSupplierFactory<C,I>
- Type Parameters:
C- The type of configuration. UseVoidif the credential supplier is not configurable.I- The type of the initialization data passed between factory methods.
A pluggable factory for creating ServerTlsCredentialSupplier instances.
ServerTlsCredentialSupplierFactory implementations are:
- service implementations provided by plugin authors
- called by the proxy runtime to create credential supplier instances
- used to configure how the proxy obtains TLS credentials for server-side connections
The proxy runtime guarantees that:
- instances will be initialized before any attempt to create credential supplier instances,
- instances will eventually be closed if and only if they were successfully initialized,
- no attempts to create credential supplier instances will be made once a factory instance is closed,
- instances will be initialized and closed on the same thread.
Credential supplier creation can happen on a different thread than initialization or cleanup.
It is suggested to pass state using the return value from initialize(ServerTlsCredentialSupplierFactoryContext, Object)
rather than relying on synchronization within a factory implementation.
Lifecycle
1.initialize(ServerTlsCredentialSupplierFactoryContext, Object)- validate config, create shared resources 2.create(ServerTlsCredentialSupplierFactoryContext, Object)- create a single shared supplier instance 3.close(Object)- release resources
Usage Example: Simple File-Based Supplier
@Plugin(configType = FileBasedSupplierConfig.class)
public class FileBasedSupplierFactory
implements ServerTlsCredentialSupplierFactory<FileBasedSupplierConfig, FileBasedSupplierConfig> {
@Override
public FileBasedSupplierConfig initialize(ServerTlsCredentialSupplierFactoryContext context,
FileBasedSupplierConfig config) {
// Validate configuration
FileBasedSupplierConfig validated = Plugins.requireConfig(this, config);
// Verify files exist
if (!Files.exists(validated.keyPath())) {
throw new PluginConfigurationException("Private key file not found: " + validated.keyPath());
}
if (!Files.exists(validated.certPath())) {
throw new PluginConfigurationException("Certificate file not found: " + validated.certPath());
}
return validated;
}
@Override
public ServerTlsCredentialSupplier create(ServerTlsCredentialSupplierFactoryContext context,
FileBasedSupplierConfig config) {
return new FileBasedCredentialSupplier(config.keyPath(), config.certPath());
}
}
public record FileBasedSupplierConfig(
@JsonProperty(required = true) Path keyPath,
@JsonProperty(required = true) Path certPath
) {}
Usage Example: Supplier with Shared Resources
@Plugin(configType = KmsSupplierConfig.class)
public class KmsSupplierFactory
implements ServerTlsCredentialSupplierFactory<KmsSupplierConfig, KmsSupplierFactory.SharedContext> {
record SharedContext(KmsSupplierConfig config, KeyManagementService kms) {}
@Override
public SharedContext initialize(ServerTlsCredentialSupplierFactoryContext context, KmsSupplierConfig config) {
KmsSupplierConfig validated = Plugins.requireConfig(this, config);
// Get KMS plugin instance
KeyManagementService kms = context.pluginInstance(
KeyManagementService.class,
validated.kmsImplementation()
);
return new SharedContext(validated, kms);
}
@Override
public ServerTlsCredentialSupplier create(ServerTlsCredentialSupplierFactoryContext context,
SharedContext sharedContext) {
return new KmsCredentialSupplier(sharedContext.kms(), sharedContext.config());
}
@Override
public void close(SharedContext sharedContext) {
// Clean up KMS resources if needed
if (sharedContext.kms() instanceof AutoCloseable closeable) {
closeable.close();
}
}
}
public record KmsSupplierConfig(
@PluginImplName(KeyManagementService.class) String kmsImplementation,
@PluginImplConfig(implNameProperty = "kmsImplementation") Object kmsConfig,
@JsonProperty(required = true) String keyId
) {}
Configuration Example
Configure a TLS credential supplier in the proxy YAML configuration:
virtualClusters:
demo:
targetCluster:
bootstrap_servers: kafka.example.com:9093
tls:
trust:
storeFile: /path/to/truststore.p12
storePassword:
passwordFile: /path/to/password.txt
# TLS credential supplier configuration
credentialSupplier:
type: FileBasedSupplier # References @Plugin annotation's name
config:
keyPath: /path/to/client-key.pem
certPath: /path/to/client-cert.pem
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptiondefault voidCalled by the runtime to release any resources associated with the giveninitializationData.create(ServerTlsCredentialSupplierFactoryContext context, I initializationData) Creates an instance ofServerTlsCredentialSupplier.initialize(ServerTlsCredentialSupplierFactoryContext context, C config) Initializes the factory with the specified configuration.
-
Method Details
-
initialize
@UnknownNullness I initialize(ServerTlsCredentialSupplierFactoryContext context, @UnknownNullness C config) throws PluginConfigurationException Initializes the factory with the specified configuration.
This method is guaranteed to be called at most once for each credential supplier configuration and before any call to
create(ServerTlsCredentialSupplierFactoryContext, Object). This method may provide extra semantic validation of the config and returns some object (which may be the config itself, or some other object) which will be passed tocreate(ServerTlsCredentialSupplierFactoryContext, Object)andclose(Object).Use this method to:
- Validate the configuration using
Plugins.requireConfig(Object, Object) - Initialize expensive or shared resources (connection pools, caches, etc.)
- Retrieve nested plugin instances via
ServerTlsCredentialSupplierFactoryContext.pluginInstance(Class, String) - Verify external dependencies (files exist, services are reachable, etc.)
- Parameters:
context- The factory context providing access to plugins and runtime resourcesconfig- The configuration (may be null if not configurable)- Returns:
- A configuration state object, specific to the given
config, which will be passed tocreate(ServerTlsCredentialSupplierFactoryContext, Object)andclose(Object) - Throws:
PluginConfigurationException- when the configuration is invalid
- Validate the configuration using
-
create
ServerTlsCredentialSupplier create(ServerTlsCredentialSupplierFactoryContext context, @UnknownNullness I initializationData) Creates an instance of
ServerTlsCredentialSupplier.Called once after initialization to create a shared supplier instance. The returned supplier must be thread-safe as it will be shared across all connections to this virtual cluster.
This can be called on a different thread from
initialize(ServerTlsCredentialSupplierFactoryContext, Object)andclose(Object). Implementors should either use theinitializationDatato pass state frominitialize(ServerTlsCredentialSupplierFactoryContext, Object)or use appropriate synchronization.- Parameters:
context- The factory context providing access to plugins and runtime resourcesinitializationData- The initialization data that was returned frominitialize(ServerTlsCredentialSupplierFactoryContext, Object)- Returns:
- The
ServerTlsCredentialSupplierinstance
-
close
Called by the runtime to release any resources associated with the given
initializationData.This is guaranteed to eventually be called for each successful call to
initialize(ServerTlsCredentialSupplierFactoryContext, Object). Once this method has been called,create(ServerTlsCredentialSupplierFactoryContext, Object)won't be called again.Use this method to clean up resources such as:
- Closing connection pools
- Shutting down executors
- Releasing file handles
- Closing nested plugin instances
- Parameters:
initializationData- The initialization data that was returned frominitialize(ServerTlsCredentialSupplierFactoryContext, Object)
-