Closed rhauch closed 19 hours ago
Several builds failed with OOM errors when trying to start the Apicurio container during our tests. Disabling the Apicurio dev services that starts an Apicurio container during testing worked, and will be fixed separately with #156.
Also, we should consider upgrading the CI machine types (#155), since we're clearly getting close to the limit of our CI machine types. Disabling the Apicurio container will help in the short term, but we'll soon be adding other containers for CP.
I've done some manual testing with quarkus:dev
and native executable by using the REST API to create a direct connection that uses a CCloud cluster with API key and secret, and have verified the admin client and consumer clients are built correctly and will successfully work with the remote cluster.
There are a few shortcuts taken for direct connections that will be addressed in subsequent PR as part of #123:
status
for direct connections is not accurate or useful, and will have to use an AdminClient and SR client to verify the credentials and update the status.kafka_cluster.id
and schema_registry.id
are currently optional in the OpenAPI spec but are required until we can obtain the cluster ID of the remote system and verify it matches. The RealDirectFetcher
will need to perform a describe-cluster using the admin client, and set the cluster ID. (We might consider remove the id
fields from the connection spec, if we always get a good ID from the describe-cluster.)I've updated the PR description, and I think this PR is in state that's ready to be merged, pending approval.
Summary of Changes
Resolves #124
Adds basic and API key+secret credentials to direct connections, including validating the credentials in the Connections API and using credentials when connecting to the Kafka cluster and SR defined in the direct connection spec.
New Credentials types
The
Credentials
interface andBasicCredentials
andApiKeyAndSecret
record types have methods that build the auth-related configuration properties for Kafka clients and SR clients. Each concreteCredentials
type customizes the logic, though parameters are used to supply information not in theCredentials
objects.The
Credentials
interface defines three methods that will likely be overridden by each concrete subtype:kafkaClientProperties(...)
-- Construct the auth-related Kafka client configuration properties. The method parameter defines connectivity options that might affect these properties.schemaRegistryClientProperties(...)
-- Construct the auth-related SR client configuration properties. The method parameter defines connectivity options that might affect these properties.httpClientHeaders(...)
-- Construct the auth-related HTTP headers.New Redactable types for write-only objects
The
BasicCredentials
has apassword
field, and theApiKeyAndSecret
record type has aapi_secret
field. Because these fields will contain secrets, they must ensure that these fields are always masked (e.g.,********
) when written to the log or in API responses.To do this, this PR defines a new
Password
class andApiSecret
class that extend a newRedactable
abstract class representing any literal String value that must be redacted in all API responses and never logged in messages (or output by the sidecar). These are essentially write-only values that prevent external reads. TheRedactable
class includes a custom serializer that always writes a masked representation consisting of exactly eight asterisk (*
) characters regardless of the actual literal value. ThetoString()
method also outputs the same masked representation, primarily to help prevent sensitive literal values from being included in logs or exception messages. There are also a few methods that can be used in validating, such as checking whether the value is empty or longer than some size. ThehashCode()
andequals()
methods never use the value. All of these methods are marked as final to ensure subclasses do not alter the behavior.)Building Kafka and SR client configurations
The logic to build the complete configurations for the Kafka admin, consumer and producer clients and the Schema Registry clients are moved into a new
ClientConfigurator
bean that is@ApplicationScoped
. These methods rely upon theCredentials
methods for the auth-related config properties and theKafkaCluster
orSchemaRegistry
cluster for the remaining configuration properties.The
ClientConfigurator
bean’s methods have a boolean parameter as to whether the resulting configuration should redact secrets, so that the configuration can be expose the connection properties to the user, say to allow them to copy the connection properties and use them in their application, or if we use the generated (but redacted) connection configs in the template service. But theAdminClients
,KafkaProducerClients
,KafkaConsumerFactory
andSchemaRegistryClients
beans use the configurator and do not redact the configuration.New methods have been added to the
ConnectionState
class to make it easy to get theCredentials
for a Kafka cluster with a given ID or a Schema Registry cluster with a given ID. TheDirectConnectionState
subclass always returns the credentials for the one Kafka cluster or one SR cluster. In the future, otherConnectionState
subclasses (e.g., for CP MDS) might need to maintain a map of credentials by cluster ID for any clusters do not have the same MDS credentials (e.g., the Kafka or SR cluster does not delegate authN functionality to MDS).Adding other types of credentials in the future
In the future, the only thing we need to do to support other types of authN credentials, such as OAuth 2.0, mTLS, Kerberos (SASL/GSSAPI), etc., is to define new
Credentials
subtypes and implement the methods to construct the auth-related client properties using the subtype-specific credential information.Limitations
There are a few shortcuts taken for direct connections that will be addressed in subsequent PR as part of #123:
status
for direct connections is not accurate or useful, and will have to use an AdminClient and SR client to verify the credentials and update the status.kafka_cluster.id
andschema_registry.id
are currently optional in the OpenAPI spec but are required until we can obtain the cluster ID of the remote system and verify it matches. TheRealDirectFetcher
will need to perform a describe-cluster using the admin client, and set the cluster ID. (We might consider remove theid
fields from the connection spec, if we always get a good ID from the describe-cluster.)Testing
I've done some manual testing with
quarkus:dev
and native executable by using the REST API to create a direct connection that uses a CCloud cluster with API key and secret, and have verified the admin client and consumer clients are built correctly and will successfully work with the remote cluster.Pull request checklist
Please check if your PR fulfills the following (if applicable):