Skip to content

Commit c69fee2

Browse files
ManuelBilbaoltitanbjclapis
authored
CBST2-11: Improve path validation on local Mux keys loader (#300)
Co-authored-by: eltitanb <[email protected]> Co-authored-by: ltitanb <[email protected]> Co-authored-by: Joe Clapis <[email protected]>
1 parent 34723b9 commit c69fee2

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

crates/cli/src/docker_init.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ pub async fn handle_docker_init(config_path: PathBuf, output_dir: PathBuf) -> Re
256256

257257
if let Some(mux_config) = cb_config.muxes {
258258
for mux in mux_config.muxes.iter() {
259-
if let Some((env_name, actual_path, internal_path)) = mux.loader_env() {
259+
if let Some((env_name, actual_path, internal_path)) = mux.loader_env()? {
260260
let (key, val) = get_env_val(&env_name, &internal_path);
261261
pbs_envs.insert(key, val);
262262
pbs_volumes.push(Volumes::Simple(format!("{}:{}:ro", actual_path, internal_path)));

crates/common/src/config/mux.rs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -130,19 +130,29 @@ pub struct MuxConfig {
130130

131131
impl MuxConfig {
132132
/// Returns the env, actual path, and internal path to use for the file
133-
/// loader
134-
pub fn loader_env(&self) -> Option<(String, String, String)> {
135-
self.loader.as_ref().and_then(|loader| match loader {
133+
/// loader. In File mode, validates the mux file prior to returning.
134+
pub fn loader_env(&self) -> eyre::Result<Option<(String, String, String)>> {
135+
let Some(loader) = self.loader.as_ref() else {
136+
return Ok(None);
137+
};
138+
139+
match loader {
136140
MuxKeysLoader::File(path_buf) => {
137-
let path =
138-
path_buf.to_str().unwrap_or_else(|| panic!("invalid path: {:?}", path_buf));
139-
let internal_path = get_mux_path(&self.id);
141+
let Some(path) = path_buf.to_str() else {
142+
bail!("invalid path: {:?}", path_buf);
143+
};
144+
145+
let file = load_file(path)?;
146+
// make sure we can load the pubkeys correctly
147+
let _: Vec<BlsPublicKey> =
148+
serde_json::from_str(&file).wrap_err("failed to parse mux keys file")?;
140149

141-
Some((get_mux_env(&self.id), path.to_owned(), internal_path))
150+
let internal_path = get_mux_path(&self.id);
151+
Ok(Some((get_mux_env(&self.id), path.to_owned(), internal_path)))
142152
}
143-
MuxKeysLoader::HTTP { .. } => None,
144-
MuxKeysLoader::Registry { .. } => None,
145-
})
153+
MuxKeysLoader::HTTP { .. } => Ok(None),
154+
MuxKeysLoader::Registry { .. } => Ok(None),
155+
}
146156
}
147157
}
148158

0 commit comments

Comments
 (0)