Skip to content

fix(k8s): normalize certificate identities on create like on update - #4300

Merged
lizhimins merged 1 commit into
apache:rocketmq-studiofrom
btlqql:codex/btl-k8s-cert-identity-normalization
Sep 15, 2026
Merged

lizhimins merged 1 commit into
apache:rocketmq-studiofrom
btlqql:codex/btl-k8s-cert-identity-normalization

Conversation

@btlqql

@btlqql btlqql commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

What is the purpose of the change

Fixes #4299.

K8sCertService.createCert passed k8sId, cluster and issuer straight from the request into the
stored entity, while updateCert sends the same three fields through normalizeOptionalIdentity
(trim, reject blank with 400 Certificate <field> cannot be blank). A whitespace-only issuer was
therefore accepted and stored padded on create, and could not be reproduced through update.

Brief changelog

  • server/src/main/java/org/apache/rocketmq/studio/cluster/k8s/K8sCertService.java
    • createCert normalises k8sId and cluster with normalizeOptionalIdentity, the helper the
      update path already uses.
    • issuer is normalised the same way when the create carries no certPem; a supplied certificate
      still overrides the submitted issuer/SAN with its parsed values, so the upload flow is unchanged.
  • server/src/test/java/org/apache/rocketmq/studio/cluster/k8s/K8sCertServiceTest.java
    • New createCertShouldRejectBlankIdentityFields, mirroring the existing
      updateCertShouldRejectBlankIdentityFields.
    • New createCertShouldTrimIdentityFieldsLikeUpdateDoes.

Verification

Red, before the fix (mvn -o -f server/pom.xml test -Dtest=K8sCertServiceTest):

[ERROR] Tests run: 20, Failures: 2, Errors: 0, Skipped: 0, Time elapsed: 1.845 s <<< FAILURE! -- in org.apache.rocketmq.studio.cluster.k8s.K8sCertServiceTest
Expecting actual throwable to be an instance of:
but was:
 but was: " new-tls-cert "
[ERROR]   K8sCertServiceTest.createCertShouldRejectBlankIdentityFields:214
Expecting actual throwable to be an instance of:
but was:
[ERROR]   K8sCertServiceTest.createCertShouldTrimIdentityFieldsLikeUpdateDoes:234
[ERROR] Tests run: 20, Failures: 2, Errors: 0, Skipped: 0
[INFO] BUILD FAILURE

Green, after the fix (mvn -o -f server/pom.xml test -Dtest=K8sCertServiceTest,K8sCertControllerTest):

[INFO] Tests run: 11, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 6.850 s -- in org.apache.rocketmq.studio.cluster.k8s.K8sCertControllerTest
[INFO] Tests run: 20, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.723 s -- in org.apache.rocketmq.studio.cluster.k8s.K8sCertServiceTest
[INFO] Tests run: 31, Failures: 0, Errors: 0, Skipped: 0
[INFO] BUILD SUCCESS

K8sCertControllerTest (11 tests) is included because it drives the create/update endpoints end to end
and confirms the certificate-upload path is unaffected.

AI disclosure

Drafted with AI assistance (analysis, patch and test authoring); the red and green Maven output above
was executed and observed locally on Windows, JDK 21.

@RockteMQ-AI RockteMQ-AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Summary

This PR aligns K8sCertService.createCert with updateCert by applying normalizeOptionalIdentity() to k8sId, cluster, and issuer fields on create. Previously, whitespace-only values were silently accepted and stored padded on create, but rejected on update — an asymmetry that could make certificates unfindable by identity.

The certificateSupplied extraction is a clean refactor, and the issuer handling is correct: when a PEM cert is provided, the issuer is derived from the cert itself, so the caller-provided value is irrelevant.

Comprehensive tests cover both blank rejection and whitespace trimming for all three identity fields. LGTM.


Automated review by github-manager-bot

@btlqql

btlqql commented Sep 15, 2026

Copy link
Copy Markdown
Contributor Author

Whole-suite comparison, added for completeness (mvn -o -f server/pom.xml test, unmodified base
rocketmq-studio @ 6c24d2e vs. this branch):

base     Tests run: 2151, Failures: 5, Errors: 5, Skipped: 0
branch   Tests run: 2153, Failures: 5, Errors: 5, Skipped: 0

The two added tests are the new ones; the failing ids are identical on both sides and unrelated to this
change (CliAgentProviderTest / ClaudeCodeAgentProviderTest need a POSIX sh runtime, and the two
AuthCorsIntegrationTest cases are being aligned in #4217).

createCert stored k8sId, cluster and issuer verbatim, so a whitespace-only

issuer was accepted and padded identities were persisted, while updateCert

trims them and rejects a blank value.

(cherry picked from commit 891344f)
@lizhimins
lizhimins force-pushed the codex/btl-k8s-cert-identity-normalization branch from 891344f to 5a6d582 Compare September 15, 2026 13:08
@lizhimins
lizhimins merged commit 156f8d6 into apache:rocketmq-studio Sep 15, 2026
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.

3 participants