ss77892 commented on code in PR #10916:
URL: https://github.com/apache/ozone/pull/10916#discussion_r3716256330


##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/SCMSecurityProtocolServer.java:
##########
@@ -326,7 +334,29 @@ public String getSCMCertificate(ScmNodeDetailsProto 
scmNodeDetails,
     LOGGER.info("Processing CSR for scm {}, nodeId: {}",
         scmNodeDetails.getHostName(), scmNodeDetails.getScmNodeId());
 
-    return getEncodedCertToString(certSignReq, NodeType.SCM);
+    boolean leaderless = !storageContainerManager.checkLeader()
+        && isLeaderlessPrimaryScmSigner(storageContainerManager,
+            
storageContainerManager.getScmHAManager().getRatisServer().triggerNotLeaderException(),
+            isRenew);
+
+    return getEncodedCertToString(certSignReq, NodeType.SCM, leaderless, 
scmNodeDetails.getScmNodeId());
+  }
+
+  /**
+   * Single source of truth for whether this SCM should sign its own 
leaderless bootstrap SCM
+   * certificate: no Ratis leader is known cluster-wide (not merely that this 
node isn't leader),
+   * this is not a renewal, and this SCM hosts the primary root CA.
+   *
+   * @param scm     - the serving StorageContainerManager.
+   * @param nle     - the NotLeaderException produced by the local Ratis 
server, or null.
+   * @param isRenew - whether this request is a certificate renewal.
+   * @return true iff the leaderless SCM-certificate signing path should be 
used.
+   */
+  @VisibleForTesting
+  public static boolean isLeaderlessPrimaryScmSigner(StorageContainerManager 
scm, NotLeaderException nle,
+      boolean isRenew) {
+    return !isRenew && nle != null && nle.getSuggestedLeader() == null

Review Comment:
   Well, for those who never had a certificate, there is a case where the SCM 
requested a certificate and died almost immediately. So, in the we track: since 
the start, there has been no leader elected; the request comes from an existing 
quorum member, and it's not a renewal; and we are the primary SCM. 
   As for the disjoint ID ranges, my idea was just to limit IDs for 
Ratis-issued certificates to something like 1<<62 and use bigger numbers for 
leaderless certificates.  One note: we are not talking about certificates for 
everyone. All this code is for the SCM certificates only, so everything can be 
handled in one place. 



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