added support for self signed TLS certificates
This commit is contained in:
parent
8e0bca9dd8
commit
e949dd6451
4
Cargo.lock
generated
4
Cargo.lock
generated
@ -1495,7 +1495,9 @@ version = "0.23.20"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "5065c3f250cbd332cd894be57c40fa52387247659b14a2d6041d121547903b1b"
|
checksum = "5065c3f250cbd332cd894be57c40fa52387247659b14a2d6041d121547903b1b"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"log",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
|
"ring",
|
||||||
"rustls-pki-types",
|
"rustls-pki-types",
|
||||||
"rustls-webpki",
|
"rustls-webpki",
|
||||||
"subtle",
|
"subtle",
|
||||||
@ -1916,8 +1918,10 @@ dependencies = [
|
|||||||
"percent-encoding",
|
"percent-encoding",
|
||||||
"pin-project",
|
"pin-project",
|
||||||
"prost",
|
"prost",
|
||||||
|
"rustls-pemfile",
|
||||||
"socket2",
|
"socket2",
|
||||||
"tokio",
|
"tokio",
|
||||||
|
"tokio-rustls",
|
||||||
"tokio-stream",
|
"tokio-stream",
|
||||||
"tower 0.4.13",
|
"tower 0.4.13",
|
||||||
"tower-layer",
|
"tower-layer",
|
||||||
|
@ -19,7 +19,7 @@ prost-types = "0.13.4"
|
|||||||
rand = "0.8.5"
|
rand = "0.8.5"
|
||||||
tokio = { version = "1.42.0", features = ["macros", "rt-multi-thread"] }
|
tokio = { version = "1.42.0", features = ["macros", "rt-multi-thread"] }
|
||||||
tokio-stream = "0.1.17"
|
tokio-stream = "0.1.17"
|
||||||
tonic = "0.12"
|
tonic = { version = "0.12", features = ["tls"] }
|
||||||
serde_json = "1.0.135"
|
serde_json = "1.0.135"
|
||||||
bs58 = "0.5.1"
|
bs58 = "0.5.1"
|
||||||
chrono = "0.4.39"
|
chrono = "0.4.39"
|
||||||
|
@ -45,7 +45,7 @@ pub enum InterfaceType {
|
|||||||
#[derive(Deserialize, Debug)]
|
#[derive(Deserialize, Debug)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
pub owner_wallet: String,
|
pub owner_wallet: String,
|
||||||
pub brain_url: String,
|
pub network: String,
|
||||||
pub max_cores_per_vm: usize,
|
pub max_cores_per_vm: usize,
|
||||||
pub max_vcpu_reservation: usize,
|
pub max_vcpu_reservation: usize,
|
||||||
pub max_mem_reservation_mb: usize,
|
pub max_mem_reservation_mb: usize,
|
||||||
|
@ -5,6 +5,9 @@ use log::{info, warn};
|
|||||||
use sha2::{Digest, Sha256};
|
use sha2::{Digest, Sha256};
|
||||||
use std::{fs::File, io::Read, io::Write};
|
use std::{fs::File, io::Read, io::Write};
|
||||||
|
|
||||||
|
pub(crate) const DETEE_ROOT_CA: &str = "/etc/detee/root_ca.pem";
|
||||||
|
pub(crate) const BRAIN_STAGING: (&str, &str) = ("https://159.65.58.38:31337", "staging-brain");
|
||||||
|
pub(crate) const BRAIN_TESTING: (&str, &str) = ("https://164.92.249.180:31337", "testing-brain");
|
||||||
pub(crate) const VM_BOOT_DIR: &str = "/var/lib/detee/boot/";
|
pub(crate) const VM_BOOT_DIR: &str = "/var/lib/detee/boot/";
|
||||||
pub(crate) const USED_RESOURCES: &str = "/etc/detee/daemon/used_resources.yaml";
|
pub(crate) const USED_RESOURCES: &str = "/etc/detee/daemon/used_resources.yaml";
|
||||||
pub(crate) const VM_CONFIG_DIR: &str = "/etc/detee/daemon/vms/";
|
pub(crate) const VM_CONFIG_DIR: &str = "/etc/detee/daemon/vms/";
|
||||||
|
28
src/grpc.rs
28
src/grpc.rs
@ -10,16 +10,36 @@ use tokio::{
|
|||||||
task::JoinSet,
|
task::JoinSet,
|
||||||
};
|
};
|
||||||
use tokio_stream::{wrappers::ReceiverStream, StreamExt};
|
use tokio_stream::{wrappers::ReceiverStream, StreamExt};
|
||||||
use tonic::transport::Channel;
|
use tonic::transport::{Certificate, Channel, ClientTlsConfig};
|
||||||
|
|
||||||
pub mod snp_proto {
|
pub mod snp_proto {
|
||||||
pub use detee_shared::vm_proto::*;
|
pub use detee_shared::vm_proto::*;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn client(network: &str) -> Result<BrainVmDaemonClient<Channel>> {
|
||||||
|
let (brain_url, brain_san) = match network {
|
||||||
|
"staging" => BRAIN_STAGING,
|
||||||
|
"testnet" => BRAIN_TESTING,
|
||||||
|
_ => {
|
||||||
|
return Err(anyhow::anyhow!(
|
||||||
|
"The only networks currently supported are staging and testnet."
|
||||||
|
))
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let pem = std::fs::read_to_string(DETEE_ROOT_CA)?;
|
||||||
|
let ca = Certificate::from_pem(pem);
|
||||||
|
|
||||||
|
let tls = ClientTlsConfig::new().ca_certificate(ca).domain_name(brain_san);
|
||||||
|
|
||||||
|
let channel = Channel::from_shared(brain_url.to_string())?.tls_config(tls)?.connect().await?;
|
||||||
|
|
||||||
|
Ok(BrainVmDaemonClient::new(channel))
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn register_node(config: &crate::config::Config) -> Result<Vec<VmContract>> {
|
pub async fn register_node(config: &crate::config::Config) -> Result<Vec<VmContract>> {
|
||||||
use tonic::metadata::AsciiMetadataValue;
|
use tonic::metadata::AsciiMetadataValue;
|
||||||
use tonic::Request;
|
use tonic::Request;
|
||||||
let mut client = BrainVmDaemonClient::connect(config.brain_url.clone()).await?;
|
let mut client = client(&config.network).await?;
|
||||||
debug!("Starting node registration...");
|
debug!("Starting node registration...");
|
||||||
let ip_info = IP_INFO.clone();
|
let ip_info = IP_INFO.clone();
|
||||||
let req = RegisterVmNodeReq {
|
let req = RegisterVmNodeReq {
|
||||||
@ -109,14 +129,14 @@ async fn send_messages(
|
|||||||
|
|
||||||
pub struct ConnectionData {
|
pub struct ConnectionData {
|
||||||
pub contracts: Vec<String>,
|
pub contracts: Vec<String>,
|
||||||
pub brain_url: String,
|
pub network: String,
|
||||||
pub brain_msg_tx: Sender<BrainVmMessage>,
|
pub brain_msg_tx: Sender<BrainVmMessage>,
|
||||||
pub daemon_msg_rx: Receiver<VmDaemonMessage>,
|
pub daemon_msg_rx: Receiver<VmDaemonMessage>,
|
||||||
pub daemon_msg_tx: Sender<VmDaemonMessage>,
|
pub daemon_msg_tx: Sender<VmDaemonMessage>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn connect_and_run(cd: ConnectionData) -> Result<()> {
|
pub async fn connect_and_run(cd: ConnectionData) -> Result<()> {
|
||||||
let client = BrainVmDaemonClient::connect(cd.brain_url).await?;
|
let client = client(&cd.network).await?;
|
||||||
let mut streaming_tasks = JoinSet::new();
|
let mut streaming_tasks = JoinSet::new();
|
||||||
|
|
||||||
streaming_tasks.spawn(receive_messages(client.clone(), cd.contracts.clone(), cd.brain_msg_tx));
|
streaming_tasks.spawn(receive_messages(client.clone(), cd.contracts.clone(), cd.brain_msg_tx));
|
||||||
|
@ -251,7 +251,7 @@ async fn main() {
|
|||||||
let (daemon_msg_tx, daemon_msg_rx) = tokio::sync::mpsc::channel(6);
|
let (daemon_msg_tx, daemon_msg_rx) = tokio::sync::mpsc::channel(6);
|
||||||
|
|
||||||
let mut vm_handler = VMHandler::new(brain_msg_rx, daemon_msg_tx.clone());
|
let mut vm_handler = VMHandler::new(brain_msg_rx, daemon_msg_tx.clone());
|
||||||
let brain_url = vm_handler.config.brain_url.clone();
|
let network = vm_handler.config.network.clone();
|
||||||
|
|
||||||
info!("Registering with the brain and getting back VM Contracts (if they exist).");
|
info!("Registering with the brain and getting back VM Contracts (if they exist).");
|
||||||
let mut contracts: Vec<String> = Vec::new();
|
let mut contracts: Vec<String> = Vec::new();
|
||||||
@ -270,7 +270,7 @@ async fn main() {
|
|||||||
info!("Connecting to brain...");
|
info!("Connecting to brain...");
|
||||||
if let Err(e) = grpc::connect_and_run(grpc::ConnectionData {
|
if let Err(e) = grpc::connect_and_run(grpc::ConnectionData {
|
||||||
contracts,
|
contracts,
|
||||||
brain_url,
|
network,
|
||||||
brain_msg_tx,
|
brain_msg_tx,
|
||||||
daemon_msg_rx,
|
daemon_msg_rx,
|
||||||
daemon_msg_tx,
|
daemon_msg_tx,
|
||||||
|
Loading…
Reference in New Issue
Block a user