Repository navigation
HDDS-17879. Certificate subject fails when commonName exceeds 64 characters - #12114
yandrey321 wants to merge 3 commits into
Conversation
…xceeds 64 characters Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
|
@smengcl @jojochuang @ss77892 could you please take a look? |
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
|
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. |
|
I think we need a stop gap solution and long term plan how to issue certificates that are RFC compliant. |
|
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. |
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>
|
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:
So I reworked the PR so that every CN stays within 64 characters:
|
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>andscm@<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):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:dn@<datanode UUID>om@<OM UUID>recon@<Recon ID>scm-sub@<SCM ID>scm@<SCM ID>CertificateSignRequest.commonName(preferred, prefix, id)holds the rule. Every certificate client applies it to its subject.SCMSecurityProtocolServerbuilds 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 toDefaultApprover.sign, which uses it only when the CSR's CN is longer than 64 characters.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 recoveralso finds the SCM certificates byscm-sub@<SCM ID>andscm@<SCM ID>, not only by host name.Key decisions
...-0and...-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.user@hostwas never a valid host name for verification anyway.Side effects
CertificateServer.requestCertificateandCertificateApprover.signgain an overload with the replacement CN. The existing signatures remain as default methods.CertificateSignRequest.getDistinguishedNameFormat(),getDistinguishedNameFormatWithSN()andSelfSignedCertificate.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:
TestCertificateSignRequest,TestDefaultCAServer,TestRootCertificate,TestDnCertificateClientInit,TestDefaultCertificateClient,TestDefaultProfileTestRootCARotationManager,TestInterSCMGrpcProtocolServiceTestOmCertificateClientInitTestStorageContainerServiceProviderImpl