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

cocokeyprovider: add support for daemonize #417

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions attestation-agent/coco_keyprovider/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ anyhow.workspace = true
base64.workspace = true
clap = { workspace = true, features = ["derive"] }
ctr.workspace = true
daemonize = "0.5.0"
env_logger = "0.10.0"
futures = "0.3.5"
jwt-simple = "0.11.4"
Expand Down
1 change: 0 additions & 1 deletion attestation-agent/coco_keyprovider/src/enc_mods/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ fn parse_input_params(input: &str) -> Result<InputParams> {
.collect::<Vec<&str>>()
.iter()
.filter_map(|field| field.split_once('='))
.map(|(k, v)| (k, v))
.collect();
debug!("Get new request: {:?}", map);
let sample = map
Expand Down
32 changes: 31 additions & 1 deletion attestation-agent/coco_keyprovider/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@

use anyhow::*;
use clap::{arg, command, Parser};
use daemonize::Daemonize;
use log::*;
use std::{net::SocketAddr, path::PathBuf};
use std::{fs::File, net::SocketAddr, path::PathBuf};
use tokio::fs;

pub mod enc_mods;
pub mod grpc;
Expand All @@ -30,6 +32,15 @@ struct Cli {
/// will be automatically registered into the KBS.
#[arg(long)]
kbs: Option<String>,

/// Whether this process is launched in daemon mode. If it is set to
/// true, the stdio and stderr will be redirected to
/// `/run/confidential-containers/coco_keyprovider.out` and
/// `/run/confidential-containers/coco_keyprovider.err`.
/// The pid will be recorded in
/// `/run/confidential-containers/coco_keyprovider.pid`
#[arg(short, long, default_value = "false")]
daemon: bool,
}

#[tokio::main]
Expand All @@ -48,6 +59,25 @@ async fn main() -> Result<()> {
);
}

if cli.daemon {
fs::create_dir_all("/run/confidential-containers")
.await
.context("create coco run dir failed.")?;
let stdout = File::create("/run/confidential-containers/coco_keyprovider.out")
.context("create stdout redirect file failed.")?;
let stderr = File::create("/run/confidential-containers/coco_keyprovider.err")
.context("create stderr redirect file failed.")?;

let daemonize = Daemonize::new()
.pid_file("/run/confidential-containers/coco_keyprovider.pid")
.chown_pid_file(true)
.working_directory("/run/confidential-containers")
.stdout(stdout)
.stderr(stderr);

daemonize.start().context("daemonize failed")?;
}

grpc::start_service(cli.socket, cli.auth_private_key, cli.kbs).await?;

Ok(())
Expand Down
Loading