This is an automated email from the ASF dual-hosted git repository.
lizhimins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-dashboard.git
The following commit(s) were added to refs/heads/master by this push:
new 6f56bdd38 fix(k8s): bound the certificate identity fields and the
derived issuer (#6005)
6f56bdd38 is described below
commit 6f56bdd38885aa9648c5ef6ff7673042f502478f
Author: 烤化の初雪 <[email protected]>
AuthorDate: Fri Nov 27 12:12:51 2026 +0800
fix(k8s): bound the certificate identity fields and the derived issuer
(#6005)
---
.../studio/cluster/k8s/K8sCertService.java | 28 +++++++++++++++++-
.../studio/cluster/k8s/K8sCertServiceTest.java | 34 ++++++++++++++++++++++
2 files changed, 61 insertions(+), 1 deletion(-)
diff --git
a/server/src/main/java/org/apache/rocketmq/studio/cluster/k8s/K8sCertService.java
b/server/src/main/java/org/apache/rocketmq/studio/cluster/k8s/K8sCertService.java
index 23cd71b1b..af4fd052e 100644
---
a/server/src/main/java/org/apache/rocketmq/studio/cluster/k8s/K8sCertService.java
+++
b/server/src/main/java/org/apache/rocketmq/studio/cluster/k8s/K8sCertService.java
@@ -19,6 +19,7 @@ package org.apache.rocketmq.studio.cluster.k8s;
import org.apache.rocketmq.studio.common.domain.enums.CertStatus;
import org.apache.rocketmq.studio.common.domain.enums.CertType;
import org.apache.rocketmq.studio.common.exception.BusinessException;
+import org.apache.rocketmq.studio.common.util.TextBounds;
import org.apache.rocketmq.studio.audit.OperationAuditService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
@@ -42,6 +43,11 @@ import java.util.stream.Collectors;
@Slf4j
@Service
public class K8sCertService {
+ /** `issuer VARCHAR(256)`; the other identity fields are VARCHAR(128). */
+ private static final int ISSUER_MAX_LENGTH = 256;
+ private static final String TRUNCATION_MARKER = "...";
+ private static final int IDENTITY_MAX_LENGTH = 128;
+
private static final int EXPIRING_THRESHOLD_DAYS = 30;
@@ -96,7 +102,10 @@ public class K8sCertService {
// renders it in the viewer's zone, matching every other date API.
notBefore =
LocalDateTime.ofInstant(parsed.getNotBefore().toInstant(), ZoneOffset.UTC);
notAfter =
LocalDateTime.ofInstant(parsed.getNotAfter().toInstant(), ZoneOffset.UTC);
- issuer = parsed.getIssuerX500Principal().getName();
+ // The DN is derived from the uploaded PEM, so the caller cannot
shorten it: bound it to
+ // the column (marker included) instead of failing the whole
registration - issuer is
+ // informational, and an enterprise CA DN can exceed 256
characters.
+ issuer = boundedIssuer(parsed.getIssuerX500Principal().getName());
san = extractSubjectAlternativeNames(parsed);
}
@@ -184,6 +193,16 @@ public class K8sCertService {
}
}
+ /**
+ * The derived issuer must fit {@code issuer VARCHAR(256)} - marker
included, so the suffix is
+ * subtracted from the budget instead of overflowing the column (the same
rule
+ * {@code InstanceService} applies to its bounded remark).
+ */
+ static String boundedIssuer(String issuer) {
+ return TextBounds.truncate(issuer, ISSUER_MAX_LENGTH -
TRUNCATION_MARKER.length(),
+ TRUNCATION_MARKER);
+ }
+
private String normalizeOptionalIdentity(String value, String field) {
if (value == null) {
return null;
@@ -192,6 +211,13 @@ public class K8sCertService {
if (normalized.isEmpty()) {
throw new BusinessException(400, "Certificate " + field + " cannot
be blank");
}
+ // k8s_id/cluster are VARCHAR(128), issuer VARCHAR(256); an over-long
value reached the
+ // database and the rejection surfaced as a generic 500.
+ int maxLength = "issuer".equals(field) ? ISSUER_MAX_LENGTH :
IDENTITY_MAX_LENGTH;
+ if (TextBounds.codePointCount(normalized) > maxLength) {
+ throw new BusinessException(400,
+ "Certificate " + field + " must not exceed " + maxLength +
" characters");
+ }
return normalized;
}
diff --git
a/server/src/test/java/org/apache/rocketmq/studio/cluster/k8s/K8sCertServiceTest.java
b/server/src/test/java/org/apache/rocketmq/studio/cluster/k8s/K8sCertServiceTest.java
index 86d2188bf..6c343ac37 100644
---
a/server/src/test/java/org/apache/rocketmq/studio/cluster/k8s/K8sCertServiceTest.java
+++
b/server/src/test/java/org/apache/rocketmq/studio/cluster/k8s/K8sCertServiceTest.java
@@ -367,6 +367,40 @@ class K8sCertServiceTest {
assertThat(result.getIssuer()).isEqualTo("vault");
}
+ @Test
+ void createCertShouldRejectAnIdentityLongerThanItsColumnTest() {
+ CreateCertDTO command = CreateCertDTO.builder()
+ .k8sId("k".repeat(129))
+ .cluster("cluster-a")
+ .type("TLS")
+ .build();
+
+ // k8s_id is VARCHAR(128): letting the value through reached the
database, whose rejection
+ // the API reported as a generic 500 instead of naming the limit.
+ assertThatThrownBy(() -> k8sCertService.createCert(command))
+ .isInstanceOf(BusinessException.class)
+ .hasMessage("Certificate k8sId must not exceed 128 characters")
+ .satisfies(error -> assertThat(((BusinessException)
error).getCode()).isEqualTo(400));
+ verify(k8sCertRepository, never()).save(any());
+ }
+
+ @Test
+ void
aDerivedIssuerLongerThanItsColumnIsMarkedInsteadOfFailingTheRegistrationTest() {
+ // The DN comes out of the uploaded PEM, so the caller cannot shorten
it: an enterprise CA
+ // DN over 256 characters must not make the certificate impossible to
register, but the cut
+ // has to be visible.
+ String derived = "CN=" + "x".repeat(300);
+
+ String bounded = K8sCertService.boundedIssuer(derived);
+
+ // The marker is part of the budget: 256 must fit the column, not 256
plus "...".
+
assertThat(org.apache.rocketmq.studio.common.util.TextBounds.codePointCount(bounded))
+ .isEqualTo(256);
+ assertThat(bounded).endsWith("...");
+ assertThat(bounded).startsWith("CN=");
+
assertThat(K8sCertService.boundedIssuer("CN=short")).isEqualTo("CN=short");
+ }
+
@Test
void createCertShouldRejectInvalidTypeBeforeSave() {
CreateCertDTO command = CreateCertDTO.builder()