Skip to content

Commit

Permalink
Simplify the config file format
Browse files Browse the repository at this point in the history
  • Loading branch information
kvinwang committed Sep 30, 2024
1 parent 2e5fdc7 commit a13f409
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 64 deletions.
13 changes: 5 additions & 8 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,15 @@ make -C .. certs DOMAIN=$BASE_DOMAIN TO=$CERTS_DIR

# kms
cat <<EOF > kms.toml
[default]
log_level = "info"
address = "0.0.0.0"
port = $KMS_RPC_LISTEN_PORT
[default.tls]
[tls]
key = "$CERTS_DIR/kms-rpc.key"
certs = "$CERTS_DIR/kms-rpc.cert"
[default.tls.mutual]
[tls.mutual]
ca_certs = "$CERTS_DIR/tmp-ca.cert"
mandatory = false
Expand All @@ -83,16 +82,15 @@ EOF

# tproxy
cat <<EOF > tproxy.toml
[default]
log_level = "info"
address = "0.0.0.0"
port = $TPROXY_RPC_LISTEN_PORT
[default.tls]
[tls]
key = "$CERTS_DIR/tproxy-rpc.key"
certs = "$CERTS_DIR/tproxy-rpc.cert"
[default.tls.mutual]
[tls.mutual]
ca_certs = "$CERTS_DIR/root-ca.cert"
mandatory = false
Expand All @@ -119,13 +117,12 @@ EOF

# teepod
cat <<EOF > teepod.toml
[default]
log_level = "info"
port = $TEEPOD_RPC_LISTEN_PORT
image_path = "$IMAGES_DIR"
run_path = "$RUN_DIR/vm"
[default.cvm]
[cvm]
ca_cert = "$CERTS_DIR/root-ca.cert"
tmp_ca_cert = "$CERTS_DIR/tmp-ca.cert"
tmp_ca_key = "$CERTS_DIR/tmp-ca.key"
Expand Down
14 changes: 2 additions & 12 deletions kms/kms.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
[default]
workers = 8
max_blocking = 64
ident = "Phala KMS"
Expand All @@ -8,23 +7,14 @@ log_level = "info"
address = "0.0.0.0"
port = 8043

[default.tls]
[tls]
key = "/etc/kms/certs/key.pem"
certs = "/etc/kms/certs/cert.pem"

[default.tls.mutual]
[tls.mutual]
ca_certs = "/etc/kms/certs/ca.cert"
mandatory = false

[default.limits]
bytes = "8KiB"
data-form = "2MiB"
file = "1MiB"
form = "32KiB"
json = "1MiB"
msgpack = "1MiB"
string = "8KiB"

[core]
root_ca_cert = "/etc/kms/certs/ca.cert"
root_ca_key = "/etc/kms/certs/ca.key"
Expand Down
8 changes: 4 additions & 4 deletions kms/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ pub const DEFAULT_CONFIG: &str = include_str!("../kms.toml");

pub fn load_config_figment(config_file: Option<&str>) -> Figment {
let leaf_config = match config_file {
Some(path) => Toml::file(path).nested(),
None => Toml::file(CONFIG_FILENAME).nested(),
Some(path) => Toml::file(path),
None => Toml::file(CONFIG_FILENAME),
};
Figment::from(rocket::Config::default())
.merge(Toml::string(DEFAULT_CONFIG).nested())
.merge(Toml::file(SYSTEM_CONFIG_FILENAME).nested())
.merge(Toml::string(DEFAULT_CONFIG))
.merge(Toml::file(SYSTEM_CONFIG_FILENAME))
.merge(leaf_config)
}

Expand Down
6 changes: 3 additions & 3 deletions kms/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::{anyhow, Context, Result};
use tracing::info;
use clap::Parser;
use tracing::info;

mod config;
mod main_service;
Expand All @@ -26,9 +26,9 @@ async fn main() -> Result<()> {
}

let figment = config::load_config_figment(args.config.as_deref());
let config = figment.clone().select("core").extract()?;
let config = figment.focus("core").extract()?;
let state = main_service::KmsState::new(config).context("Failed to initialize KMS state")?;
let rocket = rocket::custom(figment.select("public"))
let rocket = rocket::custom(figment)
.mount("/", web_routes::routes())
.manage(state);

