actshield 0.9.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- actshield/__init__.py +439 -0
- actshield/__main__.py +46 -0
- actshield/agents/__init__.py +12 -0
- actshield/agents/agent.py +200 -0
- actshield/agents/identity.py +114 -0
- actshield/api/__init__.py +34 -0
- actshield/api/models.py +198 -0
- actshield/api/server.py +669 -0
- actshield/api/service.py +599 -0
- actshield/approval/__init__.py +15 -0
- actshield/approval/approval.py +164 -0
- actshield/cli/__init__.py +8 -0
- actshield/cli/graph.py +49 -0
- actshield/cli/main.py +802 -0
- actshield/cli/shell.py +406 -0
- actshield/cli/theme.py +110 -0
- actshield/client.py +757 -0
- actshield/config.py +88 -0
- actshield/context/__init__.py +14 -0
- actshield/context/context.py +161 -0
- actshield/context/provenance.py +108 -0
- actshield/context/taint.py +48 -0
- actshield/decisions/decision.py +74 -0
- actshield/delegation/__init__.py +11 -0
- actshield/delegation/authority.py +63 -0
- actshield/delegation/delegation.py +180 -0
- actshield/demo.py +139 -0
- actshield/doctor.py +94 -0
- actshield/drift/__init__.py +27 -0
- actshield/drift/drift_engine.py +149 -0
- actshield/drift/drift_models.py +63 -0
- actshield/evaluation/__init__.py +1 -0
- actshield/evaluation/cases/__init__.py +1 -0
- actshield/evaluation/eval_suite.py +254 -0
- actshield/forensics/__init__.py +53 -0
- actshield/forensics/access_graph.py +216 -0
- actshield/forensics/authority_graph.py +186 -0
- actshield/forensics/delegation_graph.py +119 -0
- actshield/forensics/explanation.py +254 -0
- actshield/forensics/models.py +488 -0
- actshield/forensics/queries.py +367 -0
- actshield/forensics/serializers.py +68 -0
- actshield/forensics/service.py +310 -0
- actshield/forensics/snapshots.py +174 -0
- actshield/gates/__init__.py +13 -0
- actshield/gates/gate_models.py +46 -0
- actshield/gates/security_gate.py +191 -0
- actshield/gateway/__init__.py +13 -0
- actshield/gateway/http.py +191 -0
- actshield/gateway/mcp.py +292 -0
- actshield/incidents/__init__.py +25 -0
- actshield/incidents/incident.py +94 -0
- actshield/incidents/incident_engine.py +163 -0
- actshield/incidents/incident_rules.py +116 -0
- actshield/incidents/incident_state.py +58 -0
- actshield/integrations/__init__.py +24 -0
- actshield/integrations/ai_secura.py +169 -0
- actshield/integrations/ai_secura_analysis.py +236 -0
- actshield/integrations/apiris.py +122 -0
- actshield/integrations/few_shot.py +104 -0
- actshield/integrations/ollama_adapter.py +538 -0
- actshield/integrations/prompts/__init__.py +1 -0
- actshield/integrations/prompts/examples/__init__.py +1 -0
- actshield/integrations/security_packet.py +82 -0
- actshield/llm_config.py +89 -0
- actshield/offensive/__init__.py +95 -0
- actshield/offensive/adaptive/__init__.py +22 -0
- actshield/offensive/adaptive/adaptive_engine.py +165 -0
- actshield/offensive/adaptive/attack_selector.py +51 -0
- actshield/offensive/adaptive/boundary_search.py +99 -0
- actshield/offensive/adaptive/campaign_memory.py +123 -0
- actshield/offensive/adaptive/feedback.py +84 -0
- actshield/offensive/adaptive/mutation_planner.py +57 -0
- actshield/offensive/attack.py +78 -0
- actshield/offensive/campaign.py +219 -0
- actshield/offensive/corpus.py +155 -0
- actshield/offensive/engine.py +466 -0
- actshield/offensive/evaluator.py +116 -0
- actshield/offensive/evidence.py +63 -0
- actshield/offensive/generator.py +128 -0
- actshield/offensive/mutation.py +101 -0
- actshield/offensive/results.py +77 -0
- actshield/offensive/safety.py +80 -0
- actshield/offensive/strategies/__init__.py +22 -0
- actshield/offensive/strategies/authority_escalation.py +100 -0
- actshield/offensive/strategies/base.py +34 -0
- actshield/offensive/strategies/context_manipulation.py +100 -0
- actshield/offensive/strategies/data_exfiltration.py +100 -0
- actshield/offensive/strategies/delegation_attacks.py +100 -0
- actshield/offensive/strategies/mcp_attacks.py +100 -0
- actshield/offensive/strategies/prompt_injection.py +100 -0
- actshield/offensive/strategies/tool_poisoning.py +100 -0
- actshield/offensive/target.py +113 -0
- actshield/offensive/vulnerable_target.py +121 -0
- actshield/persistence/__init__.py +18 -0
- actshield/persistence/siem.py +102 -0
- actshield/persistence/storage.py +240 -0
- actshield/policy/__init__.py +12 -0
- actshield/policy/evaluator.py +294 -0
- actshield/policy/intent.py +113 -0
- actshield/policy/policy.py +48 -0
- actshield/posture/__init__.py +26 -0
- actshield/posture/posture_engine.py +186 -0
- actshield/posture/posture_models.py +152 -0
- actshield/posture/posture_rules.py +137 -0
- actshield/providers/__init__.py +32 -0
- actshield/providers/anthropic_provider.py +146 -0
- actshield/providers/base.py +160 -0
- actshield/providers/gemini_provider.py +133 -0
- actshield/providers/null_provider.py +40 -0
- actshield/providers/ollama_provider.py +135 -0
- actshield/providers/openai_provider.py +142 -0
- actshield/providers/registry.py +244 -0
- actshield/py.typed +0 -0
- actshield/response/__init__.py +14 -0
- actshield/response/response_actions.py +39 -0
- actshield/response/response_audit.py +32 -0
- actshield/response/response_engine.py +139 -0
- actshield/risk/models.py +104 -0
- actshield/serve.py +117 -0
- actshield/static/404.html +1 -0
- actshield/static/__next.__PAGE__.txt +24 -0
- actshield/static/__next._full.txt +20 -0
- actshield/static/__next._tree.txt +4 -0
- actshield/static/_next/static/Yp_swxN-C9UoCRNOwkYnY/_buildManifest.js +11 -0
- actshield/static/_next/static/Yp_swxN-C9UoCRNOwkYnY/_clientMiddlewareManifest.js +1 -0
- actshield/static/_next/static/Yp_swxN-C9UoCRNOwkYnY/_ssgManifest.js +1 -0
- actshield/static/_next/static/chunks/09kny2eqjc2or.js +1 -0
- actshield/static/_next/static/chunks/0c1zba1u9whdp.js +1 -0
- actshield/static/_next/static/chunks/0cz1d0mv5g_q7.js +1 -0
- actshield/static/_next/static/chunks/0dbjjeg01x25o.js +1 -0
- actshield/static/_next/static/chunks/0duobs55ne238.js +1 -0
- actshield/static/_next/static/chunks/0iaz41l6068e4.js +1 -0
- actshield/static/_next/static/chunks/0mjhyv72x2idp.js +1 -0
- actshield/static/_next/static/chunks/0nelpqfu_ciq6.js +1 -0
- actshield/static/_next/static/chunks/0p1bci9ch797v.js +1 -0
- actshield/static/_next/static/chunks/0tld_ygho5tgm.js +1 -0
- actshield/static/_next/static/chunks/0w1-y7oni66j9.js +1 -0
- actshield/static/_next/static/chunks/10537zyl427zj.js +1 -0
- actshield/static/_next/static/chunks/11pc_jkl3aggn.js +1 -0
- actshield/static/_next/static/chunks/16k7nw0b3t8ys.js +1 -0
- actshield/static/_next/static/chunks/19mx3mg6lkumu.js +1 -0
- actshield/static/_next/static/chunks/1_8p47b-kxg2a.js +1 -0
- actshield/static/_next/static/chunks/1dszjozwfqegx.js +1 -0
- actshield/static/_next/static/chunks/1h43jcb90-m2r.js +22 -0
- actshield/static/_next/static/chunks/1ly04cvt_wh_j.js +1 -0
- actshield/static/_next/static/chunks/1odxrypuwuwp_.js +1 -0
- actshield/static/_next/static/chunks/1oes4c35qz5ku.js +1 -0
- actshield/static/_next/static/chunks/1ow883jl4ln-r.js +16 -0
- actshield/static/_next/static/chunks/1po7bna1as8tc.js +1 -0
- actshield/static/_next/static/chunks/1rsh0og8ifkzx.js +1 -0
- actshield/static/_next/static/chunks/1v0lwzv-859z_.js +1 -0
- actshield/static/_next/static/chunks/25iat2epwx25a.js +1 -0
- actshield/static/_next/static/chunks/25uvt4s2f39a4.js +1 -0
- actshield/static/_next/static/chunks/27t_qfc-3_lzs.js +1 -0
- actshield/static/_next/static/chunks/28bkmy8mez7gm.js +1 -0
- actshield/static/_next/static/chunks/2b6brmw_drw1p.js +1 -0
- actshield/static/_next/static/chunks/2fnhtxi4j6vge.js +1 -0
- actshield/static/_next/static/chunks/2p087eftxemg4.js +6 -0
- actshield/static/_next/static/chunks/2s8pao_z8pgtq.js +1 -0
- actshield/static/_next/static/chunks/2yj7ooc2c-zpg.js +1 -0
- actshield/static/_next/static/chunks/3-mrrr8udt5tk.js +1 -0
- actshield/static/_next/static/chunks/310vm2bl3xxpt.js +31 -0
- actshield/static/_next/static/chunks/35mvsv251jx1r.css +3 -0
- actshield/static/_next/static/chunks/370vf0oetlsx9.js +1 -0
- actshield/static/_next/static/chunks/3e-2m72tyo556.js +1 -0
- actshield/static/_next/static/chunks/3fntmmi971322.js +1 -0
- actshield/static/_next/static/chunks/3fzw-g0hycl2c.js +1 -0
- actshield/static/_next/static/chunks/3lopq3lhmcjxg.js +129 -0
- actshield/static/_next/static/chunks/3mpe2jejel0v2.css +1 -0
- actshield/static/_next/static/chunks/3t8o4f2lzr2sf.js +1 -0
- actshield/static/_next/static/chunks/3y-v1neyllne5.js +1 -0
- actshield/static/_next/static/chunks/43oiwy8mx6cs1.js +1 -0
- actshield/static/_next/static/chunks/turbopack-23wzuebcy_lxm.js +1 -0
- actshield/static/_next/static/media/1bffadaabf893a1e-s.3-6t-g6q0vh0a.woff2 +0 -0
- actshield/static/_next/static/media/2bbe8d2671613f1f-s.0k62hbripvv8p.woff2 +0 -0
- actshield/static/_next/static/media/2c55a0e60120577a-s.0-dom-5bn10r2.woff2 +0 -0
- actshield/static/_next/static/media/5476f68d60460930-s.2uwcyprjm3xu3.woff2 +0 -0
- actshield/static/_next/static/media/83afe278b6a6bb3c-s.p.2bn3s6zvc0dyp.woff2 +0 -0
- actshield/static/_next/static/media/9c72aa0f40e4eef8-s.1y4-pdgsjb-pw.woff2 +0 -0
- actshield/static/_next/static/media/ad66f9afd8947f86-s.3lvt2whj97whp.woff2 +0 -0
- actshield/static/_next/static/media/favicon.2vob68tjqpejf.ico +0 -0
- actshield/static/_not-found/__next._full.txt +17 -0
- actshield/static/_not-found/__next._not-found/__PAGE__.txt +23 -0
- actshield/static/_not-found/__next._tree.txt +3 -0
- actshield/static/_not-found.html +1 -0
- actshield/static/_not-found.txt +17 -0
- actshield/static/access/matrix/__next._full.txt +24 -0
- actshield/static/access/matrix/__next._tree.txt +4 -0
- actshield/static/access/matrix/__next.access/matrix/__PAGE__.txt +30 -0
- actshield/static/access/matrix.html +1 -0
- actshield/static/access/matrix.txt +24 -0
- actshield/static/activity/__next._full.txt +22 -0
- actshield/static/activity/__next._tree.txt +4 -0
- actshield/static/activity/__next.activity/__PAGE__.txt +27 -0
- actshield/static/activity.html +1 -0
- actshield/static/activity.txt +22 -0
- actshield/static/agents/__next._full.txt +22 -0
- actshield/static/agents/__next._tree.txt +4 -0
- actshield/static/agents/__next.agents/__PAGE__.txt +27 -0
- actshield/static/agents.html +1 -0
- actshield/static/agents.txt +22 -0
- actshield/static/ai-secura/__next._full.txt +22 -0
- actshield/static/ai-secura/__next._tree.txt +4 -0
- actshield/static/ai-secura/__next.ai-secura/__PAGE__.txt +27 -0
- actshield/static/ai-secura.html +1 -0
- actshield/static/ai-secura.txt +22 -0
- actshield/static/api/__next._full.txt +22 -0
- actshield/static/api/__next._tree.txt +4 -0
- actshield/static/api/__next.api/__PAGE__.txt +27 -0
- actshield/static/api.html +15 -0
- actshield/static/api.txt +22 -0
- actshield/static/apiris/__next._full.txt +22 -0
- actshield/static/apiris/__next._tree.txt +4 -0
- actshield/static/apiris/__next.apiris/__PAGE__.txt +27 -0
- actshield/static/apiris.html +1 -0
- actshield/static/apiris.txt +22 -0
- actshield/static/attack-graph/__next._full.txt +23 -0
- actshield/static/attack-graph/__next._tree.txt +5 -0
- actshield/static/attack-graph/__next.attack-graph/__PAGE__.txt +28 -0
- actshield/static/attack-graph.html +2 -0
- actshield/static/attack-graph.txt +23 -0
- actshield/static/campaigns/__next._full.txt +22 -0
- actshield/static/campaigns/__next._tree.txt +4 -0
- actshield/static/campaigns/__next.campaigns/__PAGE__.txt +27 -0
- actshield/static/campaigns.html +1 -0
- actshield/static/campaigns.txt +22 -0
- actshield/static/context/__next._full.txt +22 -0
- actshield/static/context/__next._tree.txt +4 -0
- actshield/static/context/__next.context/__PAGE__.txt +27 -0
- actshield/static/context.html +1 -0
- actshield/static/context.txt +22 -0
- actshield/static/dashboard/__next._full.txt +22 -0
- actshield/static/dashboard/__next._tree.txt +4 -0
- actshield/static/dashboard/__next.dashboard/__PAGE__.txt +27 -0
- actshield/static/dashboard.html +1 -0
- actshield/static/dashboard.txt +22 -0
- actshield/static/delegations/__next._full.txt +22 -0
- actshield/static/delegations/__next._tree.txt +4 -0
- actshield/static/delegations/__next.delegations/__PAGE__.txt +27 -0
- actshield/static/delegations.html +1 -0
- actshield/static/delegations.txt +22 -0
- actshield/static/demo/__next._full.txt +22 -0
- actshield/static/demo/__next._tree.txt +4 -0
- actshield/static/demo/__next.demo/__PAGE__.txt +27 -0
- actshield/static/demo.html +1 -0
- actshield/static/demo.txt +22 -0
- actshield/static/drift/__next._full.txt +22 -0
- actshield/static/drift/__next._tree.txt +4 -0
- actshield/static/drift/__next.drift/__PAGE__.txt +27 -0
- actshield/static/drift.html +1 -0
- actshield/static/drift.txt +22 -0
- actshield/static/favicon.ico +0 -0
- actshield/static/file.svg +1 -0
- actshield/static/forensics/__next._full.txt +22 -0
- actshield/static/forensics/__next._tree.txt +4 -0
- actshield/static/forensics/__next.forensics/__PAGE__.txt +27 -0
- actshield/static/forensics.html +1 -0
- actshield/static/forensics.txt +22 -0
- actshield/static/globe.svg +1 -0
- actshield/static/incidents/__next._full.txt +22 -0
- actshield/static/incidents/__next._tree.txt +4 -0
- actshield/static/incidents/__next.incidents/__PAGE__.txt +27 -0
- actshield/static/incidents.html +1 -0
- actshield/static/incidents.txt +22 -0
- actshield/static/index.html +3 -0
- actshield/static/index.txt +20 -0
- actshield/static/logo.png +0 -0
- actshield/static/metrics/__next._full.txt +22 -0
- actshield/static/metrics/__next._tree.txt +4 -0
- actshield/static/metrics/__next.metrics/__PAGE__.txt +27 -0
- actshield/static/metrics.html +1 -0
- actshield/static/metrics.txt +22 -0
- actshield/static/next.svg +1 -0
- actshield/static/offensive/__next._full.txt +22 -0
- actshield/static/offensive/__next._tree.txt +4 -0
- actshield/static/offensive/__next.offensive/__PAGE__.txt +27 -0
- actshield/static/offensive.html +1 -0
- actshield/static/offensive.txt +22 -0
- actshield/static/policies/__next._full.txt +22 -0
- actshield/static/policies/__next._tree.txt +4 -0
- actshield/static/policies/__next.policies/__PAGE__.txt +27 -0
- actshield/static/policies.html +1 -0
- actshield/static/policies.txt +22 -0
- actshield/static/posture/__next._full.txt +22 -0
- actshield/static/posture/__next._tree.txt +4 -0
- actshield/static/posture/__next.posture/__PAGE__.txt +27 -0
- actshield/static/posture.html +1 -0
- actshield/static/posture.txt +22 -0
- actshield/static/regressions/__next._full.txt +22 -0
- actshield/static/regressions/__next._tree.txt +4 -0
- actshield/static/regressions/__next.regressions/__PAGE__.txt +27 -0
- actshield/static/regressions.html +1 -0
- actshield/static/regressions.txt +22 -0
- actshield/static/reports/__next._full.txt +22 -0
- actshield/static/reports/__next._tree.txt +4 -0
- actshield/static/reports/__next.reports/__PAGE__.txt +27 -0
- actshield/static/reports.html +1 -0
- actshield/static/reports.txt +22 -0
- actshield/static/resources/__next._full.txt +22 -0
- actshield/static/resources/__next._tree.txt +4 -0
- actshield/static/resources/__next.resources/__PAGE__.txt +27 -0
- actshield/static/resources.html +1 -0
- actshield/static/resources.txt +22 -0
- actshield/static/security-gates/__next._full.txt +22 -0
- actshield/static/security-gates/__next._tree.txt +4 -0
- actshield/static/security-gates/__next.security-gates/__PAGE__.txt +27 -0
- actshield/static/security-gates.html +1 -0
- actshield/static/security-gates.txt +22 -0
- actshield/static/settings/__next._full.txt +22 -0
- actshield/static/settings/__next._tree.txt +4 -0
- actshield/static/settings/__next.settings/__PAGE__.txt +27 -0
- actshield/static/settings.html +1 -0
- actshield/static/settings.txt +22 -0
- actshield/static/tasks/__next._full.txt +22 -0
- actshield/static/tasks/__next._tree.txt +4 -0
- actshield/static/tasks/__next.tasks/__PAGE__.txt +27 -0
- actshield/static/tasks.html +1 -0
- actshield/static/tasks.txt +22 -0
- actshield/static/threats/__next._full.txt +22 -0
- actshield/static/threats/__next._tree.txt +4 -0
- actshield/static/threats/__next.threats/__PAGE__.txt +27 -0
- actshield/static/threats.html +1 -0
- actshield/static/threats.txt +22 -0
- actshield/static/tools/__next._full.txt +22 -0
- actshield/static/tools/__next._tree.txt +4 -0
- actshield/static/tools/__next.tools/__PAGE__.txt +27 -0
- actshield/static/tools.html +1 -0
- actshield/static/tools.txt +22 -0
- actshield/static/traces/__next._full.txt +22 -0
- actshield/static/traces/__next._tree.txt +4 -0
- actshield/static/traces/__next.traces/__PAGE__.txt +27 -0
- actshield/static/traces.html +1 -0
- actshield/static/traces.txt +22 -0
- actshield/static/vercel.svg +1 -0
- actshield/static/window.svg +1 -0
- actshield/tasks/__init__.py +6 -0
- actshield/tasks/task.py +143 -0
- actshield/threatmodel/__init__.py +70 -0
- actshield/threatmodel/actors.py +210 -0
- actshield/threatmodel/analyzer.py +131 -0
- actshield/threatmodel/assets.py +167 -0
- actshield/threatmodel/boundaries.py +165 -0
- actshield/threatmodel/exporters.py +49 -0
- actshield/threatmodel/mitigations.py +209 -0
- actshield/threatmodel/models.py +80 -0
- actshield/threatmodel/report.py +341 -0
- actshield/threatmodel/scenarios.py +212 -0
- actshield/threatmodel/scoring.py +66 -0
- actshield/threatmodel/threats.py +387 -0
- actshield/tools/__init__.py +20 -0
- actshield/tools/interceptor.py +256 -0
- actshield/tools/tool.py +71 -0
- actshield/tracing/__init__.py +38 -0
- actshield/tracing/correlation.py +173 -0
- actshield/tracing/events.py +75 -0
- actshield/tracing/tracer.py +305 -0
- actshield/watch.py +129 -0
- actshield-0.9.0.dist-info/METADATA +57 -0
- actshield-0.9.0.dist-info/RECORD +366 -0
- actshield-0.9.0.dist-info/WHEEL +5 -0
- actshield-0.9.0.dist-info/entry_points.txt +4 -0
- actshield-0.9.0.dist-info/top_level.txt +2 -0
- agentguard/__init__.py +39 -0
- agentguard/__main__.py +8 -0
- agentguard/py.typed +1 -0
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
"""Human-in-the-Loop (HITL) approval governance and workflows."""
|
|
2
|
+
|
|
3
|
+
from datetime import datetime, timezone
|
|
4
|
+
from enum import Enum
|
|
5
|
+
from typing import Any, Callable, Dict, List, Optional
|
|
6
|
+
import uuid
|
|
7
|
+
from pydantic import BaseModel, Field
|
|
8
|
+
|
|
9
|
+
from actshield.decisions.decision import SecurityDecision
|
|
10
|
+
from actshield.tools.tool import ToolDefinition, ToolRequest
|
|
11
|
+
from actshield.tracing.events import EventType
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class ApprovalStatus(str, Enum):
|
|
15
|
+
"""Lifecycle status of a human approval ticket."""
|
|
16
|
+
PENDING = "PENDING"
|
|
17
|
+
APPROVED = "APPROVED"
|
|
18
|
+
REJECTED = "REJECTED"
|
|
19
|
+
EXPIRED = "EXPIRED"
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class ApprovalRequest(BaseModel):
|
|
23
|
+
"""Human-in-the-Loop approval ticket representation."""
|
|
24
|
+
request_id: str = Field(default_factory=lambda: f"appr_{uuid.uuid4().hex[:12]}")
|
|
25
|
+
trace_id: str
|
|
26
|
+
tool_name: str
|
|
27
|
+
tool_id: str
|
|
28
|
+
arguments: Dict[str, Any] = Field(default_factory=dict)
|
|
29
|
+
requesting_agent_id: Optional[str] = None
|
|
30
|
+
reason: str
|
|
31
|
+
risk_score: float = 0.0
|
|
32
|
+
status: ApprovalStatus = ApprovalStatus.PENDING
|
|
33
|
+
created_at: datetime = Field(default_factory=lambda: datetime.now(timezone.utc))
|
|
34
|
+
reviewed_at: Optional[datetime] = None
|
|
35
|
+
reviewer_id: Optional[str] = None
|
|
36
|
+
review_notes: Optional[str] = None
|
|
37
|
+
metadata: Dict[str, Any] = Field(default_factory=dict)
|
|
38
|
+
|
|
39
|
+
@property
|
|
40
|
+
def is_pending(self) -> bool:
|
|
41
|
+
return self.status == ApprovalStatus.PENDING
|
|
42
|
+
|
|
43
|
+
@property
|
|
44
|
+
def is_approved(self) -> bool:
|
|
45
|
+
return self.status == ApprovalStatus.APPROVED
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class ApprovalManager:
|
|
49
|
+
"""Manages pending human approval requests and approval lifecycle callbacks."""
|
|
50
|
+
|
|
51
|
+
def __init__(self, guard: Any) -> None:
|
|
52
|
+
self.guard = guard
|
|
53
|
+
self._requests: Dict[str, ApprovalRequest] = {}
|
|
54
|
+
self._handlers: List[Callable[[ApprovalRequest], None]] = []
|
|
55
|
+
|
|
56
|
+
def register_notification_handler(self, handler: Callable[[ApprovalRequest], None]) -> None:
|
|
57
|
+
"""Register a callback for new approval requests (e.g. Slack/Teams/PagerDuty notification)."""
|
|
58
|
+
self._handlers.append(handler)
|
|
59
|
+
|
|
60
|
+
def request_approval(
|
|
61
|
+
self,
|
|
62
|
+
tool_def: ToolDefinition,
|
|
63
|
+
request: ToolRequest,
|
|
64
|
+
decision: SecurityDecision,
|
|
65
|
+
trace_id: str,
|
|
66
|
+
reason: Optional[str] = None,
|
|
67
|
+
) -> ApprovalRequest:
|
|
68
|
+
"""Create and register a pending human approval ticket."""
|
|
69
|
+
appr = ApprovalRequest(
|
|
70
|
+
trace_id=trace_id,
|
|
71
|
+
tool_name=tool_def.name,
|
|
72
|
+
tool_id=tool_def.tool_id,
|
|
73
|
+
arguments=request.arguments,
|
|
74
|
+
requesting_agent_id=request.agent_id,
|
|
75
|
+
reason=reason or decision.explanation or "Requires explicit human confirmation.",
|
|
76
|
+
risk_score=decision.risk_score,
|
|
77
|
+
metadata={
|
|
78
|
+
"sensitivity": tool_def.sensitivity.value,
|
|
79
|
+
"reason_code": decision.reason_code,
|
|
80
|
+
},
|
|
81
|
+
)
|
|
82
|
+
self._requests[appr.request_id] = appr
|
|
83
|
+
|
|
84
|
+
# Emit approval.requested event
|
|
85
|
+
self.guard.emit_event(
|
|
86
|
+
event_type=EventType.APPROVAL_REQUESTED,
|
|
87
|
+
trace_id=trace_id,
|
|
88
|
+
agent_id=request.agent_id,
|
|
89
|
+
payload={
|
|
90
|
+
"approval_id": appr.request_id,
|
|
91
|
+
"tool_name": tool_def.name,
|
|
92
|
+
"reason": appr.reason,
|
|
93
|
+
"risk_score": appr.risk_score,
|
|
94
|
+
"status": appr.status.value,
|
|
95
|
+
},
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
for handler in self._handlers:
|
|
99
|
+
try:
|
|
100
|
+
handler(appr)
|
|
101
|
+
except Exception:
|
|
102
|
+
pass
|
|
103
|
+
|
|
104
|
+
return appr
|
|
105
|
+
|
|
106
|
+
def approve(self, request_id: str, reviewer_id: str, notes: str = "Approved by authorized human operator") -> ApprovalRequest:
|
|
107
|
+
"""Grant approval to a pending request."""
|
|
108
|
+
if request_id not in self._requests:
|
|
109
|
+
raise KeyError(f"Approval request '{request_id}' not found.")
|
|
110
|
+
|
|
111
|
+
req = self._requests[request_id]
|
|
112
|
+
if req.status != ApprovalStatus.PENDING:
|
|
113
|
+
raise ValueError(f"Approval request '{request_id}' is not in PENDING status (current: {req.status}).")
|
|
114
|
+
|
|
115
|
+
req.status = ApprovalStatus.APPROVED
|
|
116
|
+
req.reviewer_id = reviewer_id
|
|
117
|
+
req.review_notes = notes
|
|
118
|
+
req.reviewed_at = datetime.now(timezone.utc)
|
|
119
|
+
|
|
120
|
+
# Emit approval.granted event
|
|
121
|
+
self.guard.emit_event(
|
|
122
|
+
event_type=EventType.APPROVAL_GRANTED,
|
|
123
|
+
trace_id=req.trace_id,
|
|
124
|
+
agent_id=req.requesting_agent_id,
|
|
125
|
+
payload={
|
|
126
|
+
"approval_id": req.request_id,
|
|
127
|
+
"tool_name": req.tool_name,
|
|
128
|
+
"reviewer_id": reviewer_id,
|
|
129
|
+
"notes": notes,
|
|
130
|
+
},
|
|
131
|
+
)
|
|
132
|
+
return req
|
|
133
|
+
|
|
134
|
+
def reject(self, request_id: str, reviewer_id: str, notes: str = "Rejected by human security operator") -> ApprovalRequest:
|
|
135
|
+
"""Reject a pending approval request."""
|
|
136
|
+
if request_id not in self._requests:
|
|
137
|
+
raise KeyError(f"Approval request '{request_id}' not found.")
|
|
138
|
+
|
|
139
|
+
req = self._requests[request_id]
|
|
140
|
+
req.status = ApprovalStatus.REJECTED
|
|
141
|
+
req.reviewer_id = reviewer_id
|
|
142
|
+
req.review_notes = notes
|
|
143
|
+
req.reviewed_at = datetime.now(timezone.utc)
|
|
144
|
+
|
|
145
|
+
# Emit approval.rejected event
|
|
146
|
+
self.guard.emit_event(
|
|
147
|
+
event_type=EventType.APPROVAL_REJECTED,
|
|
148
|
+
trace_id=req.trace_id,
|
|
149
|
+
agent_id=req.requesting_agent_id,
|
|
150
|
+
payload={
|
|
151
|
+
"approval_id": req.request_id,
|
|
152
|
+
"tool_name": req.tool_name,
|
|
153
|
+
"reviewer_id": reviewer_id,
|
|
154
|
+
"notes": notes,
|
|
155
|
+
},
|
|
156
|
+
)
|
|
157
|
+
return req
|
|
158
|
+
|
|
159
|
+
def get_request(self, request_id: str) -> Optional[ApprovalRequest]:
|
|
160
|
+
return self._requests.get(request_id)
|
|
161
|
+
|
|
162
|
+
def get_pending_requests(self) -> List[ApprovalRequest]:
|
|
163
|
+
return [r for r in self._requests.values() if r.status == ApprovalStatus.PENDING]
|
|
164
|
+
|
actshield/cli/graph.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"""ActShield Multi-Agent Topology & Graph Visualizer for CLI."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
from typing import Dict, List, Optional
|
|
5
|
+
from rich.console import Console
|
|
6
|
+
from rich.panel import Panel
|
|
7
|
+
from rich.text import Text
|
|
8
|
+
from rich.tree import Tree
|
|
9
|
+
|
|
10
|
+
from actshield.agents.identity import AgentStatus, AgentTrustLevel
|
|
11
|
+
from actshield.client import ActShield
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def render_agent_topology(guard: Optional[ActShield] = None) -> None:
|
|
15
|
+
"""Render the multi-agent execution and delegation topology graph."""
|
|
16
|
+
console = Console()
|
|
17
|
+
|
|
18
|
+
# Root user node
|
|
19
|
+
tree = Tree("[bold white]USER (Principal / Origin)[/bold white]")
|
|
20
|
+
|
|
21
|
+
# Orchestrator
|
|
22
|
+
orch = tree.add("[bold magenta]ORCHESTRATOR [dim](orchestrator-001)[/dim] ● ACTIVE [green]HIGH TRUST[/green][/bold magenta]")
|
|
23
|
+
|
|
24
|
+
# Research child
|
|
25
|
+
research_branch = orch.add("[bold purple]RESEARCH [dim](research-agent-001)[/dim] ● ACTIVE [green]MEDIUM TRUST[/green][/bold purple]")
|
|
26
|
+
mcp_node = research_branch.add("[bold bright_cyan]MCP GATEWAY [dim](upstream-docs)[/dim] [yellow]TAINT SENSITIVE[/yellow][/bold bright_cyan]")
|
|
27
|
+
mcp_node.add("[dim white]TOOL: web_search [ALLOW][/dim white]")
|
|
28
|
+
|
|
29
|
+
# Analysis child
|
|
30
|
+
analysis_branch = orch.add("[bold purple]ANALYSIS [dim](analysis-agent-001)[/dim] ● ACTIVE [green]HIGH TRUST[/green][/bold purple]")
|
|
31
|
+
data_node = analysis_branch.add("[bold rgb(249,115,22)]DATA PIPELINE [dim](db-reader)[/dim] [orange3]RESTRICTED[/orange3][/bold rgb(249,115,22)]")
|
|
32
|
+
data_node.add("[dim white]TOOL: customer_db.read [PROTECTED / EVALUATED][/dim white]")
|
|
33
|
+
|
|
34
|
+
# Quarantined / External branch
|
|
35
|
+
external_branch = tree.add("[bold red]EXTERNAL MCP AGENT [dim](ext-untrusted-09)[/dim] ● QUARANTINED [red]UNTRUSTED[/red][/bold red]")
|
|
36
|
+
external_branch.add("[bold red]VIOLATION: Authority Boundary Exceeded -> AUTO-QUARANTINED[/bold red]")
|
|
37
|
+
|
|
38
|
+
console.print()
|
|
39
|
+
console.print(
|
|
40
|
+
Panel(
|
|
41
|
+
tree,
|
|
42
|
+
title="[bold magenta]🛡️ ActShield MULTI-AGENT SECURITY TOPOLOGY[/bold magenta]",
|
|
43
|
+
subtitle="[dim white]Purple = Active Agent │ Red = Quarantined/Blocked │ Cyan = Gateway/MCP │ Orange = Sensitive Resource[/dim white]",
|
|
44
|
+
border_style="magenta",
|
|
45
|
+
)
|
|
46
|
+
)
|
|
47
|
+
console.print()
|
|
48
|
+
|
|
49
|
+
|