Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem: Nitro helper requires a separate enclave launching(#93) #109

Merged
merged 10 commits into from
Jun 30, 2021

Conversation

linfeng-crypto
Copy link

add launch-all and enclave subcommand:

SUBCOMMANDS:
    enclave       enclave sub-commands
    help          Prints this message or the help of the given subcommand(s)
    init          Create config + keygen
    launch-all    launch all
    start         start tmkms process

launch-all will start nitro enclave / enclave vsock-proxy / enclave helper all in one.

the enclave submand include the following:

SUBCOMMANDS:
    help           Prints this message or the help of the given subcommand(s)
    info           get tmkms info
    run            run enclave
    stop           stop enclave
    vsock-proxy    launch vsock proxy

move the enclave log server to command tmkms-nitro-helper enclave run command.

@linfeng-crypto linfeng-crypto requested a review from tomtau as a code owner June 24, 2021 06:25
Copy link

@tomtau tomtau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given nitro-cli isn't yet exposed as a library properly, wouldn't be easier just call the shell command?
also: https://github.com/crypto-com/tmkms-light/pull/109/checks?check_run_id=2902100730#step:5:22

Copy link

@tomtau tomtau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good -- it seems much simpler with just Commands.
left a few suggestions and questions

Comment on lines 33 to 41
let proxy_opt = VSockProxyOpt {
remote_addr: format!("kms.{}.amazonaws.com", aws_region),
..Default::default()
};
let all_config = Config {
sign_opt: nitro_sign_opt,
enclave: enclave_opt,
vsock_proxy: proxy_opt,
};
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given the "launch all" command is optional, I'm not sure if it makes sense to bundle the extra config to the global config?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 103 to 104
cmd.contains(&"tmkms-nitro-helper".to_string())
&& cmd.contains(&"enclave".to_string())
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

won't this always fail? it'll only match a command that has all those 3 names in its name?
also the functional is called check_vsock_proxy, why does it check for tmkms-nitro-helper...?

use crossbeam_channel::{bounded, Receiver, Sender};
use std::thread::{self, sleep};
use std::time::Duration;

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for pub functions or struct, it'd be good to have some doc explaining what it does -- e.g. stop_enclave_sender isn't entirely obvious from the type

use crate::command::nitro_enclave::run_vsock_proxy;
use crate::command::nitro_enclave::{describe_enclave, run_enclave};
use crate::config::Config;
use crossbeam_channel::{bounded, Receiver, Sender};
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is crossbeam used instead of std::sync::mpsc::channel? is it because the std one isn't deriving Sync or something like that?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

later, we can use crossbeam::select in a loop, process data from TCP stream or a stop signal.

@@ -11,7 +11,9 @@ main = ["sysinfo", "reqwest"]
[dependencies]
anomaly = "0.2"
bytes = "= 0.5"
ctrlc = "3.1"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ctrlc = "3.1"
ctrlc = "3"

@@ -0,0 +1,29 @@
use crate::config::VSockProxyOpt;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems this module is unused? (only launch_all and nitro_enclave are denoted "mod" in command?)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed


#[derive(Serialize, Deserialize, Default, Debug)]
pub struct Config {
pub sign_opt: NitroSignOpt,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given only NitroSignOpt is used by the normal launch, perhaps separating the other two in a different struct? so it's still backwards-compatible and for "launch-all", one can have an extra config?

Comment on lines +37 to +40
#[structopt(name = "info", about = "get tmkms info")]
Info,
#[structopt(name = "run", about = "run enclave")]
RunEnclave {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quite useful to have these "shorthand" commands, so one doesn't need to repeat the args (it'd just be automatically read or taken from a config file) 👍

@@ -37,49 +82,104 @@ enum TmkmsLight {
#[structopt(name = "start", about = "start tmkms process")]
/// start tmkms process (push config + start up proxy and state persistence)
Start {
#[structopt(short)]
config_path: Option<PathBuf>,
#[structopt(short, default_value = "tmkms.toml")]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could potentially be done for Init too?

Comment on lines 153 to 164
pub fn run_vsock_proxy(opt: &VSockProxyOpt) -> Result<(), String> {
tracing::debug!("run vsock proxy with config: {:?}", opt);
let _ = Command::new("vsock-proxy")
.args(&["--num_workers", &format!("{}", opt.num_workers)])
.args(&["--config", &opt.config_file])
.arg(opt.local_port.to_string())
.arg(&opt.remote_addr)
.arg(opt.remote_port.to_string())
.output()
.map_err(|e| format!("execute nitro-cli error: {:?}", e))?;
Ok(())
}
Copy link

@tomtau tomtau Jun 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

two questions or possible suggestions:

  1. should this also check if the vsock-proxy isn't already running in the background?
  2. what happens to this child process when the main process is ended? Given the output() isn't used, maybe this could return .spawn() instead, so that one can have Child and pass the signal to it when exiting?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my test, there is no output.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fixing this...

Copy link

@tomtau tomtau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changes in workflows to be documented in a separate PR #11

@tomtau tomtau merged commit b1a50dc into crypto-com:main Jun 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants