harvest
harvest
¶
What a task reached for, read back out of its audit log.
A deny-by-default box is only workable if the operator can find out what the
policy refused and decide whether it should have. That record already exists:
the NFLOG reader writes one line per refusal, one per accept through the timed
allow-all window, and one per connection the DOWN postures accepted only
because the shield was down, into the container's audit.jsonl. Harvest is
a reader over that file, not a second mechanism — nothing new is collected,
and nothing here writes policy.
Grouping is by target, the way a promotion decision is made: a domain when the reader recovered one from the DNS cache, the address otherwise. Counts come from the log, and the reader records at most one line per target per 30 s, so a count is a floor on how often the workload tried, never a connection count.
Every entry also says which tier stands between the task and the target, and
what could change that — classified by destination, not by the log line's
action alone. The action cannot carry it: one prefix covers the hard-deny
floor and the private ranges alike, a DISENGAGED shield logs a vault host, IMDS
and a LAN address all as down, and quarantine logs its drops as
blocked. The destination, checked against the bundle's own tiers, can.
HARVESTED_ACTIONS = ('blocked', 'bypass', 'down', 'security_deny', 'private_range')
module-attribute
¶
TIER_ALLOWLIST = 't40'
module-attribute
¶
No refusing tier claims the target: the allowlist simply does not name it.
TIER_OPERATOR_DENY = 't20_operator'
module-attribute
¶
The operator's own runtime deny (a - line in policy/live) refuses it.
TIER_SECURITY = 't20_security'
module-attribute
¶
The security tier refuses it — by name, by a domain above it, or by address.
TIER_PRIVATE = 't20_private'
module-attribute
¶
A private range (RFC 1918, RFC 4193 ULA) refuses it.
TIER_HARD_DENY = 't00'
module-attribute
¶
The hard-deny floor (link-local, IMDS) refuses it — above every override.
REMEDY_TASK = 'task'
module-attribute
¶
Allow it for this task — live, or from its next start when it is stopped.
REMEDY_PROJECT = 'project'
module-attribute
¶
Allow it for every task of the project (shield.allow).
REMEDY_SET = 'set'
module-attribute
¶
Enable a curated egress set that names it, or add it to a user set.
REMEDY_OVERRIDE = 'override'
module-attribute
¶
A break-glass shield.override, with a reason and an expiry.
REMEDY_HOST_PORT = 'host_port'
module-attribute
¶
A +localhost:PORT grant — the target is the host's own loopback, mapped.
HarvestEntry(action, target, count, first_seen, last_seen, ports, addresses, tier=TIER_ALLOWLIST, remedies=(REMEDY_TASK, REMEDY_PROJECT, REMEDY_SET))
dataclass
¶
One destination a task reached for, what the shield did, and what could change it.
action
instance-attribute
¶
What the shield did, as the reader recorded it: blocked — refused by
the terminal rule; bypass — let through by the timed allow-all window;
down — accepted only because the shield was down; security_deny —
refused by the t20 deny set; private_range — refused by a range floor.
target
instance-attribute
¶
The domain the reader recovered, or the address when it had none.
This is what a promotion would name, which is why it is the grouping key: an allowlist entry for a rotating CDN is worth nothing as an IP.
count
instance-attribute
¶
Audit lines seen for this target.
A floor on attempts, not a connection count: the reader records one line per target per 30 s, so a tight retry loop and a single request can both land as one.
first_seen
instance-attribute
¶
last_seen
instance-attribute
¶
ports
instance-attribute
¶
Destination ports, ascending — a promotion candidate on 443 and one on 25 deserve different scrutiny.
addresses
instance-attribute
¶
Addresses seen behind target, in first-seen order; empty when the target is itself an address.
tier = TIER_ALLOWLIST
class-attribute
instance-attribute
¶
The tier that stands between the task and the target: t40 when no
refusing tier claims it (the allowlist just does not name it),
t20_operator for the operator's own runtime deny, t20_security for
the security tier (vault-relayed hosts above all), t20_private for a
private range, t00 for the hard-deny floor. Read from the
destination against the container's bundle, so a down line from a
DISENGAGED shield lands in the tier that would refuse it once the shield
is back up. Defaults to the ordinary t40 case.
remedies = (REMEDY_TASK, REMEDY_PROJECT, REMEDY_SET)
class-attribute
instance-attribute
¶
What could let the task reach the target, in preference order: task
/ project (an allow), set (a curated or user set), override
(break-glass, with a reason and an expiry), host_port (a
+localhost:PORT grant for the host's own loopback — pasta's map or
the slirp4netns gateway, both refused in t00, above every override).
Empty for the rest of the hard-deny floor, which nothing reaches.
Defaults to the remedies of the ordinary t40 case.
HarvestReport(entries=(), audit_enabled=True)
dataclass
¶
What harvest found, and whether it could find anything.
An empty harvest means two different things depending on
audit_enabled: with audit on, the task reached for nothing it could
not have; with audit off, the reader recorded nothing to begin with, so
the emptiness says nothing about the task. A caller shows the second as
such rather than as an all-clear.
Iterating the report yields its entries, and its length is theirs, so a caller that only ever listed the entries reads it unchanged.
harvest(state_dir)
¶
Summarise what the container in state_dir reached for.
Entries come in review order: what an operator can promote outright first, then break-glass, then what nothing reaches — and within each tier refusals before window accepts before what the DOWN posture let through, then by how often the target appeared and by name. A missing audit log yields no entries: a task that never tried anything has none. A log that exists but cannot be read is an error, never an empty harvest — the operator decides what to allow from this report, and a false all-clear would mislead that decision. The report says whether audit was on at all, which is the one reason an empty harvest is not an answer.
Raises:
| Type | Description |
|---|---|
RuntimeError
|
The audit log exists but cannot be read; the message names its path. |