ce744a85c4
tracker-policy-pr / check-pr (pull_request) Successful in 11s
test / integration-docker (pull_request) Successful in 17s
test / unit (pull_request) Successful in 49s
lint / lint (push) Failing after 2m49s
test / integration-firecracker (pull_request) Successful in 3m35s
test / coverage (pull_request) Successful in 18s
test / publish-infra (pull_request) Has been skipped
Group the gateway's data-plane modules into three service sub-packages mirroring the host-side trio (bot_bottle.egress / .supervisor / .git_gate): gateway/egress/ addon_core, addon, dlp_config, dlp_detectors gateway/supervisor/ server (was supervise_server) gateway/git_gate/ render, http_backend Prefix-stripped filenames now that the package namespaces them; each sub-package has a thin docstring __init__ (no eager imports, cheap leaf loads). The two cross-cutting files stay at the gateway root: policy_resolver (shared per-client lookup) and gateway_init, renamed to bootstrap now that gateway/ already namespaces it. Updated all importers (bot_bottle + tests), the in-VM/container `-m` launch strings, the Dockerfile.gateway addon shim + ENTRYPOINT, and the five gateway entries in scripts/critical-modules.txt. Full unit suite green (2243). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
91 lines
2.7 KiB
Python
91 lines
2.7 KiB
Python
"""Per-agent egress (PRD 0017).
|
|
|
|
The egress gateway is a TLS-terminating forward proxy that allow-lists a
|
|
bottle's outbound HTTP(S), scans payloads for secret exfil, and injects
|
|
per-route upstream credentials the agent never sees.
|
|
|
|
Layout:
|
|
|
|
* `service` — the `Egress` host-side service (`prepare` the launch plan,
|
|
`resolve_token_values`, `agent_env_entries`) + the route-building /
|
|
rendering functions.
|
|
* `plan` — `EgressPlan` / `EgressRoute`, the launch DTOs (in the backend
|
|
contract).
|
|
|
|
The runtime enforcement (the mitmproxy addon) lives in
|
|
`bot_bottle.gateway.egress.addon*`. Public names are re-exported lazily via
|
|
`__getattr__`, so `from bot_bottle.egress import …` keeps working and importing
|
|
`egress.plan` (the contract's dependency) stays light.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import TYPE_CHECKING, Any
|
|
|
|
if TYPE_CHECKING:
|
|
from .plan import EgressPlan, EgressRoute
|
|
from .service import (
|
|
CLAUDE_HOST_CREDENTIAL_TOKEN_REF,
|
|
CODEX_HOST_CREDENTIAL_TOKEN_REF,
|
|
EGRESS_HOSTNAME,
|
|
EGRESS_ROUTES_FILENAME,
|
|
EGRESS_ROUTES_IN_CONTAINER,
|
|
Egress,
|
|
egress_agent_env_entries,
|
|
egress_gateway_env_entries,
|
|
egress_manifest_routes,
|
|
egress_render_routes,
|
|
egress_resolve_token_values,
|
|
egress_routes_for_bottle,
|
|
egress_token_env_map,
|
|
)
|
|
|
|
|
|
_LAZY: dict[str, str] = {
|
|
"EgressPlan": ".plan",
|
|
"EgressRoute": ".plan",
|
|
"Egress": ".service",
|
|
"CLAUDE_HOST_CREDENTIAL_TOKEN_REF": ".service",
|
|
"CODEX_HOST_CREDENTIAL_TOKEN_REF": ".service",
|
|
"EGRESS_HOSTNAME": ".service",
|
|
"EGRESS_ROUTES_FILENAME": ".service",
|
|
"EGRESS_ROUTES_IN_CONTAINER": ".service",
|
|
"egress_agent_env_entries": ".service",
|
|
"egress_gateway_env_entries": ".service",
|
|
"egress_manifest_routes": ".service",
|
|
"egress_render_routes": ".service",
|
|
"egress_resolve_token_values": ".service",
|
|
"egress_routes_for_bottle": ".service",
|
|
"egress_token_env_map": ".service",
|
|
}
|
|
|
|
|
|
def __getattr__(name: str) -> Any:
|
|
src = _LAZY.get(name)
|
|
if src is None:
|
|
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
from importlib import import_module
|
|
|
|
value = getattr(import_module(src, __name__), name)
|
|
globals()[name] = value
|
|
return value
|
|
|
|
|
|
__all__ = [
|
|
"CLAUDE_HOST_CREDENTIAL_TOKEN_REF",
|
|
"CODEX_HOST_CREDENTIAL_TOKEN_REF",
|
|
"EGRESS_HOSTNAME",
|
|
"EGRESS_ROUTES_FILENAME",
|
|
"EGRESS_ROUTES_IN_CONTAINER",
|
|
"Egress",
|
|
"EgressPlan",
|
|
"EgressRoute",
|
|
"egress_manifest_routes",
|
|
"egress_render_routes",
|
|
"egress_resolve_token_values",
|
|
"egress_routes_for_bottle",
|
|
"egress_agent_env_entries",
|
|
"egress_gateway_env_entries",
|
|
"egress_token_env_map",
|
|
]
|