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

KAFKA-17921: Support SASL_PLAINTEXT protocol with java.security.auth.login.config #17671

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from

Conversation

FrankYang0529
Copy link
Member

Support SASL_PLAINTEXT protocol in ClusterTest framework.

Committer Checklist (excluded from commit message)

  • Verify design and implementation
  • Verify test coverage and CI build status
  • Verify documentation (including upgrade notes)

Copy link
Member

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

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

@FrankYang0529 thanks for this patch

import java.util.Map;
import java.util.stream.Collectors;

public class JaasModule {
Copy link
Member

Choose a reason for hiding this comment

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

Is this duplicate to core JaasModule?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, this is duplicated. Original JaasModule is in core module. I think we can remove original one after we migrate all sasl test case to new framework. WDYT?

@@ -602,6 +630,9 @@ public void close() throws Exception {
waitForAllFutures(futureEntries);
futureEntries.clear();
Utils.delete(baseDirectory);
if (jaasFile.isPresent()) {
Copy link
Member

Choose a reason for hiding this comment

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

Could you please use ifPresent instead?


import javax.security.auth.login.Configuration;

public class JaasTestUtils {
Copy link
Member

Choose a reason for hiding this comment

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

It is already in xxx.test package, maybe we can call it JaasUtils?

public static final String KAFKA_PLAIN_ADMIN = "plain-admin";
public static final String KAFKA_PLAIN_ADMIN_PASSWORD = "plain-admin-secret";

public static File writeJaasContextsToFile(List<JaasSection> jaasSections) throws IOException {
Copy link
Member

Choose a reason for hiding this comment

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

Do we really need this object? How about using map? It is more simple


private final Map<String, String> entries;

private JaasModule(String name, boolean debug, Map<String, String> entries) {
Copy link
Member

Choose a reason for hiding this comment

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

Could you please try to use record class?

configs.put(SaslConfigs.SASL_JAAS_CONFIG,
String.format("org.apache.kafka.common.security.plain.PlainLoginModule required username=\"%s\" password=\"%s\";",
JaasTestUtils.KAFKA_PLAIN_USER1, JaasTestUtils.KAFKA_PLAIN_USER1_PASSWORD));
try (Admin admin = clusterInstance.admin(configs)) {
Copy link
Member

Choose a reason for hiding this comment

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

Those helper should return authorized client object, right? Otherwise, developers have to configure them manually

@FrankYang0529 FrankYang0529 force-pushed the KAFKA-17921 branch 2 times, most recently from 7e4b4a6 to c9ea0ad Compare December 29, 2024 14:08
Copy link
Member

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

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

@FrankYang0529 thanks for this patch. two minor comments are left PTAL

assertDoesNotThrow(() -> admin.describeAcls(AclBindingFilter.ANY).values().get());
}
String topic = "sasl-plaintext-topic";
Assertions.assertDoesNotThrow(() -> clusterInstance.createTopic(topic, 1, (short) 1));
Copy link
Member

Choose a reason for hiding this comment

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

Since the APIs in question only throw runtime exceptions, there's no need to use assertDoesNotThrow, which is typically employed to convert checked exceptions into runtime exceptions.

}

// client with non-admin credentials
Map<String, Object> nonAdminConfig = Map.of(
Copy link
Member

Choose a reason for hiding this comment

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

the helper methods of clusterInstance should be able configure the sasl.jaas.config automatically - that is why we add those helper to clusterInstance

Copy link
Member Author

Choose a reason for hiding this comment

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

Hi @chia7712, thanks for the review. Yes, we already set default user to admin, consumer, and producer helper function automatically. Here, we would like to test developer overrides sasl.jaas.config with non-admin credentials. We also test overriding with unknown credential, so we can make sure the cluster instance with sasl plaintext works.

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.

2 participants