Add SSL mutual authentication support for rdci

The RDC API is changed to pass the certificates to the gRPC.

Add the support to add all GPUs in the host to a group. Also before
add a GPU to a group, the RDC API will verify that GPU exists or not.

Add the support to fetch the temperature metrics.

Change-Id: I5857ef03fede233d16e8b2836be120f33172da93
Этот коммит содержится в:
Bill(Shuzhou) Liu
2020-03-10 14:02:05 -04:00
коммит произвёл Chris Freehill
родитель 023de40df7
Коммит 66e4e790c3
20 изменённых файлов: 232 добавлений и 57 удалений
+4 -2
Просмотреть файл
@@ -64,11 +64,13 @@ set(SRC_DIR "${PROJECT_SOURCE_DIR}/rdci/src")
set(INC_DIR "${PROJECT_SOURCE_DIR}/rdci/include")
set(LIB_BOOSTRAP_DIR "${PROJECT_BINARY_DIR}/rdc_libs")
include_directories(${INC_DIR} ${PROJECT_SOURCE_DIR}/include)
include_directories(${INC_DIR} ${PROJECT_SOURCE_DIR}/include
${PROJECT_SOURCE_DIR})
set(RDCI_SRC_LIST "${SRC_DIR}/rdci.cc")
set(RDCI_SRC_LIST ${RDCI_SRC_LIST} "${SRC_DIR}/RdciDisCoverySubSystem.cc")
set(RDCI_SRC_LIST ${RDCI_SRC_LIST} "${SRC_DIR}/RdciDiscoverySubSystem.cc")
set(RDCI_SRC_LIST ${RDCI_SRC_LIST} "${SRC_DIR}/RdciSubSystem.cc")
set(RDCI_SRC_LIST ${RDCI_SRC_LIST} "${PROJECT_SOURCE_DIR}/common/rdc_utils.cc")
message("RDCI_SRC_LIST=${RDCI_SRC_LIST}")
set(RDCI_EXE "rdci")
-49
Просмотреть файл
@@ -1,49 +0,0 @@
/*
Copyright (c) 2019 - present Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#ifndef RDCI_INCLUDE_RDCEXCEPTION_H_
#define RDCI_INCLUDE_RDCEXCEPTION_H_
#include <exception>
#include <string>
#include "rdc/rdc.h"
namespace amd {
namespace rdc {
class RdcException : public std::exception {
public:
RdcException(rdc_status_t error, const std::string description) :
err_(error), desc_(description) {}
rdc_status_t error_code() const noexcept { return err_; }
const char* what() const noexcept override { return desc_.c_str(); }
private:
rdc_status_t err_;
std::string desc_;
};
} // namespace rdc
} // namespace amd
#endif // RDCI_INCLUDE_RDCEXCEPTION_H_
+6
Просмотреть файл
@@ -39,8 +39,14 @@ class RdciSubSystem {
virtual void process() = 0;
virtual ~RdciSubSystem();
protected:
void show_common_usage() const;
rdc_handle_t rdc_handle_;
std::string ip_port_;
bool use_auth_;
std::string root_ca_;
std::string client_cert_;
std::string client_key_;
};
typedef std::shared_ptr<RdciSubSystem> RdciSubSystemPtr;
+10 -11
Просмотреть файл
@@ -23,14 +23,14 @@ THE SOFTWARE.
#include <unistd.h>
#include "rdc_lib/rdc_common.h"
#include "rdc/rdc.h"
#include "RdcException.h"
#include "rdc_lib/RdcException.h"
#include "RdciDiscoverySubSystem.h"
namespace amd {
namespace rdc {
RdciDiscoverySubSystem::RdciDiscoverySubSystem() :show_help_(false) {
RdciDiscoverySubSystem::RdciDiscoverySubSystem() : show_help_(false) {
}
void RdciDiscoverySubSystem::parse_cmd_opts(int argc, char ** argv) {
@@ -38,13 +38,14 @@ void RdciDiscoverySubSystem::parse_cmd_opts(int argc, char ** argv) {
const struct option long_options[] = {
{"host", required_argument, nullptr, HOST_OPTIONS },
{"help", optional_argument, nullptr, 'h' },
{"unauth", optional_argument, nullptr, 'u' },
{ nullptr, 0 , nullptr, 0 }
};
int option_index = 0;
int opt = 0;
while ((opt = getopt_long(argc, argv, "h",
while ((opt = getopt_long(argc, argv, "hu",
long_options, &option_index)) != -1) {
switch (opt) {
case HOST_OPTIONS:
@@ -53,27 +54,25 @@ void RdciDiscoverySubSystem::parse_cmd_opts(int argc, char ** argv) {
case 'h':
show_help_ = true;
return;
case 'u':
use_auth_ = false;
break;
default:
show_help();
throw RdcException(RDC_ST_BAD_PARAMETER,
"Unknown command line options");
}
}
}
void RdciDiscoverySubSystem::show_help() const {
std::cout << " discovery -- Used to discover and identify GPUs "
<< "and their attributes.\n\n";
std::cout << "Usage\n";
std::cout << " rdci discovery [--host <IP/FQDN>:port]\n";
std::cout << " rdci discovery [--host <IP/FQDN>:port] [-u]\n";
std::cout << "\nFlags:\n";
std::cout << " --host <IP/FQDN>:port Connects to "
<< "specified IP or fully-qualified domain name.\n";
std::cout << " The port "
<< "must be specified.\n";
std::cout << " Default: localhost:50051\n";
std::cout << " -h --help Displays usage "
<< "information and exits.\n";
show_common_usage();
}
+76 -5
Просмотреть файл
@@ -20,14 +20,19 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include "RdciSubSystem.h"
#include "RdcException.h"
#include "rdc_lib/RdcException.h"
#include "common/rdc_utils.h"
namespace amd {
namespace rdc {
RdciSubSystem::RdciSubSystem():
rdc_handle_(nullptr)
, ip_port_("localhost:50051") { // default host
, ip_port_("localhost:50051") // default host
, use_auth_(true)
, root_ca_("/etc/rdc/client/certs/rdc_cacert.pem")
, client_cert_("/etc/rdc/client/certs/rdc_client_cert.pem")
, client_key_("/etc/rdc/client/private/rdc_client_cert.key") {
rdc_status_t status = rdc_init(0);
if (status != RDC_ST_OK) {
throw RdcException(status, "RDC initialize fail");
@@ -35,12 +40,79 @@ RdciSubSystem::RdciSubSystem():
}
void RdciSubSystem::connect() {
rdc_status_t status = rdc_connect(ip_port_.c_str(), &rdc_handle_);
rdc_status_t status;
if (use_auth_) {
std::string ca_pem;
std::string client_cert_pem;
std::string client_key_pem;
if (!FileExists(root_ca_.c_str())) {
std::cout << "In order to use the SSL mutual authentication, the "
<< "root CA must be copied to " << root_ca_ << std::endl;
throw RdcException(RDC_ST_BAD_PARAMETER, "root CA not found");
}
int ret = ReadFile(root_ca_, &ca_pem);
if (ret) {
throw RdcException(RDC_ST_BAD_PARAMETER,
std::string("Fail to read root CA at") + root_ca_);
}
if (!FileExists(client_cert_.c_str())) {
std::cout << "In order to use the SSL mutual authentication, the "
<< "client certificate must be copied to "
<< client_cert_ << std::endl;
throw RdcException(RDC_ST_BAD_PARAMETER,
"client cert not found");
}
ret = ReadFile(client_cert_, &client_cert_pem);
if (ret) {
throw RdcException(RDC_ST_BAD_PARAMETER,
std::string("Fail to read client certificate at") + client_cert_);
}
if (!FileExists(client_key_.c_str())) {
std::cout << "In order to use the SSL mutual authentication, the "
<< "client private key must be copied to "
<< client_key_ << std::endl;
throw RdcException(RDC_ST_BAD_PARAMETER,
"client key not found");
}
ret = ReadFile(client_key_, &client_key_pem);
if (ret) {
throw RdcException(RDC_ST_BAD_PARAMETER,
std::string("Fail to read client key at ") + client_key_);
}
status = rdc_connect(ip_port_.c_str(), &rdc_handle_,
ca_pem.c_str(), client_cert_pem.c_str(), client_key_pem.c_str());
} else { // Not use the SSL mutual authentication
status = rdc_connect(ip_port_.c_str(), &rdc_handle_,
nullptr, nullptr, nullptr);
}
if (status != RDC_ST_OK) {
throw RdcException(status, "Fail to setup the connection");
throw RdcException(status,
"Fail to setup the connection. Please check all libraries in right folder");
}
}
void RdciSubSystem::show_common_usage() const {
std::cout << " --host <IP/FQDN>:port Connects to "
<< "specified IP or fully-qualified domain name.\n";
std::cout << " The port "
<< "must be specified.\n";
std::cout << " Default: localhost:50051\n";
std::cout << " -u --unauth Do not use the SSL mutual"
<< " authentication to encrypt the communication\n"
<< " Default: SSL mutual will be"
<< " used. You must copy the root CA to "
<< root_ca_ << "\n"
<< " Client certificate to "
<< client_cert_ << "\n"
<< " Client key to "
<< client_key_ << "\n";
std::cout << " -h --help Displays usage "
<< "information and exits.\n";
}
RdciSubSystem::~RdciSubSystem() {
if (rdc_handle_) {
@@ -51,6 +123,5 @@ RdciSubSystem::~RdciSubSystem() {
rdc_shutdown();
}
} // namespace rdc
} // namespace amd
+1 -1
Просмотреть файл
@@ -24,7 +24,7 @@ THE SOFTWARE.
#include <string>
#include "rdc_lib/rdc_common.h"
#include "rdc/rdc.h"
#include "RdcException.h"
#include "rdc_lib/RdcException.h"
#include "RdciDiscoverySubSystem.h"