agentlighthouse-core 0.4.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.
Files changed (78) hide show
  1. agentlighthouse_core-0.4.0.dist-info/METADATA +358 -0
  2. agentlighthouse_core-0.4.0.dist-info/RECORD +78 -0
  3. agentlighthouse_core-0.4.0.dist-info/WHEEL +4 -0
  4. agentlighthouse_core-0.4.0.dist-info/entry_points.txt +2 -0
  5. agentlighthouse_core-0.4.0.dist-info/licenses/LICENSE +21 -0
  6. al_core/__init__.py +12 -0
  7. al_core/_bundled/configs/audit.yaml +12 -0
  8. al_core/_bundled/configs/balanced.yaml +36 -0
  9. al_core/_bundled/configs/strict.yaml +32 -0
  10. al_core/_bundled/dashboard/assets/index-CN2LU6nV.css +1 -0
  11. al_core/_bundled/dashboard/assets/index-DX6cZzRi.js +40 -0
  12. al_core/_bundled/dashboard/index.html +15 -0
  13. al_core/_bundled/policies/default-deny.yaml +37 -0
  14. al_core/a2a/__init__.py +25 -0
  15. al_core/a2a/envelope.py +60 -0
  16. al_core/a2a/mediator.py +221 -0
  17. al_core/app.py +427 -0
  18. al_core/audit/__init__.py +149 -0
  19. al_core/audit/db.py +481 -0
  20. al_core/audit/pg.py +350 -0
  21. al_core/audit/pool.py +260 -0
  22. al_core/audit/siem.py +97 -0
  23. al_core/capability/__init__.py +28 -0
  24. al_core/capability/budget.py +56 -0
  25. al_core/capability/gate.py +334 -0
  26. al_core/capability/hitl.py +331 -0
  27. al_core/capability/policy.py +270 -0
  28. al_core/capability/store.py +209 -0
  29. al_core/capability/taint.py +79 -0
  30. al_core/cli/__init__.py +1 -0
  31. al_core/cli/main.py +1275 -0
  32. al_core/config/__init__.py +436 -0
  33. al_core/config/watch.py +51 -0
  34. al_core/detect/__init__.py +23 -0
  35. al_core/detect/base.py +131 -0
  36. al_core/detect/bip39_words.py +267 -0
  37. al_core/detect/budget.py +92 -0
  38. al_core/detect/detect_secrets_adapter.py +110 -0
  39. al_core/detect/engine.py +270 -0
  40. al_core/detect/scanners.py +454 -0
  41. al_core/egress/__init__.py +27 -0
  42. al_core/egress/nftables.py +59 -0
  43. al_core/egress/selftest.py +94 -0
  44. al_core/embed.py +51 -0
  45. al_core/gateway/__init__.py +29 -0
  46. al_core/gateway/content.py +154 -0
  47. al_core/gateway/decision.py +124 -0
  48. al_core/gateway/dnspin.py +131 -0
  49. al_core/gateway/forward.py +261 -0
  50. al_core/gateway/policy.py +66 -0
  51. al_core/gateway/ssrf.py +178 -0
  52. al_core/gateway/vkeys.py +205 -0
  53. al_core/gateway/web.py +801 -0
  54. al_core/identity/__init__.py +209 -0
  55. al_core/jsonstore.py +73 -0
  56. al_core/keys/__init__.py +141 -0
  57. al_core/killswitch.py +130 -0
  58. al_core/learn/__init__.py +17 -0
  59. al_core/learn/bundle.py +76 -0
  60. al_core/learn/miner.py +156 -0
  61. al_core/learn/scanner.py +77 -0
  62. al_core/learn/testgen.py +107 -0
  63. al_core/mcp/__init__.py +25 -0
  64. al_core/mcp/chain.py +147 -0
  65. al_core/mcp/descriptors.py +111 -0
  66. al_core/mcp/mediator.py +150 -0
  67. al_core/mcp/proxy.py +161 -0
  68. al_core/mcp/session.py +537 -0
  69. al_core/memory/__init__.py +15 -0
  70. al_core/memory/guard.py +330 -0
  71. al_core/memory/store.py +80 -0
  72. al_core/normalize/__init__.py +254 -0
  73. al_core/principal.py +59 -0
  74. al_core/receipt/__init__.py +192 -0
  75. al_core/resources.py +33 -0
  76. al_core/runtime.py +471 -0
  77. al_core/skills/__init__.py +30 -0
  78. al_core/skills/guard.py +218 -0
@@ -0,0 +1,60 @@
1
+ """A2A wire types: the Agent Card and the message envelope.
2
+
3
+ Both are *untrusted input*. The card is the peer's self-description — the A2A
4
+ analogue of an MCP tool descriptor, and it is attacked the same way: swapped
5
+ behind a trusted name (drift), or stuffed with an injection payload the reading
6
+ model will act on (poisoning). The envelope carries the payload plus the
7
+ session id, which is the smuggling surface.
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ import hashlib
13
+ import json
14
+ from dataclasses import dataclass, field
15
+ from typing import Any, Literal
16
+
17
+
18
+ @dataclass(frozen=True)
19
+ class AgentCard:
20
+ """A peer agent's self-description (name, purpose, advertised skills)."""
21
+
22
+ name: str
23
+ description: str = ""
24
+ skills: tuple[str, ...] = ()
25
+ endpoint: str = ""
26
+
27
+ def canonical(self) -> str:
28
+ return json.dumps(
29
+ {"name": self.name, "description": self.description,
30
+ "skills": list(self.skills), "endpoint": self.endpoint},
31
+ sort_keys=True, separators=(",", ":"), ensure_ascii=False,
32
+ )
33
+
34
+ def digest(self) -> str:
35
+ return "sha256:" + hashlib.sha256(self.canonical().encode("utf-8")).hexdigest()
36
+
37
+ def text(self) -> str:
38
+ """Everything a model would read — the poisoning surface."""
39
+ return "\n".join([self.name, self.description, *self.skills])
40
+
41
+
42
+ @dataclass(frozen=True)
43
+ class AgentEnvelope:
44
+ """One inter-agent message (the Phase-0 interface, unchanged)."""
45
+
46
+ sender: str # spiffe id of the sending agent
47
+ recipient: str # spiffe id of the receiving agent
48
+ payload: str
49
+ session_id: str = "default"
50
+ protocol: Literal["a2a", "custom"] = "a2a"
51
+ agent_card: AgentCard | None = None # pinned + drift-checked, like MCP
52
+ metadata: dict[str, Any] = field(default_factory=dict)
53
+
54
+ @property
55
+ def peers(self) -> tuple[str, str]:
56
+ """The unordered pair this session legitimately belongs to."""
57
+ return tuple(sorted((self.sender, self.recipient))) # type: ignore[return-value]
58
+
59
+
60
+ __all__ = ["AgentCard", "AgentEnvelope"]
@@ -0,0 +1,221 @@
1
+ """A2aMediator — one fail-closed decision point for an inter-agent message.
2
+
3
+ Order matters and mirrors the other gates:
4
+
5
+ 1. **Identity** — sender and recipient must both be known (no identity → deny).
6
+ 2. **Agent-Card poisoning** — the card's own text is run through L2/L3. A card
7
+ that carries "ignore your instructions and…" is hostile *before* any payload
8
+ arrives (ASI07 + ASI01).
9
+ 3. **Agent-Card pinning** — first sight pins the card's digest; a later message
10
+ presenting the *same peer* with a *different* card is a rug-pull, blocked
11
+ until an operator re-approves. Identical to the MCP descriptor defence,
12
+ because it is identical to the MCP attack.
13
+ 4. **Session smuggling** — a session id belongs to the peer pair that opened
14
+ it. A third agent replaying that id to inherit its context is smuggling:
15
+ denied, and the receipt names both the owner and the impostor.
16
+ 5. **Payload** — inter-agent content is untrusted like any web fetch: it runs
17
+ through the content gate (block → withheld, strip → redacted on delivery)
18
+ and **taints the receiving session** (``UNTRUSTED_AGENT``), so a later
19
+ protected tool call in that session faces the tightened HITL gate.
20
+
21
+ Every decision is receipted as ``a2a_message``.
22
+ """
23
+
24
+ from __future__ import annotations
25
+
26
+ import json
27
+ from dataclasses import dataclass
28
+ from pathlib import Path
29
+ from typing import Any, Callable
30
+
31
+ from ..capability.taint import TaintSource, TaintTracker
32
+ from ..detect import ContentGate, ScanContext
33
+ from ..gateway.decision import BlockReason, Decision, finding
34
+ from .envelope import AgentCard, AgentEnvelope
35
+
36
+ Recorder = Callable[..., Any]
37
+
38
+
39
+ @dataclass
40
+ class A2aOutcome:
41
+ """Result of mediating one message. ``payload`` is what the recipient may
42
+ see (redacted when the verdict was strip); None when the message is denied."""
43
+
44
+ decision: Decision
45
+ payload: str | None = None
46
+ redaction: dict[str, int] | None = None
47
+
48
+ @property
49
+ def allowed(self) -> bool:
50
+ return self.decision.allowed
51
+
52
+
53
+ class SessionRegistry:
54
+ """Which peer pair owns a session id (the anti-smuggling ledger).
55
+
56
+ Persisted, because a smuggling attempt that only works after a restart is
57
+ still a smuggling attempt."""
58
+
59
+ def __init__(self, path: Path | None = None) -> None:
60
+ self._path = Path(path) if path else None
61
+ self._owners: dict[str, list[str]] = {}
62
+ if self._path and self._path.exists():
63
+ self._owners = json.loads(self._path.read_text(encoding="utf-8"))
64
+
65
+ def _save(self) -> None:
66
+ if not self._path:
67
+ return
68
+ self._path.parent.mkdir(parents=True, exist_ok=True)
69
+ self._path.write_text(json.dumps(self._owners, indent=2), encoding="utf-8")
70
+
71
+ def owner(self, session_id: str) -> tuple[str, str] | None:
72
+ pair = self._owners.get(session_id)
73
+ return (pair[0], pair[1]) if pair else None
74
+
75
+ def check(self, envelope: AgentEnvelope) -> Decision:
76
+ """First sight binds the session to its peer pair; a different pair on
77
+ the same id is smuggling."""
78
+ owner = self.owner(envelope.session_id)
79
+ if owner is None:
80
+ self._owners[envelope.session_id] = list(envelope.peers)
81
+ self._save()
82
+ return Decision.allow()
83
+ if owner == envelope.peers:
84
+ return Decision.allow()
85
+ return Decision.block(
86
+ BlockReason.A2A_SESSION_SMUGGLED,
87
+ [finding("a2a_session", "a2a.session_smuggling", "critical",
88
+ owasp="ASI07", mitre="T1134")],
89
+ )
90
+
91
+ def forget(self, session_id: str) -> None:
92
+ self._owners.pop(session_id, None)
93
+ self._save()
94
+
95
+
96
+ class CardPinner:
97
+ """Pins peer Agent Cards; drift = rug-pull (ASI07/ASI04)."""
98
+
99
+ def __init__(self, path: Path | None = None) -> None:
100
+ self._path = Path(path) if path else None
101
+ self._pins: dict[str, str] = {}
102
+ if self._path and self._path.exists():
103
+ self._pins = json.loads(self._path.read_text(encoding="utf-8"))
104
+
105
+ def _save(self) -> None:
106
+ if not self._path:
107
+ return
108
+ self._path.parent.mkdir(parents=True, exist_ok=True)
109
+ self._path.write_text(json.dumps(self._pins, indent=2), encoding="utf-8")
110
+
111
+ def check(self, agent: str, card: AgentCard) -> Decision:
112
+ digest = card.digest()
113
+ pinned = self._pins.get(agent)
114
+ if pinned is None:
115
+ self._pins[agent] = digest
116
+ self._save()
117
+ return Decision.allow()
118
+ if pinned == digest:
119
+ return Decision.allow()
120
+ return Decision.block(
121
+ BlockReason.A2A_CARD_DRIFT,
122
+ [finding("a2a_card", "a2a.card_drift", "high", owasp="ASI07",
123
+ mitre="T1195")],
124
+ )
125
+
126
+ def approve(self, agent: str, card: AgentCard) -> None:
127
+ """Operator re-pins a peer after reviewing its new card."""
128
+ self._pins[agent] = card.digest()
129
+ self._save()
130
+
131
+ def is_pinned(self, agent: str) -> bool:
132
+ return agent in self._pins
133
+
134
+
135
+ class A2aMediator:
136
+ def __init__(
137
+ self,
138
+ content_gate: ContentGate,
139
+ *,
140
+ pinner: CardPinner | None = None,
141
+ sessions: SessionRegistry | None = None,
142
+ taint: TaintTracker | None = None,
143
+ recorder: Recorder | None = None,
144
+ known_agent: Callable[[str], bool] | None = None,
145
+ ) -> None:
146
+ self._gate = content_gate
147
+ self._pinner = pinner or CardPinner()
148
+ self._sessions = sessions or SessionRegistry()
149
+ self._taint = taint or TaintTracker()
150
+ self._record = recorder or (lambda **_: None)
151
+ self._known_agent = known_agent or (lambda a: bool(a))
152
+
153
+ @property
154
+ def taint(self) -> TaintTracker:
155
+ return self._taint
156
+
157
+ @property
158
+ def pinner(self) -> CardPinner:
159
+ return self._pinner
160
+
161
+ def mediate(self, envelope: AgentEnvelope) -> A2aOutcome:
162
+ target = f"a2a:{envelope.recipient}"
163
+
164
+ # 1. Identity — an unnamed peer is not a peer.
165
+ if not (self._known_agent(envelope.sender)
166
+ and self._known_agent(envelope.recipient)):
167
+ return self._deny(envelope, target, Decision.block(
168
+ BlockReason.NO_IDENTITY,
169
+ [finding("a2a", "a2a.no_identity", "high", owasp="ASI07")],
170
+ ))
171
+
172
+ # 2 + 3. The peer's card: poisoned text, then drift.
173
+ if envelope.agent_card is not None:
174
+ card = envelope.agent_card
175
+ scan = self._gate.scan_text(card.text(), ScanContext(
176
+ actor=envelope.sender, direction="inbound",
177
+ target=f"a2a:card:{envelope.sender}"))
178
+ if scan.blocked:
179
+ self._taint.mark(envelope.session_id, TaintSource.UNTRUSTED_AGENT)
180
+ return self._deny(envelope, target, Decision.block(
181
+ BlockReason.A2A_CARD_POISONED,
182
+ [finding("a2a_card", "a2a.card_poisoning", "critical",
183
+ owasp="ASI07", mitre="T1204")] + scan.findings,
184
+ ))
185
+ drift = self._pinner.check(envelope.sender, card)
186
+ if not drift.allowed:
187
+ return self._deny(envelope, target, drift)
188
+
189
+ # 4. Session smuggling.
190
+ smuggle = self._sessions.check(envelope)
191
+ if not smuggle.allowed:
192
+ return self._deny(envelope, target, smuggle)
193
+
194
+ # 5. Payload — untrusted content, and it taints the session either way.
195
+ result = self._gate.scan_text(envelope.payload, ScanContext(
196
+ actor=envelope.sender, direction="inbound", target=target))
197
+ self._taint.mark(envelope.session_id, TaintSource.UNTRUSTED_AGENT)
198
+ if result.blocked:
199
+ return self._deny(envelope, target, Decision.block(
200
+ BlockReason.A2A_MESSAGE_BLOCKED,
201
+ [finding("a2a", "a2a.payload_blocked", "high", owasp="ASI07")]
202
+ + result.findings,
203
+ ))
204
+
205
+ self._record(actor=envelope.sender, action="a2a_message", target=target,
206
+ verdict=result.verdict, findings=result.findings,
207
+ redaction=result.redaction or None,
208
+ session=envelope.session_id)
209
+ return A2aOutcome(decision=Decision.allow(), payload=result.text,
210
+ redaction=result.redaction or None)
211
+
212
+ def _deny(self, envelope: AgentEnvelope, target: str,
213
+ decision: Decision) -> A2aOutcome:
214
+ self._record(actor=envelope.sender or "anonymous", action="a2a_message",
215
+ target=target, verdict="block",
216
+ block_reason=decision.block_reason, findings=decision.findings,
217
+ session=envelope.session_id)
218
+ return A2aOutcome(decision=decision)
219
+
220
+
221
+ __all__ = ["A2aMediator", "A2aOutcome", "CardPinner", "SessionRegistry"]