Spaces:
Running
Running
feat(security): add security config models to AppConfig
Browse filesCo-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- agent_bench/core/config.py +39 -0
- configs/default.yaml +25 -0
- tests/test_security_config.py +58 -0
agent_bench/core/config.py
CHANGED
|
@@ -90,6 +90,44 @@ class EvaluationConfig(BaseModel):
|
|
| 90 |
golden_dataset: str = "agent_bench/evaluation/datasets/tech_docs_golden.json"
|
| 91 |
|
| 92 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
class AppConfig(BaseModel):
|
| 94 |
agent: AgentConfig = AgentConfig()
|
| 95 |
provider: ProviderConfig = ProviderConfig()
|
|
@@ -99,6 +137,7 @@ class AppConfig(BaseModel):
|
|
| 99 |
embedding: EmbeddingConfig = EmbeddingConfig()
|
| 100 |
serving: ServingConfig = ServingConfig()
|
| 101 |
evaluation: EvaluationConfig = EvaluationConfig()
|
|
|
|
| 102 |
|
| 103 |
|
| 104 |
# --- Task config ---
|
|
|
|
| 90 |
golden_dataset: str = "agent_bench/evaluation/datasets/tech_docs_golden.json"
|
| 91 |
|
| 92 |
|
| 93 |
+
class InjectionConfig(BaseModel):
|
| 94 |
+
enabled: bool = True
|
| 95 |
+
action: str = "block" # block | warn | flag
|
| 96 |
+
tiers: list[str] = ["heuristic", "classifier"]
|
| 97 |
+
classifier_url: str = ""
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
class PIIConfig(BaseModel):
|
| 101 |
+
enabled: bool = True
|
| 102 |
+
mode: str = "redact" # redact | detect_only | passthrough
|
| 103 |
+
redact_patterns: list[str] = [
|
| 104 |
+
"EMAIL", "PHONE", "SSN", "CREDIT_CARD", "IP_ADDRESS",
|
| 105 |
+
]
|
| 106 |
+
use_ner: bool = False
|
| 107 |
+
ner_entities: list[str] = ["PERSON"]
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
class OutputConfig(BaseModel):
|
| 111 |
+
enabled: bool = True
|
| 112 |
+
pii_check: bool = True
|
| 113 |
+
url_check: bool = True
|
| 114 |
+
blocklist: list[str] = []
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
class AuditConfig(BaseModel):
|
| 118 |
+
enabled: bool = True
|
| 119 |
+
path: str = "logs/audit.jsonl"
|
| 120 |
+
max_size_mb: int = 100
|
| 121 |
+
rotate: bool = True
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
class SecurityConfig(BaseModel):
|
| 125 |
+
injection: InjectionConfig = InjectionConfig()
|
| 126 |
+
pii: PIIConfig = PIIConfig()
|
| 127 |
+
output: OutputConfig = OutputConfig()
|
| 128 |
+
audit: AuditConfig = AuditConfig()
|
| 129 |
+
|
| 130 |
+
|
| 131 |
class AppConfig(BaseModel):
|
| 132 |
agent: AgentConfig = AgentConfig()
|
| 133 |
provider: ProviderConfig = ProviderConfig()
|
|
|
|
| 137 |
embedding: EmbeddingConfig = EmbeddingConfig()
|
| 138 |
serving: ServingConfig = ServingConfig()
|
| 139 |
evaluation: EvaluationConfig = EvaluationConfig()
|
| 140 |
+
security: SecurityConfig = SecurityConfig()
|
| 141 |
|
| 142 |
|
| 143 |
# --- Task config ---
|
configs/default.yaml
CHANGED
|
@@ -55,3 +55,28 @@ serving:
|
|
| 55 |
evaluation:
|
| 56 |
judge_provider: openai
|
| 57 |
golden_dataset: agent_bench/evaluation/datasets/tech_docs_golden.json
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
evaluation:
|
| 56 |
judge_provider: openai
|
| 57 |
golden_dataset: agent_bench/evaluation/datasets/tech_docs_golden.json
|
| 58 |
+
|
| 59 |
+
security:
|
| 60 |
+
injection:
|
| 61 |
+
enabled: true
|
| 62 |
+
action: block
|
| 63 |
+
tiers:
|
| 64 |
+
- heuristic
|
| 65 |
+
- classifier
|
| 66 |
+
classifier_url: ""
|
| 67 |
+
pii:
|
| 68 |
+
enabled: true
|
| 69 |
+
mode: redact
|
| 70 |
+
redact_patterns: [EMAIL, PHONE, SSN, CREDIT_CARD, IP_ADDRESS]
|
| 71 |
+
use_ner: false
|
| 72 |
+
ner_entities: [PERSON]
|
| 73 |
+
output:
|
| 74 |
+
enabled: true
|
| 75 |
+
pii_check: true
|
| 76 |
+
url_check: true
|
| 77 |
+
blocklist: []
|
| 78 |
+
audit:
|
| 79 |
+
enabled: true
|
| 80 |
+
path: logs/audit.jsonl
|
| 81 |
+
max_size_mb: 100
|
| 82 |
+
rotate: true
|
tests/test_security_config.py
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for security configuration models."""
|
| 2 |
+
|
| 3 |
+
from agent_bench.core.config import AppConfig
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
class TestSecurityConfig:
|
| 7 |
+
def test_security_config_has_defaults(self):
|
| 8 |
+
"""SecurityConfig is present on AppConfig with sane defaults."""
|
| 9 |
+
config = AppConfig()
|
| 10 |
+
assert config.security.injection.enabled is True
|
| 11 |
+
assert config.security.injection.action == "block"
|
| 12 |
+
assert config.security.injection.tiers == ["heuristic", "classifier"]
|
| 13 |
+
assert config.security.pii.enabled is True
|
| 14 |
+
assert config.security.pii.mode == "redact"
|
| 15 |
+
assert "EMAIL" in config.security.pii.redact_patterns
|
| 16 |
+
assert config.security.pii.use_ner is False
|
| 17 |
+
assert config.security.output.enabled is True
|
| 18 |
+
assert config.security.output.pii_check is True
|
| 19 |
+
assert config.security.output.url_check is True
|
| 20 |
+
assert config.security.output.blocklist == []
|
| 21 |
+
assert config.security.audit.enabled is True
|
| 22 |
+
assert config.security.audit.path == "logs/audit.jsonl"
|
| 23 |
+
|
| 24 |
+
def test_security_config_from_yaml(self, tmp_path):
|
| 25 |
+
"""Security config loads from YAML correctly."""
|
| 26 |
+
import yaml
|
| 27 |
+
config_data = {
|
| 28 |
+
"security": {
|
| 29 |
+
"injection": {"enabled": False, "action": "warn"},
|
| 30 |
+
"pii": {"mode": "passthrough", "use_ner": True},
|
| 31 |
+
"audit": {"path": "custom/audit.jsonl", "max_size_mb": 50},
|
| 32 |
+
}
|
| 33 |
+
}
|
| 34 |
+
yaml_path = tmp_path / "test.yaml"
|
| 35 |
+
yaml_path.write_text(yaml.dump(config_data))
|
| 36 |
+
|
| 37 |
+
from agent_bench.core.config import load_config
|
| 38 |
+
config = load_config(path=yaml_path)
|
| 39 |
+
assert config.security.injection.enabled is False
|
| 40 |
+
assert config.security.injection.action == "warn"
|
| 41 |
+
assert config.security.pii.mode == "passthrough"
|
| 42 |
+
assert config.security.pii.use_ner is True
|
| 43 |
+
assert config.security.audit.path == "custom/audit.jsonl"
|
| 44 |
+
assert config.security.audit.max_size_mb == 50
|
| 45 |
+
|
| 46 |
+
def test_injection_action_values(self):
|
| 47 |
+
"""Injection action accepts block, warn, flag."""
|
| 48 |
+
from agent_bench.core.config import InjectionConfig
|
| 49 |
+
for action in ("block", "warn", "flag"):
|
| 50 |
+
cfg = InjectionConfig(action=action)
|
| 51 |
+
assert cfg.action == action
|
| 52 |
+
|
| 53 |
+
def test_pii_mode_values(self):
|
| 54 |
+
"""PII mode accepts redact, detect_only, passthrough."""
|
| 55 |
+
from agent_bench.core.config import PIIConfig
|
| 56 |
+
for mode in ("redact", "detect_only", "passthrough"):
|
| 57 |
+
cfg = PIIConfig(mode=mode)
|
| 58 |
+
assert cfg.mode == mode
|