You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by "merlimat (via GitHub)" <gi...@apache.org> on 2026/10/22 22:38:07 UTC

[PR] [improve][misc] PIP-351: Add options to Pulsar-Test client to support KeyStore based TLS [pulsar]

merlimat opened a new pull request, #27058:
URL: https://github.com/apache/pulsar/pull/27058

   Fixes #22678
   
   Main Issue: #22678
   
   PIP: [PIP-351](https://github.com/apache/pulsar/blob/master/pip/pip-351.md) (#22694)
   
   This picks up #22692 by @shasank112001, which was approved but stalled and now conflicts with
   master. The author's 16 commits are kept as they were, rebased onto current master. My commits on top
   add the V5 client path, which didn't exist when #22692 was written. Supersedes #22692.
   
   ### Motivation
   
   pulsar-perf has no way to configure KeyStore-based TLS. `AuthenticationKeyStoreTls` and other
   keystore-only mTLS setups need `useKeyStoreTls=true` plus truststore and keystore settings on the
   client. `conf/client.conf` already ships `useKeyStoreTls`, `tlsTrustStore*` and `tlsKeyStore*`, but
   pulsar-perf never reads them. PIP-351 adds these options, and it was accepted on dev@
   ([vote](https://lists.apache.org/thread/61l7bdhkjy0vy61934shmh2cphb6pp06)).
   
   Since #22692 was opened, the perf commands have been split into V4 and V5 implementations. The V5
   client takes TLS settings through a `TlsPolicy`, so the options also need to be mapped there.
   
   ### Modifications
   
   From #22692 (@shasank112001):
   - New options in `PerformanceBaseArguments`, as specified in PIP-351, all off by default:
     `--use-keystore-tls`, `--truststore-type`, `--truststore-path`, `--truststore-pass`,
     `--keystore-type`, `--keystore-path`, `--keystore-pass`. Their `descriptionKey`s match the
     `client.conf` keys, so they can also be set from the config file.
   - `validate()` fails if `--use-keystore-tls` is set without `--truststore-path`.
   - `PerfClientUtils` passes the options to the v4 `ClientBuilder` and to `PulsarAdminBuilder`.
   
   On top:
   - V5 client: `createV5ClientBuilderFromArguments` now builds its `TlsPolicy` in a new
     `createV5TlsPolicy(arguments)` method. With `--use-keystore-tls` the policy uses
     `Format.KEYSTORE` with the truststore and keystore settings. Blank keystore path or password
     fields are skipped, so a truststore-only setup works.
   - `wantsTls()` treats `--use-keystore-tls` as a request for TLS, as it already does for
     `--trust-cert-file`. `client.conf` ships `useKeyStoreTls=false`, so this doesn't turn TLS on for
     plaintext runs.
   - Passing both `--use-keystore-tls` and `--trust-cert-file` fails on the V5 path:
     `TlsPolicy.build()` rejects PEM fields on a keystore policy, so the run errors out and neither
     option is silently dropped.
   - Dropped an unrelated whitespace change in `DefaultMessageFormatter`, and fixed checkstyle
     violations in the tests.
   
   ### Verifying this change
   
   - [ ] Make sure that the change passes the CI checks.
   
   This change added tests and can be verified as follows:
     - `PerformanceBaseArgumentsTest`: option parsing, the missing-truststore validation, and loading the
       options from a config file (from #22692).
     - `PerfClientUtilsTest`: mapping onto the v4 client and admin builders, also from a config file
       (from #22692), plus V5 `TlsPolicy` tests for the full keystore case, a truststore-only keystore,
       PEM when keystore TLS is off, and the rejection of `--use-keystore-tls` with `--trust-cert-file`.
   
   ### Does this pull request potentially affect one of the following parts:
   
   *If the box was checked, please highlight the changes*
   
   - [ ] Dependencies (add or upgrade a dependency)
   - [ ] The public API
   - [ ] The schema
   - [ ] The default values of configurations
   - [ ] The threading model
   - [ ] The binary protocol
   - [ ] The REST endpoints
   - [ ] The admin CLI options
   - [ ] The metrics
   - [ ] Anything that affects deployment
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [improve][misc] PIP-351: Add options to Pulsar-Test client to support KeyStore based TLS [pulsar]

Posted by "codelipenghui (via GitHub)" <gi...@apache.org>.
codelipenghui commented on code in PR #27058:
URL: https://github.com/apache/pulsar/pull/27058#discussion_r4356479726


##########
pulsar-testclient/src/main/java/org/apache/pulsar/testclient/PerfClientUtils.java:
##########
@@ -216,6 +205,55 @@ public static PulsarClientBuilder createV5ClientBuilderFromArguments(Performance
         return builder;
     }
 
+    /**
+     * Build the V5 {@link TlsPolicy} from the perf CLI arguments: {@link TlsPolicy.Format#KEYSTORE} material
+     * when {@code --use-keystore-tls} is set (PIP-351), PEM otherwise.
+     *
+     * <p>A keystore policy rejects PEM fields on {@link TlsPolicy.Builder#build()}, so combining
+     * {@code --use-keystore-tls} with {@code --trust-cert-file} fails loudly instead of silently dropping one.
+     *
+     * <p>Package-private for {@code PerfClientUtilsTest} (VisibleForTesting).
+     *
+     * @param arguments the parsed perf-tool arguments
+     * @return the TLS policy for the V5 client
+     */
+    static TlsPolicy createV5TlsPolicy(PerformanceBaseArguments arguments) {
+        TlsPolicy.Builder tls = TlsPolicy.builder();
+        if (arguments.useKeyStoreTls) {
+            tls.format(TlsPolicy.Format.KEYSTORE)
+                    .trustStoreType(arguments.tlsTrustStoreType)
+                    .trustStorePath(arguments.tlsTrustStorePath)
+                    .keyStoreType(arguments.tlsKeyStoreType);
+            if (isNotBlank(arguments.tlsTrustStorePassword)) {
+                tls.trustStorePassword(arguments.tlsTrustStorePassword);
+            }
+            if (isNotBlank(arguments.tlsKeyStorePath)) {
+                tls.keyStorePath(arguments.tlsKeyStorePath);
+            }
+            if (isNotBlank(arguments.tlsKeyStorePassword)) {
+                tls.keyStorePassword(arguments.tlsKeyStorePassword);
+            }
+        }
+        if (isNotBlank(arguments.tlsTrustCertsFilePath)) {
+            tls.trustCertsFilePath(arguments.tlsTrustCertsFilePath);
+        }

Review Comment:
   On the V5 path the PEM trust file is still applied after the format is set to `KEYSTORE`. So `--use-keystore-tls` plus a `tlsTrustCertsFilePath` (for example one already in client.conf) throws from `TlsPolicy.build()`.
   
   The v4 path accepts the same input and uses the keystore: `ClientTlsFactorySupport.clientDefaultPolicy` ignores the PEM trust file when `useKeyStoreTls` is set. `pulsar-client`'s V5 translation (`PulsarClientTool.applyTlsPolicy`) does the same, and PIP-351 describes switching between trust certs and truststore based on `useKeyStoreTls`. As a result, the same command works for `persistent://` topics but fails for `topic://` ones.
   
   Also, for `produce` the exception is raised inside the worker thread (`runProducer` → `createClient`). It is logged as `Got error` and the command still exits 0.
   
   Could we either set `trustCertsFilePath` only when keystore TLS is off, or reject the combination in `validate()` so both client APIs fail up front with a `ParameterException`?



##########
pulsar-testclient/src/main/java/org/apache/pulsar/testclient/PerformanceBaseArguments.java:
##########
@@ -50,6 +50,32 @@ public abstract class PerformanceBaseArguments extends CmdBase{
             descriptionKey = "tlsTrustCertsFilePath")
     public String tlsTrustCertsFilePath = "";
 
+    @Option(names = {"--use-keystore-tls" }, description = "Use KeyStore TLS", descriptionKey = "useKeyStoreTls")
+    public boolean useKeyStoreTls = false;
+
+    @Option(names = {"--truststore-type"}, description = "Type of the truststore, PKCS12 or JKS. The default is JKS.",
+            descriptionKey = "tlsTrustStoreType")
+    public String tlsTrustStoreType = "JKS";
+
+    @Option(names = {"--truststore-path"}, description = "Path to the truststore.",
+            descriptionKey = "tlsTrustStorePath")
+    public String tlsTrustStorePath = "";
+
+    @Option(names = {"--truststore-pass"}, description = "Password to the truststore.",
+            descriptionKey = "tlsTrustStorePassword")
+    public String tlsTrustStorePassword = "";

Review Comment:
   `tlsTrustStorePassword` here and `tlsKeyStorePassword` below are public fields. That puts them in the `Starting Pulsar perf ... with config` JSON that every command logs at INFO (`new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(arguments)` in `PerformanceProducerBase`, `PerformanceConsumerBase`, `PerformanceReaderBase` and `PerformanceTransactionBase`). Both passwords are printed in plaintext, even when they come from client.conf.
   
   `ClientConfigurationData` marks the same fields `@Secret`. Could we annotate these two with `org.apache.pulsar.client.util.Secret` as well? It serializes them as `*****`. A small test that the serialized arguments don't contain the password would keep it that way.



##########
pulsar-testclient/src/main/java/org/apache/pulsar/testclient/PerformanceBaseArguments.java:
##########
@@ -133,6 +159,9 @@ public PerformanceBaseArguments(String cmdName) {
     @Override
     public void validate() throws Exception {
         parseCLI();
+        if (useKeyStoreTls && isBlank(tlsTrustStorePath)) {
+            throw new ParameterException("tlsTrustStorePath is required if useKeystoreTls is used");
+        }

Review Comment:
   Is the truststore really required here? In keystore mode the client works without one. With no `trustStorePath` it falls back to the platform trust store, or trusts all certificates with `--tls-allow-insecure` (`TlsMaterialSource.loadTrustCerts` / `TlsContexts.applyTrust`). `pulsar-client` doesn't require it either.
   
   As written, `--use-keystore-tls --keystore-path client.p12 --tls-allow-insecure` is rejected. If the check stays, could the message name the CLI flags (`--truststore-path` / `--use-keystore-tls`) rather than the config keys?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [improve][misc] PIP-351: Add options to Pulsar-Test client to support KeyStore based TLS [pulsar]

Posted by "merlimat (via GitHub)" <gi...@apache.org>.
merlimat merged PR #27058:
URL: https://github.com/apache/pulsar/pull/27058


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [improve][misc] PIP-351: Add options to Pulsar-Test client to support KeyStore based TLS [pulsar]

Posted by "codelipenghui (via GitHub)" <gi...@apache.org>.
codelipenghui commented on code in PR #27058:
URL: https://github.com/apache/pulsar/pull/27058#discussion_r4360818958


##########
pulsar-testclient/src/main/java/org/apache/pulsar/testclient/PerformanceBaseArguments.java:
##########
@@ -50,6 +51,34 @@ public abstract class PerformanceBaseArguments extends CmdBase{
             descriptionKey = "tlsTrustCertsFilePath")
     public String tlsTrustCertsFilePath = "";
 
+    @Option(names = {"--use-keystore-tls" }, description = "Use KeyStore TLS", descriptionKey = "useKeyStoreTls")
+    public boolean useKeyStoreTls = false;
+
+    @Option(names = {"--truststore-type"}, description = "Type of the truststore, PKCS12 or JKS. The default is JKS.",
+            descriptionKey = "tlsTrustStoreType")
+    public String tlsTrustStoreType = "JKS";
+
+    @Option(names = {"--truststore-path"}, description = "Path to the truststore.",
+            descriptionKey = "tlsTrustStorePath")
+    public String tlsTrustStorePath = "";
+
+    @Option(names = {"--truststore-pass"}, description = "Password to the truststore.",
+            descriptionKey = "tlsTrustStorePassword")
+    @Secret
+    public String tlsTrustStorePassword = "";

Review Comment:
   Thanks for adding `@Secret`. There's one more output path, though. The root `pulsar-perf` command sets `showDefaultValues = true` with `scope = INHERIT`, and the client.conf values act as the picocli defaults. So a password set in client.conf is still printed as `Default: <password>` in usage help.
   
   This happens on `--help`, and also in the usage picocli prints to stderr after a parse error, for example `pulsar-perf conf/client.conf produce` without a topic. `@Secret` only affects the JSON dump.
   
   Adding `showDefaultValue = CommandLine.Help.Visibility.NEVER` to `--truststore-pass` and `--keystore-pass` would keep the passwords out of the help as well.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [improve][misc] PIP-351: Add options to Pulsar-Test client to support KeyStore based TLS [pulsar]

Posted by "merlimat (via GitHub)" <gi...@apache.org>.
merlimat commented on code in PR #27058:
URL: https://github.com/apache/pulsar/pull/27058#discussion_r4356526660


##########
pulsar-testclient/src/main/java/org/apache/pulsar/testclient/PerformanceBaseArguments.java:
##########
@@ -50,6 +50,32 @@ public abstract class PerformanceBaseArguments extends CmdBase{
             descriptionKey = "tlsTrustCertsFilePath")
     public String tlsTrustCertsFilePath = "";
 
+    @Option(names = {"--use-keystore-tls" }, description = "Use KeyStore TLS", descriptionKey = "useKeyStoreTls")
+    public boolean useKeyStoreTls = false;
+
+    @Option(names = {"--truststore-type"}, description = "Type of the truststore, PKCS12 or JKS. The default is JKS.",
+            descriptionKey = "tlsTrustStoreType")
+    public String tlsTrustStoreType = "JKS";
+
+    @Option(names = {"--truststore-path"}, description = "Path to the truststore.",
+            descriptionKey = "tlsTrustStorePath")
+    public String tlsTrustStorePath = "";
+
+    @Option(names = {"--truststore-pass"}, description = "Password to the truststore.",
+            descriptionKey = "tlsTrustStorePassword")
+    public String tlsTrustStorePassword = "";

Review Comment:
   Annotated `tlsTrustStorePassword` and `tlsKeyStorePassword` with `@Secret`, so they now serialize as `*****`, and added `PerformanceBaseArgumentsTest.testStorePasswordsAreMaskedInLoggedConfig` (7393fa6c34).
   
   _🤖 Addressed by [Claude Code](https://claude.com/claude-code)_



##########
pulsar-testclient/src/main/java/org/apache/pulsar/testclient/PerfClientUtils.java:
##########
@@ -216,6 +205,55 @@ public static PulsarClientBuilder createV5ClientBuilderFromArguments(Performance
         return builder;
     }
 
+    /**
+     * Build the V5 {@link TlsPolicy} from the perf CLI arguments: {@link TlsPolicy.Format#KEYSTORE} material
+     * when {@code --use-keystore-tls} is set (PIP-351), PEM otherwise.
+     *
+     * <p>A keystore policy rejects PEM fields on {@link TlsPolicy.Builder#build()}, so combining
+     * {@code --use-keystore-tls} with {@code --trust-cert-file} fails loudly instead of silently dropping one.
+     *
+     * <p>Package-private for {@code PerfClientUtilsTest} (VisibleForTesting).
+     *
+     * @param arguments the parsed perf-tool arguments
+     * @return the TLS policy for the V5 client
+     */
+    static TlsPolicy createV5TlsPolicy(PerformanceBaseArguments arguments) {
+        TlsPolicy.Builder tls = TlsPolicy.builder();
+        if (arguments.useKeyStoreTls) {
+            tls.format(TlsPolicy.Format.KEYSTORE)
+                    .trustStoreType(arguments.tlsTrustStoreType)
+                    .trustStorePath(arguments.tlsTrustStorePath)
+                    .keyStoreType(arguments.tlsKeyStoreType);
+            if (isNotBlank(arguments.tlsTrustStorePassword)) {
+                tls.trustStorePassword(arguments.tlsTrustStorePassword);
+            }
+            if (isNotBlank(arguments.tlsKeyStorePath)) {
+                tls.keyStorePath(arguments.tlsKeyStorePath);
+            }
+            if (isNotBlank(arguments.tlsKeyStorePassword)) {
+                tls.keyStorePassword(arguments.tlsKeyStorePassword);
+            }
+        }
+        if (isNotBlank(arguments.tlsTrustCertsFilePath)) {
+            tls.trustCertsFilePath(arguments.tlsTrustCertsFilePath);
+        }

Review Comment:
   Switched the V5 path to the v4 behavior: `trustCertsFilePath` is now set only when keystore TLS is off, so `--use-keystore-tls` with a PEM trust file uses the keystore on both client APIs. The rejection test is replaced by `v5TlsPolicyKeyStoreTlsIgnoresTrustCertFile` (7393fa6c34).
   
   _🤖 Addressed by [Claude Code](https://claude.com/claude-code)_



##########
pulsar-testclient/src/main/java/org/apache/pulsar/testclient/PerformanceBaseArguments.java:
##########
@@ -133,6 +159,9 @@ public PerformanceBaseArguments(String cmdName) {
     @Override
     public void validate() throws Exception {
         parseCLI();
+        if (useKeyStoreTls && isBlank(tlsTrustStorePath)) {
+            throw new ParameterException("tlsTrustStorePath is required if useKeystoreTls is used");
+        }

Review Comment:
   Agreed, and PIP-351 doesn't require it either. I removed the check, so `--use-keystore-tls` without `--truststore-path` now passes validation. The config-file test now asserts this (7393fa6c34).
   
   _🤖 Addressed by [Claude Code](https://claude.com/claude-code)_



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [improve][misc] PIP-351: Add options to Pulsar-Test client to support KeyStore based TLS [pulsar]

Posted by "merlimat (via GitHub)" <gi...@apache.org>.
merlimat commented on code in PR #27058:
URL: https://github.com/apache/pulsar/pull/27058#discussion_r4360859323


##########
pulsar-testclient/src/main/java/org/apache/pulsar/testclient/PerformanceBaseArguments.java:
##########
@@ -50,6 +51,34 @@ public abstract class PerformanceBaseArguments extends CmdBase{
             descriptionKey = "tlsTrustCertsFilePath")
     public String tlsTrustCertsFilePath = "";
 
+    @Option(names = {"--use-keystore-tls" }, description = "Use KeyStore TLS", descriptionKey = "useKeyStoreTls")
+    public boolean useKeyStoreTls = false;
+
+    @Option(names = {"--truststore-type"}, description = "Type of the truststore, PKCS12 or JKS. The default is JKS.",
+            descriptionKey = "tlsTrustStoreType")
+    public String tlsTrustStoreType = "JKS";
+
+    @Option(names = {"--truststore-path"}, description = "Path to the truststore.",
+            descriptionKey = "tlsTrustStorePath")
+    public String tlsTrustStorePath = "";
+
+    @Option(names = {"--truststore-pass"}, description = "Password to the truststore.",
+            descriptionKey = "tlsTrustStorePassword")
+    @Secret
+    public String tlsTrustStorePassword = "";

Review Comment:
   Added `showDefaultValue = Visibility.NEVER` to `--truststore-pass` and `--keystore-pass`. A new test, `PerformanceBaseArgumentsTest.testStorePasswordsAreHiddenInUsageHelp`, renders the help with the passwords as client.conf defaults and checks they don't appear (aa58bb3026).
   
   _🤖 Addressed by [Claude Code](https://claude.com/claude-code)_



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org