Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/fork-ci-tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ fork-kit/schedule-kick/tests/install.test.py unittest
fork-kit/schedule-kick/tests/kick.test.py unittest
fork-kit/schedule-kick/tests/late.test.py unittest
fork-kit/update-policy/tests/baseline.test.py unittest
fork-kit/update-policy/tests/exposure.test.py unittest
fork-kit/update-policy/tests/idle.test.py unittest
fork-kit/update-policy/tests/install.test.py unittest
fork-kit/update-policy/tests/tick.test.py unittest
Expand Down
2 changes: 1 addition & 1 deletion fork-kit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Every kit follows the same pattern:
| [pc-agents](pc-agents/README.md) | Run T3's agents on a Windows PC in a walled WSL2 distro, checked before every start (WSL2) |
| [review](review/README.md) | A review skill for the merge gate: lenses picked by changed paths, the state question, a comment format checked against the gate's parser, a model eval; no installer, used from a checkout |
| [schedule-kick](schedule-kick/README.md) | `schedule-kick`: start scheduled GitHub workflows on time by `workflow_dispatch` when no run exists for the slot; timer every 5 minutes (Linux, systemd) |
| [update-policy](update-policy/README.md) | Restart only when idle at the quiet hour (dev, personal), alert only (live); a daily baseline check that reports drift (Linux, Debian/Ubuntu, systemd) |
| [update-policy](update-policy/README.md) | Restart only when idle at the quiet hour (dev, personal), alert only (live); daily baseline and exposure (KEV, EPSS) checks that report only drift and what needs action (Linux, Debian/Ubuntu, systemd) |

[common](common/README.md) is code the kits share, copied into each kit's version folder: the loader of the one
private machine file (`/etc/fork-kit/machine.json`) where the facts of one machine live, and the installer and
Expand Down
16 changes: 16 additions & 0 deletions fork-kit/common/machine.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,22 @@
"diskPaths": ["/"],
"pendingDays": 3,
"sshUsers": ["root", "example-agent"]
},
"exposure": {
"enabled": true,
"epssMin": 0.1,
"fixWaitingDays": 3,
"staleDays": 3,
"maxFeedMb": 64,
"maxXmlMb": 1024,
"timeoutSeconds": 60,
"ignore": [
{
"cve": "CVE-2021-1789",
"reason": "example: the package is not used here",
"until": "2026-12-31"
}
]
}
},
"desk": {
Expand Down
127 changes: 119 additions & 8 deletions fork-kit/update-policy/README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion fork-kit/update-policy/lib/updatepolicy/baseline.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def policy_drift(host, cfg, s, state):
problem = aptconf.restart_problem(cfg) if isinstance(cfg, dict) else None
if problem:
out.append(problem)
for unit in OWN_UNITS:
for unit in OWN_UNITS + (('update-policy-exposure.timer',) if s['exposure']['enabled'] else ()):
word = enabled(host, unit)
if word != 'enabled':
out.append(f'{unit} is installed but {word}, not enabled: pending restarts are neither made nor '
Expand Down
13 changes: 12 additions & 1 deletion fork-kit/update-policy/lib/updatepolicy/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
update-policy baseline the daily check: prints only drift, alerts with it; exit 0 none, 1 drift
update-policy booted after a boot: says once that a restart this kit made came back (update-policy-boot)
update-policy status the role, the window, a pending restart and what the last ticks saw
update-policy exposure the daily exposure check: KEV, security fixes waiting, ranked by EPSS; exit 0 none, 1 any
(update-policy-exposure.service runs it as an unprivileged user; --cache DIR)
update-policy exposure-alert sends the last exposure report through the alert command (as root, after it)

The facts of the machine (role, quiet hour, time zone, alert command, ...) are in the "update-policy" section of
/etc/fork-kit/machine.json. Run it as root: it reads every user's cgroups, containers and sockets.
"""
import argparse, datetime, json, os, sys

from updatepolicy import baseline, idle, settings, tick, window
from updatepolicy import baseline, exposure, idle, settings, tick, window

LEVELS = {'err': 3, 'warning': 4, 'notice': 5, 'info': 6}
EXIT_IDLE, EXIT_BUSY = 0, 75
Expand Down Expand Up @@ -73,6 +76,10 @@ def main(argv, host=None, read_settings=None):
sub.add_parser('baseline')
sub.add_parser('booted')
sub.add_parser('status')
e = sub.add_parser('exposure')
e.add_argument('--cache', default=exposure.CACHE)
e2 = sub.add_parser('exposure-alert')
e2.add_argument('--cache', default=exposure.CACHE)
d = sub.add_parser('docker-ps')
d.add_argument('socket')
a = ap.parse_args(argv)
Expand All @@ -85,6 +92,10 @@ def main(argv, host=None, read_settings=None):
return 1
print(json.dumps(names))
return 0
if a.cmd == 'exposure':
return exposure.run(host, read_settings, a.cache)
if a.cmd == 'exposure-alert':
return exposure.alert(m, read_settings, a.cache)
if a.cmd == 'tick':
return tick.tick(m, read_settings, lambda s: idle.look(host, s))
if a.cmd == 'booted':
Expand Down
60 changes: 60 additions & 0 deletions fork-kit/update-policy/lib/updatepolicy/debver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
"""Debian package versions compared the way dpkg compares them (deb-version(7)): [epoch:]upstream[-revision], with
`~` sorting before everything, even the end of the string. Pure; no dpkg needed."""
import re

VERSION_RE = re.compile(r'^(?:([0-9]+):)?([A-Za-z0-9.+~:-]+?)(?:-([A-Za-z0-9.+~]+))?$')


def _order(c):
if c == '~':
return -1
if c.isdigit():
return 0
if c.isalpha():
return ord(c)
return ord(c) + 256


def _part(a, b):
"""dpkg's verrevcmp for one upstream or revision part."""
i = j = 0
while i < len(a) or j < len(b):
first = 0
while (i < len(a) and not a[i].isdigit()) or (j < len(b) and not b[j].isdigit()):
ac = _order(a[i]) if i < len(a) else 0
bc = _order(b[j]) if j < len(b) else 0
if ac != bc:
return ac - bc
i, j = i + 1, j + 1
while i < len(a) and a[i] == '0':
i += 1
while j < len(b) and b[j] == '0':
j += 1
while i < len(a) and a[i].isdigit() and j < len(b) and b[j].isdigit():
if not first:
first = ord(a[i]) - ord(b[j])
i, j = i + 1, j + 1
if i < len(a) and a[i].isdigit():
return 1
if j < len(b) and b[j].isdigit():
return -1
if first:
return first
return 0


def split(version):
"""(epoch, upstream, revision). Raises ValueError for a string that is no Debian version."""
m = VERSION_RE.match(version.strip())
if not m:
raise ValueError(f'not a Debian version: {version!r}')
return int(m.group(1) or 0), m.group(2), m.group(3) or ''


def compare(a, b):
"""<0, 0 or >0 as version a sorts before, with or after version b."""
ea, ua, ra = split(a)
eb, ub, rb = split(b)
if ea != eb:
return ea - eb
return _part(ua, ub) or _part(ra, rb)
Loading
Loading