fix(app): keep masking the secrets the running services got after a key is replaced or removed
The log hub masks the stored secrets and the values the services were started with (bot token, MCP environment values), so a late worker or MCP line carrying a key replaced or removed while the services run stays masked on the screen, in copies, files and exports; the next start replaces the in-use values. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -49,6 +49,12 @@ pub async fn start_services(data_dir: &Path, llm: Arc<Llm>) -> Result<Services,
|
||||
None => std::env::var("JARVIS_DISCORD_TOKEN").map_err(|_| "no bot token: set it in the app or JARVIS_DISCORD_TOKEN")?,
|
||||
};
|
||||
|
||||
// What these services are given stays masked in the logs until the next start, also if it is
|
||||
// replaced or removed in the store meanwhile (admin.spec.md, "Logs").
|
||||
if let Some(hub) = crate::logs::installed() {
|
||||
hub.set_secrets_in_use(secrets_in_use(&token, &mcp_env));
|
||||
}
|
||||
|
||||
let (base_url, model) = llm.start(&settings).await?;
|
||||
let brain_config = match crate::strata::write_brain_config(data_dir, &base_url, &model, &settings) {
|
||||
Ok(f) => f,
|
||||
@@ -106,6 +112,15 @@ pub async fn start_services(data_dir: &Path, llm: Arc<Llm>) -> Result<Services,
|
||||
Ok(Services { core, events, worker, worker_process, missed, llm })
|
||||
}
|
||||
|
||||
/// The secret values the services get: the bot token and the MCP servers' environment values.
|
||||
pub fn secrets_in_use(token: &str, mcp_env: &Value) -> Vec<String> {
|
||||
let mut v = vec![token.to_owned()];
|
||||
for vars in mcp_env.as_object().into_iter().flat_map(|m| m.values()) {
|
||||
v.extend(vars.as_object().into_iter().flat_map(|m| m.values()).filter_map(Value::as_str).map(str::to_owned));
|
||||
}
|
||||
v
|
||||
}
|
||||
|
||||
/// Stop the LLM after a failed start; the error also says if its server may still run.
|
||||
async fn after_llm_stop(llm: &Llm, error: String) -> String {
|
||||
match llm.stop().await {
|
||||
@@ -113,3 +128,16 @@ async fn after_llm_stop(llm: &Llm, error: String) -> String {
|
||||
Err(stop) => format!("{error} ({stop})"),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn the_services_secrets_are_the_token_and_every_mcp_value() {
|
||||
let env = serde_json::json!({"brave": {"BRAVE_API_KEY": "k1"}, "other": {"A": "k2", "B": "k3"}});
|
||||
let mut v = secrets_in_use("tok", &env);
|
||||
v.sort();
|
||||
assert_eq!(v, vec!["k1", "k2", "k3", "tok"]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user