adoroszlai commented on code in PR #5009:
URL: https://github.com/apache/ozone/pull/5009#discussion_r1250602722


##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java:
##########
@@ -640,6 +638,16 @@ private OzoneManager(OzoneConfiguration conf, 
StartupOption startupOption)
           HddsServerUtil.getSecretKeyClientForOm(conf);
       secretKeyClient = new DefaultSecretKeySignerClient(secretKeyProtocol);
     }
+    serviceInfo = new ServiceInfoProvider(
+        configuration, this, certClient,
+        (certificateClient, config) -> {
+          try {
+            return HAUtils.buildCAList(certificateClient, config);
+          } catch (Exception e) {
+            throw new RuntimeException(e);
+          }
+        });

Review Comment:
   If you change the last parameter of `ServiceInfoProvider` from `BiFunction` 
to `CheckedBiFunction`, then this can be simplified to: `HAUtils::buildCAList`



##########
hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/security/x509/certificate/client/CertificateClient.java:
##########
@@ -126,6 +130,30 @@ X509Certificate getCertificate(String certSerialId)
    */
   Set<X509Certificate> getAllCaCerts();
 
+  /**
+   * This method serves as a convenience to solve the common problem in the
+   * code related to clients, and handle single SCM case and the data with
+   * which we provide one single cert to old clients.
+   * @return either the rootCA certificate, or the sub-CA certificate
+   *          of the node that served as the rootCA during bootstrap.
+   */
+  default String getSingleCACertificatePEM() throws SCMSecurityException {
+    return CertificateCodec.getPEMEncodedString(getSingleCACertificate());
+  }

Review Comment:
   Since this is only used by `ServiceInfoProvider`, which already handles PEM 
encoding for the CA list, I think this method should be omitted.



##########
hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/TestServiceInfoProvider.java:
##########
@@ -0,0 +1,138 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.hadoop.ozone.om;
+
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import 
org.apache.hadoop.hdds.security.x509.certificate.client.CertificateClient;
+import org.apache.hadoop.ozone.om.helpers.ServiceInfo;
+import org.apache.hadoop.ozone.om.helpers.ServiceInfoEx;
+import org.apache.hadoop.ozone.om.protocol.OzoneManagerProtocol;
+import org.junit.Test;

Review Comment:
   It would be nice to implement new tests using JUnit5.



##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ServiceInfoProvider.java:
##########
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.hadoop.ozone.om;
+
+import org.apache.hadoop.hdds.conf.ConfigurationSource;
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.hdds.security.SecurityConfig;
+import 
org.apache.hadoop.hdds.security.x509.certificate.client.CertificateClient;
+import org.apache.hadoop.hdds.security.x509.certificate.utils.CertificateCodec;
+import org.apache.hadoop.ozone.om.helpers.ServiceInfoEx;
+import org.apache.hadoop.ozone.om.protocol.OzoneManagerProtocol;
+import org.slf4j.Logger;
+
+import java.io.IOException;
+import java.security.cert.X509Certificate;
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.function.BiFunction;
+import java.util.function.Function;
+
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * A helper class to handle the construction of
+ * {@link org.apache.hadoop.ozone.om.helpers.ServiceInfoEx} objects,
+ * and refresh of the things that are necessary for constructing it.
+ */
+public final class ServiceInfoProvider {
+
+  private static final Logger LOG = getLogger(ServiceInfoProvider.class);
+
+  private final OzoneManagerProtocol om;
+  private final CertificateClient certificateClient;
+
+  private String caCertPem;
+  private List<String> caCertPemList;
+
+  public ServiceInfoProvider(
+      OzoneConfiguration config,
+      OzoneManagerProtocol om,
+      CertificateClient certificateClient,
+      BiFunction<CertificateClient, ConfigurationSource, List<String>> caList
+  ) throws IOException {
+    this.om = om;
+    if (new SecurityConfig(config).isSecurityEnabled()) {
+      this.certificateClient = certificateClient;
+      caCertPem = certificateClient.getSingleCACertificatePEM();
+      caCertPemList =
+          caList == null ? null : caList.apply(certificateClient, config);
+      certificateClient.registerRootCARotationListener(onRootCAChange());
+    } else {
+      this.certificateClient = null;
+      caCertPem = null;
+      caCertPemList = null;

Review Comment:
   Please use `emptyList()` instead of `null` for `caCertPemList` (in all 
branches).
   
   ```
   om1_1       | java.lang.NullPointerException
   om1_1       |   at 
org.apache.hadoop.ozone.protocolPB.OzoneManagerRequestHandler.getServiceList(OzoneManagerRequestHandler.java:855)
   ```



##########
hadoop-hdds/common/src/test/java/org/apache/hadoop/hdds/security/x509/package-info.java:
##########
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+/**
+ * This package contains common routines used in creating an x509 based 
identity
+ * framework for HDDS.
+ */
+package org.apache.hadoop.hdds.security.x509;
+/*
+
+Architecture of Certificate Infrastructure for SCM.
+====================================================

Review Comment:
   I think this should be a javadoc comment on the package, otherwise most 
people will never see it.  At least I didn't know about it until now. ;)
   
   Also, I don't think we should duplicate this description in yet another 
place, it's already present in:
   
   ```
   
hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/security/x509/package-info.java
   
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/security/x509/package-info.java
   ```
   
   It should be in `common/src/main` only, and the others should refer to it.



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