config
config
¶
Shield configuration types, enums, and mode protocol.
Defines the vocabulary shared across the entire codebase: what a shield configuration looks like, what modes and states exist, and what contract a mode backend must satisfy.
DnsTier
¶
Bases: Enum
DNS resolution tier for egress control.
Determines how domain-based allowlists are enforced:
Per-container dnsmasq with --nftset auto-populates nft
allow sets on every DNS query. Handles IP rotation.
DIG: Static resolution at pre-start via dig (current fallback).
GETENT: Single-IP resolution via getent hosts (minimal fallback).
ShieldMode
¶
Bases: Enum
Operating mode for the shield firewall.
Currently only HOOK is supported. Future modes (e.g. bridge) will add members here.
ShieldState
¶
Bases: Enum
Per-container shield state, derived from the live nft ruleset.
UP: Normal enforcing mode (deny-all). DOWN: Bypass mode with private-range protection (RFC 1918 + RFC 4193). DOWN_ALL: Bypass mode without private-range protection. INACTIVE: No ruleset found (container stopped or unshielded). ERROR: Ruleset present but unrecognised.
ShieldConfig(state_dir, mode=ShieldMode.HOOK, default_profiles=('dev-standard',), loopback_ports=(), audit_enabled=True, profiles_dir=None, interactive=False)
dataclass
¶
Per-container shield configuration.
The library is a pure function of its inputs. Given a
ShieldConfig with state_dir, it writes to that directory
and nowhere else. No env-var reading, no config-file parsing.
AuditFileConfig
¶
Bases: BaseModel
Audit section of config.yml.
ShieldFileConfig
¶
Bases: BaseModel
Validated schema for config.yml.
Loaded by the CLI at startup. extra="forbid" rejects unknown
keys so typos (e.g. mod: hook) produce a clear error instead
of being silently ignored.
ShieldModeBackend
¶
Bases: Protocol
Strategy protocol for shield mode implementations.
Each concrete backend (e.g. HookMode) provides the full
lifecycle: per-container firewalling, live allow/deny, bypass,
and preview.
detect_dns_tier(has, dnsmasq_nftset_ok=lambda: True)
¶
Detect the best available DNS resolution tier.
Probes for executables in priority order: dnsmasq (with nftset support) > dig > getent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
has
|
Callable[[str], bool]
|
Returns True if the named executable exists on PATH. |
required |
dnsmasq_nftset_ok
|
Callable[[], bool]
|
Returns True if installed dnsmasq supports
|
lambda: True
|