Compare commits
No commits in common. "823078b4cdaf93e09de0847c5eaa75beb7b26b7f" and "ea09b483fe7482f834d0ec8f8410325f6faf55a2" have entirely different histories.
823078b4cd
...
ea09b483fe
3 changed files with 21 additions and 30 deletions
|
@ -174,9 +174,7 @@ async fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn cli_command(opt: Opt) -> Result<(), Error> {
|
async fn cli_command(opt: Opt) -> Result<(), Error> {
|
||||||
let config = if (opt.secrets.rpc_secret.is_none() && opt.secrets.rpc_secret_file.is_none())
|
let config = if opt.secrets.rpc_secret.is_none() || opt.rpc_host.is_none() {
|
||||||
|| opt.rpc_host.is_none()
|
|
||||||
{
|
|
||||||
Some(garage_util::config::read_config(opt.config_file.clone())
|
Some(garage_util::config::read_config(opt.config_file.clone())
|
||||||
.err_context(format!("Unable to read configuration file {}. Configuration file is needed because -h or -s is not provided on the command line.", opt.config_file.to_string_lossy()))?)
|
.err_context(format!("Unable to read configuration file {}. Configuration file is needed because -h or -s is not provided on the command line.", opt.config_file.to_string_lossy()))?)
|
||||||
} else {
|
} else {
|
||||||
|
@ -184,19 +182,14 @@ async fn cli_command(opt: Opt) -> Result<(), Error> {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Find and parse network RPC secret
|
// Find and parse network RPC secret
|
||||||
let mut rpc_secret = config.as_ref().and_then(|c| c.rpc_secret.clone());
|
let net_key_hex_str = opt
|
||||||
secrets::fill_secret(
|
.secrets
|
||||||
&mut rpc_secret,
|
.rpc_secret
|
||||||
&config.as_ref().and_then(|c| c.rpc_secret_file.clone()),
|
.as_ref()
|
||||||
&opt.secrets.rpc_secret,
|
.or_else(|| config.as_ref().and_then(|c| c.rpc_secret.as_ref()))
|
||||||
&opt.secrets.rpc_secret_file,
|
.ok_or("No RPC secret provided")?;
|
||||||
"rpc_secret",
|
|
||||||
true,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
let net_key_hex_str = rpc_secret.ok_or("No RPC secret provided")?;
|
|
||||||
let network_key = NetworkKey::from_slice(
|
let network_key = NetworkKey::from_slice(
|
||||||
&hex::decode(&net_key_hex_str).err_context("Invalid RPC secret key (bad hex)")?[..],
|
&hex::decode(net_key_hex_str).err_context("Invalid RPC secret key (bad hex)")?[..],
|
||||||
)
|
)
|
||||||
.ok_or("Invalid RPC secret provided (wrong length)")?;
|
.ok_or("Invalid RPC secret provided (wrong length)")?;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
use std::path::PathBuf;
|
|
||||||
|
|
||||||
use structopt::StructOpt;
|
use structopt::StructOpt;
|
||||||
|
|
||||||
use garage_util::config::Config;
|
use garage_util::config::Config;
|
||||||
|
@ -25,7 +23,7 @@ pub struct Secrets {
|
||||||
/// RPC secret network key, used to replace rpc_secret in config.toml and rpc-secret
|
/// RPC secret network key, used to replace rpc_secret in config.toml and rpc-secret
|
||||||
/// when running the daemon or doing admin operations
|
/// when running the daemon or doing admin operations
|
||||||
#[structopt(long = "rpc-secret-file", env = "GARAGE_RPC_SECRET_FILE")]
|
#[structopt(long = "rpc-secret-file", env = "GARAGE_RPC_SECRET_FILE")]
|
||||||
pub rpc_secret_file: Option<PathBuf>,
|
pub rpc_secret_file: Option<String>,
|
||||||
|
|
||||||
/// Admin API authentication token, replaces admin.admin_token in config.toml when
|
/// Admin API authentication token, replaces admin.admin_token in config.toml when
|
||||||
/// running the Garage daemon
|
/// running the Garage daemon
|
||||||
|
@ -35,7 +33,7 @@ pub struct Secrets {
|
||||||
/// Admin API authentication token file path, replaces admin.admin_token in config.toml
|
/// Admin API authentication token file path, replaces admin.admin_token in config.toml
|
||||||
/// and admin-token when running the Garage daemon
|
/// and admin-token when running the Garage daemon
|
||||||
#[structopt(long = "admin-token-file", env = "GARAGE_ADMIN_TOKEN_FILE")]
|
#[structopt(long = "admin-token-file", env = "GARAGE_ADMIN_TOKEN_FILE")]
|
||||||
pub admin_token_file: Option<PathBuf>,
|
pub admin_token_file: Option<String>,
|
||||||
|
|
||||||
/// Metrics API authentication token, replaces admin.metrics_token in config.toml when
|
/// Metrics API authentication token, replaces admin.metrics_token in config.toml when
|
||||||
/// running the Garage daemon
|
/// running the Garage daemon
|
||||||
|
@ -45,7 +43,7 @@ pub struct Secrets {
|
||||||
/// Metrics API authentication token file path, replaces admin.metrics_token in config.toml
|
/// Metrics API authentication token file path, replaces admin.metrics_token in config.toml
|
||||||
/// and metrics-token when running the Garage daemon
|
/// and metrics-token when running the Garage daemon
|
||||||
#[structopt(long = "metrics-token-file", env = "GARAGE_METRICS_TOKEN_FILE")]
|
#[structopt(long = "metrics-token-file", env = "GARAGE_METRICS_TOKEN_FILE")]
|
||||||
pub metrics_token_file: Option<PathBuf>,
|
pub metrics_token_file: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Single function to fill all secrets in the Config struct from their correct source (value
|
/// Single function to fill all secrets in the Config struct from their correct source (value
|
||||||
|
@ -85,11 +83,11 @@ pub fn fill_secrets(mut config: Config, secrets: Secrets) -> Result<Config, Erro
|
||||||
Ok(config)
|
Ok(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn fill_secret(
|
fn fill_secret(
|
||||||
config_secret: &mut Option<String>,
|
config_secret: &mut Option<String>,
|
||||||
config_secret_file: &Option<PathBuf>,
|
config_secret_file: &Option<String>,
|
||||||
cli_secret: &Option<String>,
|
cli_secret: &Option<String>,
|
||||||
cli_secret_file: &Option<PathBuf>,
|
cli_secret_file: &Option<String>,
|
||||||
name: &'static str,
|
name: &'static str,
|
||||||
allow_world_readable: bool,
|
allow_world_readable: bool,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
|
@ -119,14 +117,14 @@ pub(crate) fn fill_secret(
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_secret_file(file_path: &PathBuf, allow_world_readable: bool) -> Result<String, Error> {
|
fn read_secret_file(file_path: &String, allow_world_readable: bool) -> Result<String, Error> {
|
||||||
if !allow_world_readable {
|
if !allow_world_readable {
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
{
|
{
|
||||||
use std::os::unix::fs::MetadataExt;
|
use std::os::unix::fs::MetadataExt;
|
||||||
let metadata = std::fs::metadata(file_path)?;
|
let metadata = std::fs::metadata(file_path)?;
|
||||||
if metadata.mode() & 0o077 != 0 {
|
if metadata.mode() & 0o077 != 0 {
|
||||||
return Err(format!("File {} is world-readable! (mode: 0{:o}, expected 0600)\nRefusing to start until this is fixed, or environment variable GARAGE_ALLOW_WORLD_READABLE_SECRETS is set to true.", file_path.display(), metadata.mode()).into());
|
return Err(format!("File {} is world-readable! (mode: 0{:o}, expected 0600)\nRefusing to start until this is fixed, or environment variable GARAGE_ALLOW_WORLD_READABLE_SECRETS is set to true.", file_path, metadata.mode()).into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -262,7 +260,7 @@ mod tests {
|
||||||
let config = fill_secrets(
|
let config = fill_secrets(
|
||||||
config,
|
config,
|
||||||
Secrets {
|
Secrets {
|
||||||
rpc_secret_file: Some(path_secret2.clone()),
|
rpc_secret_file: Some(path_secret2.display().to_string()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
)?;
|
)?;
|
||||||
|
@ -273,7 +271,7 @@ mod tests {
|
||||||
config,
|
config,
|
||||||
Secrets {
|
Secrets {
|
||||||
rpc_secret: Some("baz".into()),
|
rpc_secret: Some("baz".into()),
|
||||||
rpc_secret_file: Some(path_secret2.clone()),
|
rpc_secret_file: Some(path_secret2.display().to_string()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
@ -52,7 +52,7 @@ pub struct Config {
|
||||||
/// RPC secret key: 32 bytes hex encoded
|
/// RPC secret key: 32 bytes hex encoded
|
||||||
pub rpc_secret: Option<String>,
|
pub rpc_secret: Option<String>,
|
||||||
/// Optional file where RPC secret key is read from
|
/// Optional file where RPC secret key is read from
|
||||||
pub rpc_secret_file: Option<PathBuf>,
|
pub rpc_secret_file: Option<String>,
|
||||||
/// Address to bind for RPC
|
/// Address to bind for RPC
|
||||||
pub rpc_bind_addr: SocketAddr,
|
pub rpc_bind_addr: SocketAddr,
|
||||||
/// Public IP address of this node
|
/// Public IP address of this node
|
||||||
|
@ -166,12 +166,12 @@ pub struct AdminConfig {
|
||||||
/// Bearer token to use to scrape metrics
|
/// Bearer token to use to scrape metrics
|
||||||
pub metrics_token: Option<String>,
|
pub metrics_token: Option<String>,
|
||||||
/// File to read metrics token from
|
/// File to read metrics token from
|
||||||
pub metrics_token_file: Option<PathBuf>,
|
pub metrics_token_file: Option<String>,
|
||||||
|
|
||||||
/// Bearer token to use to access Admin API endpoints
|
/// Bearer token to use to access Admin API endpoints
|
||||||
pub admin_token: Option<String>,
|
pub admin_token: Option<String>,
|
||||||
/// File to read admin token from
|
/// File to read admin token from
|
||||||
pub admin_token_file: Option<PathBuf>,
|
pub admin_token_file: Option<String>,
|
||||||
|
|
||||||
/// OTLP server to where to export traces
|
/// OTLP server to where to export traces
|
||||||
pub trace_sink: Option<String>,
|
pub trace_sink: Option<String>,
|
||||||
|
|
Loading…
Add table
Reference in a new issue