Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

refactor(core): write core.token through the shared atomic keyring writer

M3gA-Minda6e726ca45fa
diff --git a/crates/openhuman-core/src/core/auth.rs b/crates/openhuman-core/src/core/auth.rs
index bbdabecfbd..296b316a23 100644
--- a/crates/openhuman-core/src/core/auth.rs
+++ b/crates/openhuman-core/src/core/auth.rs
@@ -33,9 +33,6 @@
use std::path::Path;
use std::sync::OnceLock;
-#[cfg(unix)]
-use std::io::Write as _;
-
// The axum RPC-auth middleware + the `/v1` external-inference bearer helpers
// are exclusive to the `http-server` feature (#5048). The always-compiled token
// primitives (`verify_bearer_token`, `init_rpc_token`, `get_rpc_token`,
@@ -219,31 +216,13 @@ fn generate_token() -> String {
}
/// Write `token` to `path` with owner-only read+write permissions on Unix.
+///
+/// Published through a fresh 0600 inode renamed over the old file (the shared
+/// keyring writer): chmod on an existing file neither revokes descriptors
+/// already open on it nor survives a failed rewrite, and the old token stays
+/// intact until the rename succeeds.
fn write_token_file(path: &Path, token: &str) -> anyhow::Result<()> {
- if let Some(parent) = path.parent() {
- std::fs::create_dir_all(parent)?;
- }
-
- #[cfg(unix)]
- {
- // Publish through a fresh 0600 inode and rename it over the old file:
- // chmod on an existing file neither revokes descriptors already open on
- // it nor survives a failed rewrite, and the old token stays intact
- // until the rename succeeds.
- let dir = path
- .parent()
- .filter(|d| !d.as_os_str().is_empty())
- .unwrap_or_else(|| Path::new("."));
- let mut file = tempfile::NamedTempFile::new_in(dir)?;
- file.write_all(token.as_bytes())?;
- file.persist(path)?;
- }
-
- #[cfg(not(unix))]
- {
- std::fs::write(path, token)?;
- }
-
+ crate::security::secret_storage::file_store::write_atomic(path, token.as_bytes())?;
Ok(())
}
diff --git a/scripts/ci/storage-bypass-baseline.json b/scripts/ci/storage-bypass-baseline.json
index 28ac210c63..6264dbb179 100644
--- a/scripts/ci/storage-bypass-baseline.json
+++ b/scripts/ci/storage-bypass-baseline.json
@@ -111,20 +111,6 @@
"text": "std::fs::write(&summary_path, &summary)",
"occurrence": 1
},
- {
- "rule": "json-write",
- "path": "crates/openhuman-core/src/core/auth.rs",
- "line": 231,
- "text": "let mut file = std::fs::OpenOptions::new()",
- "occurrence": 1
- },
- {
- "rule": "json-write",
- "path": "crates/openhuman-core/src/core/auth.rs",
- "line": 242,
- "text": "std::fs::write(path, token)?;",
- "occurrence": 1
- },
{
"rule": "json-write",
"path": "crates/openhuman-core/src/core/observability/progress_tracing/export.rs",