yandrey321 commented on code in PR #12114:
URL: https://github.com/apache/ozone/pull/12114#discussion_r4675281215


##########
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/security/x509/certificate/utils/CertificateSignRequest.java:
##########
@@ -106,26 +110,61 @@ private CertificateSignRequest(String subject, String 
scmID, String clusterID,
     this.extensions = extensions;
   }
 
-  public static String getDistinguishedNameFormat() {
-    return DISTINGUISHED_NAME_FORMAT;
-  }
-
-  public static String getDistinguishedNameFormatWithSN() {
-    return DISTINGUISHED_NAME_WITH_SN_FORMAT;
-  }
-
   // used by server side DN regeneration
   public static X500Name getDistinguishedNameWithSN(String subject,
       String scmID, String clusterID, String serialID) {
-    return new X500Name(String.format(DISTINGUISHED_NAME_WITH_SN_FORMAT,
-        subject, scmID, clusterID, serialID));
+    return distinguishedNameBuilder(subject, scmID, clusterID)
+        .addRDN(BCStyle.SERIALNUMBER, new 
DERPrintableString(String.valueOf(serialID)))
+        .build();
   }
 
   // used by client side DN generation
   public static X500Name getDistinguishedName(String subject, String scmID,
       String clusterID) {
-    return new X500Name(String.format(getDistinguishedNameFormat(), subject,
-        scmID, clusterID));
+    return distinguishedNameBuilder(subject, scmID, clusterID).build();
+  }
+
+  /**
+   * The commonName of a certificate subject: {@code preferred} when it fits 
RFC 5280 ub-common-name
+   * ({@value #MAX_COMMON_NAME_LENGTH}), else {@code prefix@id}, e.g. {@code 
dn@<datanode UUID>} for a user@FQDN on
+   * Kubernetes. Truncating {@code preferred} instead could give hosts whose 
names differ only at the end the same
+   * commonName; {@code id} is unique to the requester and does not change 
with its host name.
+   */
+  public static String commonName(String preferred, String prefix, String id) {

Review Comment:
   Thanks for writing this up. Both rules would fix the startup failure, and I 
agree nothing relies on CN uniqueness, since OU, O and SERIALNUMBER keep the 
full DN unique. I'd still like to keep <prefix>@<UUID>:
   
   - One rule that never truncates and doesn't depend on the host name's shape. 
Today's subjects vary: user@FQDN (datanode, Recon), user@host or a bare host 
name (OM, depending on DNS SANs), and scm-sub@ / scm@ (SCM). "First DNS label, 
truncated to 64" behaves differently across these, and truncation is still 
possible for long first labels. <prefix>@<UUID> is always at most 44 characters 
(scm-sub@ plus a 36-character UUID).
   - The ID is the node's identity in Ozone: datanode UUID, OM node UUID, Recon 
ID, SCM ID. A certificate listed by `ozone admin cert list` maps straight to 
`ozone admin datanode list` or the SCM roles output, whatever DNS says. A short 
host name only identifies a pod together with its namespace or domain, which is 
exactly what gets cut.
   - It changes nothing for hosts that work today. The usual CN is kept 
whenever it fits, so only hosts that currently fail to start get a different 
CN, and their host name is still in the subjectAltName, which is what TLS 
checks.
   
   The cost of my approach is the SCM-side plumbing for clients without this 
change: the overloads and the per-RPC ID. Your rule would avoid that, since SCM 
could derive the CN from the CSR alone. I've reduced the plumbing in this 
round: SCM now takes the ID from the request for every RPC (see the 
SCMSecurityProtocolServer thread), and each RPC has a test. If you and @ss77892 
still prefer the host-derived CN, I can switch, but I think the UUID is the 
more predictable choice for operators.
   



-- 
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