From f21b371c433862174debd135ce1f3b9c04803bf4 Mon Sep 17 00:00:00 2001 From: Matheus Oliveira <99829531+omatheusmesmo@users.noreply.github.com> Date: Sat, 31 Oct 2026 12:31:27 -0300 Subject: [PATCH] fix(msk): default EncryptionInTransit clientBroker to TLS (#7054) CreateCluster that omit EncryptionInfo or clientBroker described TLS_PLAINTEXT, but the MSK API and CloudFormation schema both name the default as TLS. An explicitly supplied value still echoes as shipped. Closes #6968 Signed-off-by: Matheus Oliveira Co-authored-by: Priamo Germosen <6233424+pgermosen@users.noreply.github.com> --- docs/services/msk.md | 4 +-- .../floci/services/msk/MskService.java | 4 +-- .../msk/MskControllerIntegrationTest.java | 29 +++++++++++++++-- .../floci/services/msk/MskServiceTest.java | 32 +++++++++++++++++-- 4 files changed, 61 insertions(+), 8 deletions(-) diff --git a/docs/services/msk.md b/docs/services/msk.md index eb9fd28fd6..40cb926578 100644 --- a/docs/services/msk.md +++ b/docs/services/msk.md @@ -78,7 +78,7 @@ Two details worth knowing: `configurationRevision`, which is where the Terraform AWS provider reads it from. - Members AWS defaults server-side are defaulted here too, so a `terraform plan` converges: `enhancedMonitoring` becomes `DEFAULT`, and `encryptionInfo.encryptionInTransit` becomes - `clientBroker: TLS_PLAINTEXT` / `inCluster: true` when the request omits them. + `clientBroker: TLS` / `inCluster: true` when the request omits them. ### Serverless clusters @@ -116,7 +116,7 @@ Cluster and configuration tags are managed through `/v1/tags/{resourceArn}` Configuration tags are reachable only through the tag endpoints, because AWS's `DescribeConfiguration` response has no tags member. -### SCRAM Secrets Association +### SCRAM Secrets Association Manages credentials only: the broker does not enable SASL authentication or validate these users when clients connect. Clients can still connect without diff --git a/src/main/java/io/github/hectorvent/floci/services/msk/MskService.java b/src/main/java/io/github/hectorvent/floci/services/msk/MskService.java index 8849655a67..ab35ffa0a6 100644 --- a/src/main/java/io/github/hectorvent/floci/services/msk/MskService.java +++ b/src/main/java/io/github/hectorvent/floci/services/msk/MskService.java @@ -52,7 +52,7 @@ public class MskService implements ResourceProvider { private static final Logger LOG = Logger.getLogger(MskService.class); private static final String DEFAULT_KAFKA_VERSION = "3.6.0"; private static final String DEFAULT_ENHANCED_MONITORING = "DEFAULT"; - private static final String DEFAULT_CLIENT_BROKER_ENCRYPTION = "TLS_PLAINTEXT"; + private static final String DEFAULT_CLIENT_BROKER_ENCRYPTION = "TLS"; private static final String PROVISIONED_CLUSTER_TYPE = "PROVISIONED"; private static final String SERVERLESS_CLUSTER_TYPE = "SERVERLESS"; private static final int MAX_PAGE = 100; @@ -305,7 +305,7 @@ public class MskService implements ResourceProvider { /** * Fills in the encryption-in-transit defaults AWS applies when CreateCluster omits them: - * {@code clientBroker} defaults to TLS_PLAINTEXT and {@code inCluster} to true. An + * {@code clientBroker} defaults to TLS and {@code inCluster} to true. An * explicitly supplied value is never overwritten. {@code encryptionAtRest} is left alone - * real MSK creates a KMS key for you there, which the emulator has no equivalent of, so * inventing an ARN would be worse than omitting the member. diff --git a/src/test/java/io/github/hectorvent/floci/services/msk/MskControllerIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/msk/MskControllerIntegrationTest.java index 39172da866..7bde32fb5d 100644 --- a/src/test/java/io/github/hectorvent/floci/services/msk/MskControllerIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/msk/MskControllerIntegrationTest.java @@ -228,10 +228,35 @@ class MskControllerIntegrationTest { .then() .statusCode(200) .body("clusterInfo.enhancedMonitoring", equalTo("DEFAULT")) - .body("clusterInfo.encryptionInfo.encryptionInTransit.clientBroker", equalTo("TLS_PLAINTEXT")) + .body("clusterInfo.encryptionInfo.encryptionInTransit.clientBroker", equalTo("TLS")) .body("clusterInfo.encryptionInfo.encryptionInTransit.inCluster", equalTo(true)); } + // An explicitly requested clientBroker is echoed as-is, including TLS_PLAINTEXT, which is + // now different from the default rather than the default itself. + @Test + void createClusterV1EchoesAnExplicitEncryptionInTransitClientBroker() { + String clusterArn = given() + .contentType("application/json") + .body(""" + {"clusterName": "v1-explicit-client-broker-test", "kafkaVersion": "3.6.0", + "numberOfBrokerNodes": 1, + "encryptionInfo": {"encryptionInTransit": {"clientBroker": "TLS_PLAINTEXT"}}} + """) + .when() + .post("/v1/clusters") + .then() + .statusCode(200) + .extract().path("clusterArn"); + + given() + .when() + .get("/v1/clusters/{clusterArn}", clusterArn) + .then() + .statusCode(200) + .body("clusterInfo.encryptionInfo.encryptionInTransit.clientBroker", equalTo("TLS_PLAINTEXT")); + } + // The v2 ClusterInfo is not the flat v1 shape: everything provisioned-specific nests under // "provisioned", which is the only place an AWS SDK v2 client looks for it. @Test @@ -1345,7 +1370,7 @@ class MskControllerIntegrationTest { .header("X-Amz-Target", "secretsmanager.CreateSecret") .body(Map.of( "Name", "AmazonMSK_" + UUID.randomUUID(), - "KmsKeyId", createScramKey(), + "KmsKeyId", createScramKey(), "SecretString", "{\"username\":\"alice\",\"password\":\"password\"}") ) .when() diff --git a/src/test/java/io/github/hectorvent/floci/services/msk/MskServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/msk/MskServiceTest.java index 1b15025c89..e5b62dfd0c 100644 --- a/src/test/java/io/github/hectorvent/floci/services/msk/MskServiceTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/msk/MskServiceTest.java @@ -81,7 +81,7 @@ class MskServiceTest { config = Mockito.mock(EmulatorConfig.class); EmulatorConfig.ServicesConfig servicesConfig = Mockito.mock(EmulatorConfig.ServicesConfig.class); EmulatorConfig.MskServiceConfig mskConfig = Mockito.mock(EmulatorConfig.MskServiceConfig.class); - + when(config.services()).thenReturn(servicesConfig); when(servicesConfig.msk()).thenReturn(mskConfig); when(mskConfig.mock()).thenReturn(true); @@ -373,10 +373,38 @@ class MskServiceTest { MskCluster cluster = mskService.createCluster(request); assertEquals("DEFAULT", cluster.getEnhancedMonitoring()); - assertEquals("TLS_PLAINTEXT", cluster.getEncryptionInfo().getEncryptionInTransit().getClientBroker()); + assertEquals("TLS", cluster.getEncryptionInfo().getEncryptionInTransit().getClientBroker()); assertTrue(cluster.getEncryptionInfo().getEncryptionInTransit().getInCluster()); } + @Test + void createClusterDefaultsClientBrokerWhenOnlySomeEncryptionMembersAreAbsent() { + EncryptionInfo onlyEncryptionInfo = new EncryptionInfo(); + CreateClusterRequest withoutTransit = new CreateClusterRequest(); + withoutTransit.setClusterName("partial-encryption-no-transit-cluster"); + withoutTransit.setKafkaVersion("3.6.0"); + withoutTransit.setEncryptionInfo(onlyEncryptionInfo); + + MskCluster withoutTransitCluster = mskService.createCluster(withoutTransit); + + assertEquals("TLS", withoutTransitCluster.getEncryptionInfo().getEncryptionInTransit().getClientBroker()); + assertTrue(withoutTransitCluster.getEncryptionInfo().getEncryptionInTransit().getInCluster()); + + EncryptionInTransit onlyInCluster = new EncryptionInTransit(); + onlyInCluster.setInCluster(false); + EncryptionInfo withoutClientBroker = new EncryptionInfo(); + withoutClientBroker.setEncryptionInTransit(onlyInCluster); + CreateClusterRequest noClientBroker = new CreateClusterRequest(); + noClientBroker.setClusterName("partial-encryption-no-client-broker-cluster"); + noClientBroker.setKafkaVersion("3.6.0"); + noClientBroker.setEncryptionInfo(withoutClientBroker); + + MskCluster withoutClientBrokerCluster = mskService.createCluster(noClientBroker); + + assertEquals("TLS", withoutClientBrokerCluster.getEncryptionInfo().getEncryptionInTransit().getClientBroker()); + assertFalse(withoutClientBrokerCluster.getEncryptionInfo().getEncryptionInTransit().getInCluster()); + } + @Test void createClusterDoesNotOverrideExplicitlyRequestedEncryptionInTransit() { CreateClusterRequest request = new CreateClusterRequest();