Skip to content

Personal AI, On Personal Devices

Python

feat: security profiles — personal, shared, server presets with user overrides

Jon Saad-Falcon57ecd5c77fb8
diff --git a/src/openjarvis/core/config.py b/src/openjarvis/core/config.py
index 23f41635..dea8ab2c 100644
--- a/src/openjarvis/core/config.py
+++ b/src/openjarvis/core/config.py
@@ -1006,6 +1006,83 @@ class SecurityConfig:
capabilities: CapabilitiesConfig = field(default_factory=CapabilitiesConfig)
+# ---------------------------------------------------------------------------
+# Security profile presets
+# ---------------------------------------------------------------------------
+
+_SECURITY_PROFILES: Dict[str, Dict[str, Dict[str, Any]]] = {
+ "personal": {
+ "security": {
+ "mode": "redact",
+ "rate_limit_enabled": True,
+ "local_engine_bypass": False,
+ "local_tool_bypass": False,
+ },
+ "server": {
+ "host": "127.0.0.1",
+ },
+ },
+ "shared": {
+ "security": {
+ "mode": "redact",
+ "rate_limit_enabled": True,
+ "local_engine_bypass": False,
+ "local_tool_bypass": False,
+ },
+ "server": {
+ "host": "127.0.0.1",
+ },
+ },
+ "server": {
+ "security": {
+ "mode": "block",
+ "rate_limit_enabled": True,
+ "rate_limit_rpm": 30,
+ "rate_limit_burst": 5,
+ "local_engine_bypass": False,
+ "local_tool_bypass": False,
+ },
+ "server": {
+ "host": "0.0.0.0",
+ },
+ },
+}
+
+
+def apply_security_profile(
+ security_cfg: "SecurityConfig",
+ server_cfg: "ServerConfig | None",
+ *,
+ overrides: "set[str] | None" = None,
+) -> None:
+ """Expand a named security profile into config fields.
+
+ Fields in *overrides* (explicitly set by the user in TOML) are
+ not overwritten by the profile.
+ """
+ profile = security_cfg.profile
+ if not profile:
+ return
+
+ if profile not in _SECURITY_PROFILES:
+ raise ValueError(
+ f"Unknown security profile '{profile}'. "
+ f"Valid profiles: {', '.join(_SECURITY_PROFILES)}"
+ )
+
+ _overrides = overrides or set()
+ pdef = _SECURITY_PROFILES[profile]
+
+ for key, value in pdef.get("security", {}).items():
+ if key not in _overrides and hasattr(security_cfg, key):
+ setattr(security_cfg, key, value)
+
+ if server_cfg is not None:
+ for key, value in pdef.get("server", {}).items():
+ if key not in _overrides and hasattr(server_cfg, key):
+ setattr(server_cfg, key, value)
+
+
@dataclass(slots=True)
class SandboxConfig:
"""Container sandbox settings."""
@@ -1386,6 +1463,14 @@ def load_config(path: Optional[Path] = None) -> JarvisConfig:
if "memory" in data:
_apply_toml_section(cfg.tools.storage, data["memory"])
+ # Expand security profile (user TOML overrides take precedence)
+ _user_security_keys = set(data.get("security", {}).keys())
+ apply_security_profile(cfg.security, cfg.server, overrides=_user_security_keys)
+
+ # Apply profile even without a config file (in case defaults set one)
+ if not config_path.exists() and cfg.security.profile:
+ apply_security_profile(cfg.security, cfg.server)
+
return cfg
diff --git a/tests/security/test_security_profiles.py b/tests/security/test_security_profiles.py
new file mode 100644
index 00000000..8086ed69
--- /dev/null
+++ b/tests/security/test_security_profiles.py
@@ -0,0 +1,54 @@
+"""Tests for security profile expansion (Section 7)."""
+
+from __future__ import annotations
+
+import pytest
+
+
+class TestProfileExpansion:
+ """Profiles should pre-fill security and server config fields."""
+
+ def test_personal_profile_sets_redact(self) -> None:
+ from openjarvis.core.config import SecurityConfig, apply_security_profile
+
+ cfg = SecurityConfig(profile="personal")
+ apply_security_profile(cfg, None)
+ assert cfg.mode == "redact"
+ assert cfg.rate_limit_enabled is True
+
+ def test_server_profile_sets_block(self) -> None:
+ from openjarvis.core.config import (
+ SecurityConfig,
+ ServerConfig,
+ apply_security_profile,
+ )
+
+ cfg = SecurityConfig(profile="server")
+ server_cfg = ServerConfig()
+ apply_security_profile(cfg, server_cfg)
+ assert cfg.mode == "block"
+ assert cfg.rate_limit_rpm == 30
+ assert cfg.rate_limit_burst == 5
+ assert server_cfg.host == "0.0.0.0"
+
+ def test_explicit_override_beats_profile(self) -> None:
+ from openjarvis.core.config import SecurityConfig, apply_security_profile
+
+ cfg = SecurityConfig(profile="server", mode="warn")
+ apply_security_profile(cfg, None, overrides={"mode"})
+ assert cfg.mode == "warn"
+
+ def test_empty_profile_is_noop(self) -> None:
+ from openjarvis.core.config import SecurityConfig, apply_security_profile
+
+ cfg = SecurityConfig()
+ original_mode = cfg.mode
+ apply_security_profile(cfg, None)
+ assert cfg.mode == original_mode
+
+ def test_unknown_profile_raises(self) -> None:
+ from openjarvis.core.config import SecurityConfig, apply_security_profile
+
+ cfg = SecurityConfig(profile="nonexistent")
+ with pytest.raises(ValueError, match="Unknown security profile"):
+ apply_security_profile(cfg, None)