Security and Governance Framework
Securing Agentic AI Systems
Document ID: C3-SECURITY | Version: 1.0 | Category: P3 - Technical Deep Dives
Executive Summary
Agentic systems introduce unique security challenges: autonomous action, tool access, and persistent memory. This guide provides security patterns for production deployment.
Threat Model
Agent-Specific Threats
| Threat | Description | Impact | Mitigation |
|---|---|---|---|
| Prompt Injection | Malicious input manipulation | Unauthorized actions | Input validation |
| Tool Abuse | Misuse of tool capabilities | Data breach, damage | Least privilege |
| Memory Poisoning | Corrupted memory retrieval | Wrong decisions | Memory validation |
| Jailbreaking | Bypass safety constraints | Policy violations | Defense in depth |
| Data Exfiltration | Unauthorized data access | Privacy breach | Access controls |
Security Controls
Input Validation
class InputValidator:
"""Validate and sanitize agent inputs."""
INJECTION_PATTERNS = [
r"ignore previous instructions",
r"disregard .* instructions",
r"you are now",
r"new persona",
r"system prompt",
r"</?(system|user|assistant)>"
]
def validate(self, input_text: str) -> tuple[bool, str]:
# Check for injection patterns
for pattern in self.INJECTION_PATTERNS:
if re.search(pattern, input_text, re.IGNORECASE):
return False, f"Potential injection detected: {pattern}"
# Length limits
if len(input_text) > 100000:
return False, "Input exceeds maximum length"
# Encoding validation
try:
input_text.encode('utf-8')
except UnicodeError:
return False, "Invalid encoding"
return True, "Valid"
Tool Access Control
class ToolAccessControl:
"""Role-based tool access control."""
def __init__(self):
self.role_permissions = {
"reader": ["knowledge_search", "web_search"],
"writer": ["knowledge_search", "web_search", "file_write"],
"admin": ["*"]
}
self.tool_risk_levels = {
"knowledge_search": "low",
"web_search": "low",
"file_write": "medium",
"database_write": "high",
"api_call": "high",
"code_execute": "critical"
}
def check_permission(self, user_role: str, tool_name: str) -> bool:
allowed = self.role_permissions.get(user_role, [])
return "*" in allowed or tool_name in allowed
def requires_approval(self, tool_name: str, user_role: str) -> bool:
risk = self.tool_risk_levels.get(tool_name, "high")
if risk == "critical":
return True
if risk == "high" and user_role != "admin":
return True
return False
Memory Security
class SecureMemory:
"""Secure memory with encryption and access control."""
def __init__(self, encryption_key: bytes):
from cryptography.fernet import Fernet
self.cipher = Fernet(encryption_key)
def encrypt_memory(self, content: str) -> bytes:
return self.cipher.encrypt(content.encode())
def decrypt_memory(self, encrypted: bytes) -> str:
return self.cipher.decrypt(encrypted).decode()
def validate_memory(self, content: str) -> bool:
# Check for injection in memory content
validator = InputValidator()
is_valid, _ = validator.validate(content)
return is_valid
Governance Framework
Policy Enforcement
| Policy | Enforcement | Monitoring |
|---|---|---|
| Data retention | Automatic purge | Retention audit |
| Access logging | All actions logged | Log review |
| Model usage | Approved models only | Usage tracking |
| Cost limits | Budget enforcement | Spend alerts |
| Quality gates | Review requirements | Approval tracking |
Audit Requirements
class AuditLogger:
"""Immutable audit logging."""
def log_action(
self,
user_id: str,
agent_id: str,
action: str,
target: str,
result: str
):
record = {
"timestamp": datetime.utcnow().isoformat(),
"user_id": user_id,
"agent_id": agent_id,
"action": action,
"target": target,
"result": result,
"hash": self._compute_hash(...)
}
# Write to immutable store
self.store.append(record)
Compliance Mapping
| Framework | Requirements | Agent Implementation |
|---|---|---|
| SOC 2 | Access controls | RBAC, audit logs |
| GDPR | Data protection | Encryption, retention |
| HIPAA | PHI security | Isolation, audit |
| PCI DSS | Cardholder data | Tokenization, access |
Quick Reference
| Control | Implementation | Verification |
|---|---|---|
| Input validation | Pattern matching | Unit tests |
| Tool access | RBAC | Permission audit |
| Memory encryption | AES-256 | Key rotation |
| Audit logging | Immutable store | Log integrity |
| Rate limiting | Token bucket | Monitoring |
Document maintained by CODITECT Security Team