Expand Down
2 changes: 1 addition & 1 deletion tappd/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ async fn main() -> Result<()> {
let args = Args::parse();
let figment = config::load_config_figment(args.config.as_deref());
let state =
AppState::new(figment.clone().select("core").extract()?).context("Failed to create app state")?;
AppState::new(figment.focus("core").extract()?).context("Failed to create app state")?;

let internal_figment = figment.clone().select("internal");
let external_figment = figment.select("external");
Expand Down
8 changes: 4 additions & 4 deletions tappd/tappd.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ temp_dir = "/tmp"
keep_alive = 10
log_level = "debug"

[default.core]
cert_file = "/etc/tappd/app-ca.cert"
key_file = "/etc/tappd/app-ca.key"

[internal]
address = "unix:/var/run/tappd.sock"
reuse = false

[external]
address = "0.0.0.0"
port = 8090

[core]
cert_file = "/etc/tappd/app-ca.cert"
key_file = "/etc/tappd/app-ca.key"
2 changes: 1 addition & 1 deletion teepod/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::path::{Path, PathBuf};
use std::sync::atomic::{AtomicU32, Ordering};
use std::sync::{Arc, Mutex, MutexGuard};
use std::sync::{Arc, Mutex};
use teepod_rpc::VmInfo;

#[derive(Deserialize, Serialize, Builder)]
Expand Down
8 changes: 4 additions & 4 deletions teepod/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ pub const DEFAULT_CONFIG: &str = include_str!("../teepod.toml");

pub fn load_config_figment(config_file: Option<&str>) -> Figment {
let leaf_config = match config_file {
Some(path) => Toml::file(path).nested(),
None => Toml::file(CONFIG_FILENAME).nested(),
Some(path) => Toml::file(path),
None => Toml::file(CONFIG_FILENAME),
};
Figment::from(rocket::Config::default())
.merge(Toml::string(DEFAULT_CONFIG).nested())
.merge(Toml::file(SYSTEM_CONFIG_FILENAME).nested())
.merge(Toml::string(DEFAULT_CONFIG))
.merge(Toml::file(SYSTEM_CONFIG_FILENAME))
.merge(leaf_config)
}

Expand Down
14 changes: 2 additions & 12 deletions teepod/teepod.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
[default]
workers = 8
max_blocking = 64
ident = "Teepod Server"
Expand All @@ -7,18 +6,9 @@ keep_alive = 10
log_level = "debug"
port = 8080

[default.cvm]
[cvm]
ca_cert = "../certs/ca.cert"
tmp_ca_cert = "../certs/tmp-ca.cert"
tmp_ca_key = "../certs/tmp-ca.key"
kms_url = "http://127.0.0.1:8081"
tproxy_url = "http://127.0.0.1:8082"

[default.limits]
bytes = "8KiB"
data-form = "2MiB"
file = "1MiB"
form = "32KiB"
json = "1MiB"
msgpack = "1MiB"
string = "8KiB"
tproxy_url = "http://127.0.0.1:8082"
8 changes: 4 additions & 4 deletions tproxy/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ pub const DEFAULT_CONFIG: &str = include_str!("../tproxy.toml");

pub fn load_config_figment(config_file: Option<&str>) -> Figment {
let leaf_config = match config_file {
Some(path) => Toml::file(path).nested(),
None => Toml::file(CONFIG_FILENAME).nested(),
Some(path) => Toml::file(path),
None => Toml::file(CONFIG_FILENAME),
};
Figment::from(rocket::Config::default())
.merge(Toml::string(DEFAULT_CONFIG).nested())
.merge(Toml::file(SYSTEM_CONFIG_FILENAME).nested())
.merge(Toml::string(DEFAULT_CONFIG))
.merge(Toml::file(SYSTEM_CONFIG_FILENAME))
.merge(leaf_config)
}
2 changes: 1 addition & 1 deletion tproxy/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async fn main() -> Result<()> {
let args = Args::parse();
let figment = config::load_config_figment(args.config.as_deref());

let config = figment.clone().select("core").extract::<Config>()?;
let config = figment.focus("core").extract::<Config>()?;
let proxy_config_path = config.proxy.config_path.clone();
let state = main_service::AppState::new(config);
state.lock().reconfigure()?;
Expand Down
10 changes: 0 additions & 10 deletions tproxy/tproxy.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
[default]
workers = 8
max_blocking = 64
ident = "Tproxy Server"
Expand All @@ -7,15 +6,6 @@ keep_alive = 10
log_level = "debug"
port = 8010

[default.limits]
bytes = "8KiB"
data-form = "2MiB"
file = "1MiB"
form = "32KiB"
json = "1MiB"
msgpack = "1MiB"
string = "8KiB"

[core.wg]
public_key = ""
private_key = ""
Expand Down

0 comments on commit a13f409

Please sign in to comment.