Skip to content

HDDS-17879. Certificate subject fails when commonName exceeds 64 characters - #12114

Draft
yandrey321 wants to merge 3 commits into
apache:masterfrom
yandrey321:HDDS-17879
Draft

yandrey321 wants to merge 3 commits into
apache:masterfrom
yandrey321:HDDS-17879

Conversation

@yandrey321

@yandrey321 yandrey321 commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

Problem

Since the Bouncy Castle 1.85 upgrade (HDDS-15974), new X500Name(String) throws when the commonName (CN) is longer than 64 characters, the RFC 5280 ub-common-name limit. Ozone builds the CN as <user>@<FQDN> (scm-sub@<FQDN> and scm@<FQDN> for SCM). On Kubernetes the pod FQDN alone easily exceeds 64 characters, so services fail at startup when they create a certificate signing request (CSR):

java.lang.IllegalArgumentException: commonName length 89 exceeds RFC 5280 ub-common-name (64): 'dn@...svc.cluster.local'
  at org.bouncycastle.asn1.x500.style.BCStyle.encodeStringValue(Unknown Source)
  ...
  at org.apache.hadoop.hdds.security.x509.certificate.utils.CertificateSignRequest.getDistinguishedName(CertificateSignRequest.java:127)

Implementation idea

Keep the current CN whenever it fits in 64 characters. When it doesn't, use <prefix>@<ID>, where the ID is the requester's existing UUID:

Certificate CN when the usual one is longer than 64
Datanode dn@<datanode UUID>
OM om@<OM UUID>
Recon recon@<Recon ID>
SCM sub-CA scm-sub@<SCM ID>
SCM root CA scm@<SCM ID>
  • CertificateSignRequest.commonName(preferred, prefix, id) holds the rule. Every certificate client applies it to its subject.
  • SCM applies the same rule when it signs a CSR from a client without this change. SCMSecurityProtocolServer builds the replacement CN from the UUID in the request: the datanode, OM or node details, or the SCM ID in the CSR's OU for SCM peers. It passes the CN to DefaultApprover.sign, which uses it only when the CSR's CN is longer than 64 characters.
  • The subject is built from typed values (X500NameBuilder) instead of a formatted DN string, so SCM can still read a long CN in a CSR when no replacement is given.
  • ozone repair scm cert recover also finds the SCM certificates by scm-sub@<SCM ID> and scm@<SCM ID>, not only by host name.

Key decisions

  • No truncation. Host names that differ only at the end, such as StatefulSet pods ...-0 and ...-1, would get the same CN. A UUID is unique by construction and stays the same when a pod is rescheduled. Truncation plus a hash would also avoid collisions, but it would be harder to read, and Ozone does not need a unique CN.
  • No change for hosts that fit. Every CN of 64 characters or less is encoded byte for byte as before. Only hosts that fail to start today get a different CN.
  • The CN is not used for identity. TLS peers are verified by the subjectAltName (DNS names and IPs), which is unchanged. user@host was never a valid host name for verification anyway.
  • No configuration option to allow a longer CN, and no rollback of Bouncy Castle to 1.84 (that would undo the 1.85/1.86 security fixes).

Side effects

  • On hosts whose usual CN is longer than 64 characters, the CN shows a UUID instead of the host name. The host name is still in the subjectAltName.
  • Upgrades and rolling upgrades:
    • Existing certificates keep their CN until they are renewed.
    • A client with this change works with an SCM without it, because its CN now parses.
    • An SCM with this change gives a client without it a conformant CN.
    • No protocol or layout change.
  • CertificateServer.requestCertificate and CertificateApprover.sign gain an overload with the replacement CN. The existing signatures remain as default methods.
  • Three public static format helpers that only tests used are removed: CertificateSignRequest.getDistinguishedNameFormat(), getDistinguishedNameFormatWithSN() and SelfSignedCertificate.getNameFormat().

Co-authored-by: Claude Opus 5.5 noreply@anthropic.com

What is the link to the Apache JIRA

https://issues.apache.org/jira/browse/HDDS-17879

How was this patch tested?

Existing tests pass:

Module Test classes Tests
hdds-server-framework TestCertificateSignRequest, TestDefaultCAServer, TestRootCertificate, TestDnCertificateClientInit, TestDefaultCertificateClient, TestDefaultProfile 69
hdds-server-scm TestRootCARotationManager, TestInterSCMGrpcProtocolService 6
ozone-manager TestOmCertificateClientInit 8
ozone-recon TestStorageContainerServiceProviderImpl 11

…xceeds 64 characters

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@yandrey321

Copy link
Copy Markdown
Contributor Author

@smengcl @jojochuang @ss77892 could you please take a look?

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@yandrey321
yandrey321 marked this pull request as draft November 20, 2026 20:44
@yandrey321

Copy link
Copy Markdown
Contributor Author

@ss77892

ss77892 commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

RFC explicitly says that CN should not exceed 64 characters. If older version of BC or Java ignored this fact that doesn't mean that we should make any kind of workarounds there instead of making proper fix. The one that would not use user@hostname as CN if its length exceed 64 characters. For example CN might use the hostname (pod) shortname in this case.

@yandrey321

Copy link
Copy Markdown
Contributor Author

I think we need a stop gap solution and long term plan how to issue certificates that are RFC compliant.

@fatihmete

Copy link
Copy Markdown

FreeIPA handles a similar case: hostnames are limited to 64 characters by default, but can be configured up to 255 characters. It would be helpful to add a similar configuration option, especially for Kubernetes users.

% ipa config-mod --maxhostname 255
  Maximum username length: 32
  Maximum hostname length: 255

link

@ss77892

ss77892 commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

FreeIPA handles a similar case: hostnames are limited to 64 characters by default

That's not the same case. FreeIPA match Linux max host name lenght (64) but allows you to configure it up to 255 as RFC 1035 says. It's still issue certificates with CN under 64 chars making long hostnames short if it's required. Exactly the way I've suggested earlier.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@yandrey321

Copy link
Copy Markdown
Contributor Author

Thanks @ss77892, if we want RFC conformance we need to use some stable name to use in CN instead of the hostname. I checked couple of open source products that do the same, and it seems like the options are:

  1. Leave CN empty if @ exceeds 64 character
  2. Trim FQDN + hash of the full @
  3. Use the hash of FQDN if @ exceeds 64 characters

So I reworked the PR so that every CN stays within 64 characters:

  • Usual CN when it fits: <user>@<FQDN>, unchanged, so no existing cluster with normal host names sees any difference.
  • Longer than 64: <prefix>@<UUID> using the service's existing ID: dn@<datanode UUID>, om@<OM UUID>, recon@<Recon ID>, scm-sub@<SCM ID>, scm@<SCM ID>.
    I didn't shorten the host name itself, because pods in a StatefulSet differ only at the end of the name (...-0, ...-1) and would get the same CN. The UUID is unique and also survives a pod being rescheduled. The host name stays in the subjectAltName, which is what TLS checks.
  • SCM applies the same rule when it signs a request from a client that doesn't have this change yet. Rolling upgrades still end up with conformant certificates, and a new client also works with an older SCM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants