mirror of
https://github.com/matter-labs/teepot.git
synced 2025-07-21 23:23:57 +02:00
feat(tee-key-preexec): add cmdline arg for env prefix
- Introduced `clap` for command-line argument parsing. - Replaced manual argument handling with `clap`'s derived `Args` struct. - Updated environmental variables to use dynamic prefixes. Signed-off-by: Harald Hoyer <harald@matterlabs.dev>
This commit is contained in:
parent
6b0b0b69ca
commit
c94912d832
3 changed files with 33 additions and 16 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -4780,6 +4780,7 @@ name = "tee-key-preexec"
|
||||||
version = "0.1.2-alpha.1"
|
version = "0.1.2-alpha.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
"clap",
|
||||||
"rand",
|
"rand",
|
||||||
"secp256k1 0.29.0",
|
"secp256k1 0.29.0",
|
||||||
"teepot",
|
"teepot",
|
||||||
|
|
|
@ -10,6 +10,7 @@ repository.workspace = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow.workspace = true
|
anyhow.workspace = true
|
||||||
|
clap.workspace = true
|
||||||
rand.workspace = true
|
rand.workspace = true
|
||||||
secp256k1.workspace = true
|
secp256k1.workspace = true
|
||||||
teepot.workspace = true
|
teepot.workspace = true
|
||||||
|
|
|
@ -7,9 +7,9 @@
|
||||||
#![deny(clippy::all)]
|
#![deny(clippy::all)]
|
||||||
|
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
|
use clap::Parser;
|
||||||
use secp256k1::{rand, Keypair, PublicKey, Secp256k1, SecretKey};
|
use secp256k1::{rand, Keypair, PublicKey, Secp256k1, SecretKey};
|
||||||
|
use std::ffi::OsString;
|
||||||
use std::env;
|
|
||||||
use std::os::unix::process::CommandExt;
|
use std::os::unix::process::CommandExt;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
use teepot::quote::get_quote;
|
use teepot::quote::get_quote;
|
||||||
|
@ -19,6 +19,17 @@ use tracing_subscriber::{fmt, prelude::*, EnvFilter, Registry};
|
||||||
|
|
||||||
const TEE_QUOTE_FILE: &str = "/tmp/tee_quote";
|
const TEE_QUOTE_FILE: &str = "/tmp/tee_quote";
|
||||||
|
|
||||||
|
#[derive(Parser, Debug)]
|
||||||
|
#[command(author, version, about, long_about = None)]
|
||||||
|
struct Args {
|
||||||
|
/// environment variable prefix to use
|
||||||
|
#[arg(long, default_value = "")]
|
||||||
|
env_prefix: String,
|
||||||
|
/// program to exec [args...] (required)
|
||||||
|
#[arg(required = true, allow_hyphen_values = true, last = true)]
|
||||||
|
cmd_args: Vec<OsString>,
|
||||||
|
}
|
||||||
|
|
||||||
fn main_with_error() -> Result<()> {
|
fn main_with_error() -> Result<()> {
|
||||||
LogTracer::init().context("Failed to set logger")?;
|
LogTracer::init().context("Failed to set logger")?;
|
||||||
|
|
||||||
|
@ -27,14 +38,7 @@ fn main_with_error() -> Result<()> {
|
||||||
.with(fmt::layer().with_writer(std::io::stderr));
|
.with(fmt::layer().with_writer(std::io::stderr));
|
||||||
tracing::subscriber::set_global_default(subscriber).context("Failed to set logger")?;
|
tracing::subscriber::set_global_default(subscriber).context("Failed to set logger")?;
|
||||||
|
|
||||||
let args = env::args_os().collect::<Box<_>>();
|
let args = Args::parse();
|
||||||
|
|
||||||
if args.len() < 2 {
|
|
||||||
return Err(anyhow::anyhow!(
|
|
||||||
"Usage: {} <command> [args...]",
|
|
||||||
args[0].to_string_lossy()
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut rng = rand::thread_rng();
|
let mut rng = rand::thread_rng();
|
||||||
let secp = Secp256k1::new();
|
let secp = Secp256k1::new();
|
||||||
|
@ -55,14 +59,25 @@ fn main_with_error() -> Result<()> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let err = Command::new(&args[1])
|
let err = Command::new(&args.cmd_args[0])
|
||||||
.args(&args[2..])
|
.args(&args.cmd_args[1..])
|
||||||
.env("TEE_SIGNING_KEY", signing_key.display_secret().to_string())
|
.env(
|
||||||
.env("TEE_QUOTE_FILE", TEE_QUOTE_FILE)
|
format!("{}SIGNING_KEY", args.env_prefix),
|
||||||
.env("TEE_TYPE", tee_type)
|
signing_key.display_secret().to_string(),
|
||||||
|
)
|
||||||
|
.env(
|
||||||
|
format!("{}ATTESTATION_QUOTE_FILE_PATH", args.env_prefix),
|
||||||
|
TEE_QUOTE_FILE,
|
||||||
|
)
|
||||||
|
.env(format!("{}TEE_TYPE", args.env_prefix), tee_type)
|
||||||
.exec();
|
.exec();
|
||||||
|
|
||||||
Err(err).with_context(|| format!("exec of `{cmd}` failed", cmd = args[1].to_string_lossy()))
|
Err(err).with_context(|| {
|
||||||
|
format!(
|
||||||
|
"exec of `{cmd}` failed",
|
||||||
|
cmd = args.cmd_args[0].to_string_lossy()
|
||||||
|
)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue