|
@@ -0,0 +1,121 @@
|
|
|
+/**
|
|
|
+ * 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.hdds.scm.server;
|
|
|
+
|
|
|
+import com.google.protobuf.BlockingService;
|
|
|
+import java.io.IOException;
|
|
|
+import java.net.InetSocketAddress;
|
|
|
+import org.apache.hadoop.classification.InterfaceAudience;
|
|
|
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
|
|
|
+import org.apache.hadoop.hdds.protocol.proto.HddsProtos.DatanodeDetailsProto;
|
|
|
+import org.apache.hadoop.hdds.protocol.proto.SCMSecurityProtocolProtos;
|
|
|
+import org.apache.hadoop.hdds.protocolPB.SCMSecurityProtocolPB;
|
|
|
+import org.apache.hadoop.hdds.protocolPB.SCMSecurityProtocolServerSideTranslatorPB;
|
|
|
+import org.apache.hadoop.hdds.scm.HddsServerUtil;
|
|
|
+import org.apache.hadoop.hdds.scm.ScmConfigKeys;
|
|
|
+import org.apache.hadoop.hdds.protocol.SCMSecurityProtocol;
|
|
|
+import org.apache.hadoop.io.IOUtils;
|
|
|
+import org.apache.hadoop.ipc.RPC;
|
|
|
+import org.apache.hadoop.security.KerberosInfo;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+
|
|
|
+/**
|
|
|
+ * The protocol used to perform security related operations with SCM.
|
|
|
+ */
|
|
|
+@KerberosInfo(
|
|
|
+ serverPrincipal = ScmConfigKeys.HDDS_SCM_KERBEROS_PRINCIPAL_KEY)
|
|
|
+@InterfaceAudience.Private
|
|
|
+public class SCMSecurityProtocolServer implements SCMSecurityProtocol {
|
|
|
+
|
|
|
+ private static final Logger LOGGER = LoggerFactory
|
|
|
+ .getLogger(SCMClientProtocolServer.class);
|
|
|
+ private final OzoneConfiguration config;
|
|
|
+ private final StorageContainerManager scm;
|
|
|
+ private final RPC.Server rpcServer;
|
|
|
+ private final InetSocketAddress rpcAddress;
|
|
|
+
|
|
|
+ SCMSecurityProtocolServer(OzoneConfiguration conf,
|
|
|
+ StorageContainerManager scm) throws IOException {
|
|
|
+ this.config = conf;
|
|
|
+ this.scm = scm;
|
|
|
+
|
|
|
+ final int handlerCount =
|
|
|
+ conf.getInt(ScmConfigKeys.OZONE_SCM_SECURITY_HANDLER_COUNT_KEY,
|
|
|
+ ScmConfigKeys.OZONE_SCM_SECURITY_HANDLER_COUNT_DEFAULT);
|
|
|
+ rpcAddress = HddsServerUtil
|
|
|
+ .getScmSecurityInetAddress(conf);
|
|
|
+ // SCM security service RPC service.
|
|
|
+ BlockingService secureProtoPbService =
|
|
|
+ SCMSecurityProtocolProtos.SCMSecurityProtocolService
|
|
|
+ .newReflectiveBlockingService(
|
|
|
+ new SCMSecurityProtocolServerSideTranslatorPB(this));
|
|
|
+ this.rpcServer =
|
|
|
+ StorageContainerManager.startRpcServer(
|
|
|
+ conf,
|
|
|
+ rpcAddress,
|
|
|
+ SCMSecurityProtocolPB.class,
|
|
|
+ secureProtoPbService,
|
|
|
+ handlerCount);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Get SCM signed certificate for DataNode.
|
|
|
+ *
|
|
|
+ * @param dnDetails - DataNode Details.
|
|
|
+ * @param certSignReq - Certificate signing request.
|
|
|
+ * @return byte[] - SCM signed certificate.
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public String getDataNodeCertificate(
|
|
|
+ DatanodeDetailsProto dnDetails,
|
|
|
+ String certSignReq) throws IOException {
|
|
|
+ LOGGER.info("Processing CSR for dn {}, UUID: {}", dnDetails.getHostName(),
|
|
|
+ dnDetails.getUuid());
|
|
|
+ // TODO: Call scm to sign the csr.
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public RPC.Server getRpcServer() {
|
|
|
+ return rpcServer;
|
|
|
+ }
|
|
|
+
|
|
|
+ public InetSocketAddress getRpcAddress() {
|
|
|
+ return rpcAddress;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void start() {
|
|
|
+ LOGGER.info(StorageContainerManager.buildRpcServerStartMessage("Starting"
|
|
|
+ + " RPC server for SCMSecurityProtocolServer.", getRpcAddress()));
|
|
|
+ getRpcServer().start();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void stop() {
|
|
|
+ try {
|
|
|
+ LOGGER.info("Stopping the SCMSecurityProtocolServer.");
|
|
|
+ getRpcServer().stop();
|
|
|
+ } catch (Exception ex) {
|
|
|
+ LOGGER.error("SCMSecurityProtocolServer stop failed.", ex);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void join() throws InterruptedException {
|
|
|
+ LOGGER.trace("Join RPC server for SCMSecurityProtocolServer.");
|
|
|
+ getRpcServer().join();
|
|
|
+ }
|
|
|
+
|
|
|
+}
|