yandrey321 opened a new pull request, #12114:
URL: https://github.com/apache/ozone/pull/12114

   ## What changes were proposed in this pull request?
   
   **Problem**
   
   Since the Bouncy Castle 1.85 upgrade (HDDS-15974), `new X500Name(String)` 
throws when the CN is longer than
   64 characters (RFC 5280 ub-common-name). Bouncy Castle has no option to turn 
this check off. Ozone builds every
   certificate subject as a `CN=%s,OU=%s,O=%s[,SERIALNUMBER=%s]` string and 
parses it with that constructor. On
   Kubernetes the datanode CN is `<user>@<pod FQDN>`, which easily exceeds 64 
characters, so the datanode fails at
   startup:
   
   ```
   java.lang.IllegalArgumentException: commonName length 89 exceeds RFC 5280 
ub-common-name (64): '[email protected]'
     at org.bouncycastle.asn1.x500.style.BCStyle.encodeStringValue(Unknown 
Source)
     ...
     at 
org.apache.hadoop.hdds.security.x509.certificate.utils.CertificateSignRequest.getDistinguishedName(CertificateSignRequest.java:127)
   ```
   
   Three places hit the same parser:
   - the CSR on every service (`CertificateSignRequest.generateCSR`);
   - SCM, when it rebuilds the subject while signing (`DefaultApprover.sign` -> 
`getDistinguishedNameWithSN`);
   - the self-signed root CA certificate (`SelfSignedCertificate`).
   
   **Implementation idea**
   
   Build the `X500Name` from typed values with 
`X500NameBuilder.addRDN(ASN1ObjectIdentifier, ASN1Encodable)`.
   That path doesn't call `BCStyle.encodeStringValue`, where the length check 
lives.
   `getDistinguishedName` and `getDistinguishedNameWithSN` now use a shared 
builder helper, and
   `SelfSignedCertificate` now calls `getDistinguishedNameWithSN` instead of 
formatting and parsing the string
   itself.
   
   
   - **Encoding stays byte-identical** to what `BCStyle` produced: CN, OU and O 
are `DERUTF8String`, SERIALNUMBER is
     `DERPrintableString`, and the RDN order is unchanged. Existing 
certificates, and code that compares subjects, are unaffected.
   - **Null IDs are still encoded as `"null"`.** A datanode sends null SCM and 
cluster IDs before registration, `String.format` used to render them as 
`"null"`, and `DefaultApprover` matches on that literal.
   - **The CN is not truncated or hashed.** Either would keep the certificate 
RFC-conformant, but the CN would no longer be the host and every service's 
subject would change. Ozone uses the SAN for peer identity, not the CN.
   
   **Side effects**
   
   - A certificate whose CN is longer than 64 characters is not RFC 
5280-conformant. Java TLS accepted these before 1.85 and still accepts them. 
Behavior is the same as before the Bouncy Castle 1.85 upgrade.
   - A subject value containing `,`, `+`, `=` or a leading `#` is now stored 
literally instead of being parsed as DN syntax. Real subjects (`user@host`, 
hostname, SCM ID) contain none of these.
   - Upgrades: SCM rebuilds the subject when signing, so SCM needs this fix 
too. A fixed datanode still fails against an unfixed SCM.
   
   Co-authored-by: Claude Opus 5.5 <[email protected]>
   
   ## What is the link to the Apache JIRA
   
   https://issues.apache.org/jira/browse/HDDS-17879
   
   ## How was this patch tested?
   
   Unit and integration tests.


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to