Skip to content

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

fix(secret_storage): fail closed on profile reads without secret-file

Steven Enamakel595baf38f813
diff --git a/crates/openhuman-core/src/security/secret_storage/encrypted_file_backend.rs b/crates/openhuman-core/src/security/secret_storage/encrypted_file_backend.rs
index 90cfb66984..d33a01afc8 100644
--- a/crates/openhuman-core/src/security/secret_storage/encrypted_file_backend.rs
+++ b/crates/openhuman-core/src/security/secret_storage/encrypted_file_backend.rs
@@ -20,9 +20,7 @@ use zeroize::Zeroizing;
#[path = "encrypted_file_backend/key_source.rs"]
pub mod key_source;
-use key_source::{env_value, master_key_from_env, read_master_key_file};
-#[cfg(all(test, unix))]
-use key_source::key_file_mode_is_other_writable;
+use key_source::{env_value, master_key_from_env};
/// Environment variable carrying the master key inline as `2 * KEY_LEN` hex
/// characters (`openssl rand -hex 32`). Lets a headless `openhuman-core
@@ -256,6 +254,34 @@ fn try_load_master_key() -> Result<([u8; KEY_LEN], String), MasterKeyError> {
.map_err(|e| MasterKeyError::Configured(e.to_string()))
}
+/// Reads the file named by [`MASTER_KEY_FILE_ENV`].
+///
+/// On Unix a key file must not be writable by other users. Read-only group or
+/// other permissions are supported for container secret mounts, where the
+/// runtime may add group-read access for a non-root core.
+fn read_master_key_file(path: &Path) -> Result<String, String> {
+ #[cfg(unix)]
+ {
+ use std::os::unix::fs::PermissionsExt;
+ let metadata = std::fs::metadata(path).map_err(|e| {
+ format!("cannot inspect master key file permissions ({MASTER_KEY_FILE_ENV}): {e}")
+ })?;
+ let mode = metadata.permissions().mode() & 0o777;
+ if key_file_mode_is_other_writable(mode) {
+ return Err(format!(
+ "master key file ({MASTER_KEY_FILE_ENV}) is writable by other users; \
+ restrict it to a read-only secret mount"
+ ));
+ }
+ }
+ std::fs::read_to_string(path).map_err(|e| format!("cannot read master key file: {e}"))
+}
+
+#[cfg(unix)]
+fn key_file_mode_is_other_writable(mode: u32) -> bool {
+ mode & 0o002 != 0
+}
+
/// Decodes a master key supplied as exactly `2 * KEY_LEN` hex characters.
/// The value never appears in the error.
fn parse_master_key_hex(hex: &str) -> Result<[u8; KEY_LEN], String> {
diff --git a/crates/openhuman-core/src/security/secret_storage/encrypted_file_backend/key_source.rs b/crates/openhuman-core/src/security/secret_storage/encrypted_file_backend/key_source.rs
index 1dd9335f4b..1dc3867f7b 100644
--- a/crates/openhuman-core/src/security/secret_storage/encrypted_file_backend/key_source.rs
+++ b/crates/openhuman-core/src/security/secret_storage/encrypted_file_backend/key_source.rs
@@ -140,39 +140,12 @@ pub(super) fn workspace_master_key(
}
}
-/// Reads the file named by [`MASTER_KEY_FILE_ENV`].
-///
-/// On Unix a key file must not be writable by other users. Read-only group or
-/// other permissions are supported for container secret mounts, where the
-/// runtime may add group-read access for a non-root core.
-pub(super) fn read_master_key_file(path: &Path) -> Result<String, String> {
- #[cfg(unix)]
- {
- use std::os::unix::fs::PermissionsExt;
- let metadata = std::fs::metadata(path).map_err(|e| {
- format!("cannot inspect master key file permissions ({MASTER_KEY_FILE_ENV}): {e}")
- })?;
- let mode = metadata.permissions().mode() & 0o777;
- if key_file_mode_is_other_writable(mode) {
- return Err(format!(
- "master key file ({MASTER_KEY_FILE_ENV}) is writable by other users; \
- restrict it to a read-only secret mount"
- ));
- }
- }
- std::fs::read_to_string(path).map_err(|e| format!("cannot read master key file: {e}"))
-}
-
-#[cfg(unix)]
-pub(super) fn key_file_mode_is_other_writable(mode: u32) -> bool {
- mode & 0o002 != 0
-}
-
/// Resolves a key for a profile-scoped diagnostic read without creating or
/// changing key state. Explicit operator key variables retain their normal
/// precedence; otherwise only an existing key file beneath `workspace` is
/// considered. Host key sources are excluded because they can prompt or mint.
-/// Only the encrypted-file backend reads profiles this way.
+/// Only the encrypted-file backend reads profiles; without `secret-file` the
+/// placeholder backend refuses the read instead.
#[cfg(feature = "secret-file")]
pub(super) fn profile_master_key_read_only(
workspace: &Path,
@@ -184,7 +157,7 @@ pub(super) fn profile_master_key_read_only(
if let Some((key, _)) = master_key_from_env(
inline.as_deref(),
file.as_deref(),
- read_master_key_file,
+ super::read_master_key_file,
)
.map_err(SecretStorageError::Backend)?
{
diff --git a/crates/openhuman-core/src/security/secret_storage/encrypted_file_backend_disabled.rs b/crates/openhuman-core/src/security/secret_storage/encrypted_file_backend_disabled.rs
index ddccdabcb3..fe5c8fa9f5 100644
--- a/crates/openhuman-core/src/security/secret_storage/encrypted_file_backend_disabled.rs
+++ b/crates/openhuman-core/src/security/secret_storage/encrypted_file_backend_disabled.rs
@@ -85,6 +85,17 @@ impl EncryptedFileBackend {
}
}
+impl EncryptedFileBackend {
+ /// A profile-scoped read-only lookup, as the enabled backend offers it.
+ /// There is no encrypted file to read, so it fails closed.
+ pub fn get_profile_read_only(
+ &self,
+ _namespaced_key: &str,
+ ) -> Result<Option<String>, SecretStorageError> {
+ Err(unavailable())
+ }
+}
+
impl SecretBackend for EncryptedFileBackend {
fn get(&self, _: &str) -> Result<Option<String>, SecretStorageError> {
Err(unavailable())
diff --git a/crates/openhuman-core/src/security/secret_storage/encrypted_file_backend_disabled_tests.rs b/crates/openhuman-core/src/security/secret_storage/encrypted_file_backend_disabled_tests.rs
index d89ce7b205..9fe1f82a8d 100644
--- a/crates/openhuman-core/src/security/secret_storage/encrypted_file_backend_disabled_tests.rs
+++ b/crates/openhuman-core/src/security/secret_storage/encrypted_file_backend_disabled_tests.rs
@@ -15,3 +15,13 @@ fn selecting_encrypted_file_fails_closed_when_the_feature_is_disabled() {
.to_string()
.contains("enable the secret-file feature"));
}
+
+#[test]
+fn a_read_only_profile_lookup_fails_closed_when_the_feature_is_disabled() {
+ let backend = EncryptedFileBackend::new(Path::new("unused"));
+ assert!(backend
+ .get_profile_read_only("user/token")
+ .unwrap_err()
+ .to_string()
+ .contains("enable the secret-file feature"));
+}
diff --git a/scripts/ci/self-hosted/lanes-plan.mjs b/scripts/ci/self-hosted/lanes-plan.mjs
index d58d56d865..d3dd3ebf52 100644
--- a/scripts/ci/self-hosted/lanes-plan.mjs
+++ b/scripts/ci/self-hosted/lanes-plan.mjs
@@ -463,6 +463,13 @@ export function buildPlan({ profile, areas, env = {}, isPullRequest = true }) {
when: core,
run: "cargo check -p openhuman-embed --no-default-features",
},
+ // Hosts such as Chottu run modules with neither legacy storage import
+ // nor the encrypted secrets file; both are gated separately.
+ {
+ name: "embed-check-no-default-modules",
+ when: core,
+ run: "bash scripts/ci-cancel-aware.sh cargo check -p openhuman-embed --no-default-features --features modules",
+ },
// Consumers such as TinySweeper enable tracing without native modules.
{
name: "embed-check-no-default-langfuse",