the horizon says what stops being enforced soon, and what answers afterwards
GET /admin-api/expiring?within=<minutes> (1..1440, 30 by default) lists the dated
entries that stop being enforced inside the window, nearest first, and each
address-shaped row carries thenAnswers: the real DecisionEngine.Decide over a
snapshot with only that entry removed. An exemption about to lapse therefore says
which ban is waiting underneath it ("block_operator by 203.0.113.16/28"), and a
block that stands alone says the source goes free. A path rule and a path budget
have no single answer: thenAnswers is null and whyNoAnswer points at
/admin-api/decide?ip=&path= instead of the surface guessing one. Entries that
never expire are not listed; alreadyExpired counts the dated rows whose moment
already passed, which is what separates "nothing expires soon" from "there are no
dated entries". The listing reads the database, the read-only token can ask it,
and six asks write nothing.
Rulings:
- the probe address for a CIDR is its network address, which is inside the group
it describes; a pattern is not probed at all.
- the window is capped at a day because that is the longest thing an operator
plans for; out of bounds is a 400 naming 1..1440.
- the console prints the window it asked for as the first line of the answer and
empties the box before the call, so neither a scene nor an operator on a slow
link can read the previous answer as the new one.
Two product defects fell out of the gates on the way:
- the alert push worker was registered as a hosted service above the schema step,
and hosted services start in registration order: on a cold start its first
queue sweep read alert_push_queue out of a database this process had not
created, and "SQLite Error 1: no such table" became alertWebhookLastError -
the state page blaming the webhook endpoint for the edge's own startup order.
The notifier is now registered below the warmer and the order is asserted.
- a listing the edge could not answer was drawn as an empty one: with two of the
page's fourteen calls answering an error, the observation line printed "0
sources the edge has recorded" and the streak line "0 of 0 standing streaks
listed" over a map holding twelve sources. A count read off a failed answer is
0, and 0 says there is nothing to see. Every count-bearing note and its table
now say NOT READ with the error beside them.
The gate's own traps, caught and fixed: the budget scene cleared the engine ban
its probes caused after the probe that ban was failing, and its reopen retry loop
banned itself three refusals deep; the alerts assertion read a row written off the
response before the next refresh drew it.
gates: build 0 warnings / 0 errors, unit 377/377, integration 375/375 in 35 s,
console 142 assertions 0 failed, smoke passed 217 failed 0, compose 324 passed
0 failed against the built image at 262 MB, 0 containers left behind.
Refs OPEN-72.
This commit is contained in:
@@ -1825,6 +1825,52 @@ check 'the scene cleans itself' 0 \
|
||||
"$EDGE/admin-api/policy" >/dev/null; \
|
||||
admin "$EDGE/admin-api/rate-rules" | python3 -c 'import sys,json;print(len(json.load(sys.stdin)))')"
|
||||
|
||||
# What stops being enforced soon (OPEN-72), on the shipped image: the horizon is
|
||||
# read from the database, so it has to answer the same way through the container
|
||||
# as through the process, and the prediction it makes has to hold on the wire.
|
||||
echo '- the shipped edge says what stops answering soon'
|
||||
HOR_IP=198.51.100.171
|
||||
HOR_NET=198.51.100.176/29 # .176 - .183
|
||||
HOR_INSIDE=198.51.100.179
|
||||
check 'the shipped edge takes a block, a range and an allow that all expire today' '204 204 204' \
|
||||
"$(code -X POST -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" -H 'Content-Type: application/json' \
|
||||
--data-binary '{"ip":"'"$HOR_IP"'","reason":"horizon block","expiresInMinutes":45}' "$EDGE/admin-api/blocks") \
|
||||
$(code -X POST -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" -H 'Content-Type: application/json' \
|
||||
--data-binary '{"ip":"'"$HOR_NET"'","reason":"horizon range","expiresInMinutes":20}' "$EDGE/admin-api/blocks") \
|
||||
$(code -X POST -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" -H 'Content-Type: application/json' \
|
||||
--data-binary '{"match":"'"$HOR_INSIDE"'","note":"horizon allow","expiresInMinutes":60}' "$EDGE/admin-api/allow")"
|
||||
check 'the shipped horizon lists them nearest first and says the range refuses once the allow ages out' yes \
|
||||
"$(admin "$EDGE/admin-api/expiring?within=90" | python3 -c '
|
||||
import sys,json
|
||||
d=json.load(sys.stdin)
|
||||
rows=[r for r in d["expiring"] if r["match"] in ("'"$HOR_IP"'","'"$HOR_NET"'","'"$HOR_INSIDE"'")]
|
||||
order=[r["match"] for r in rows]
|
||||
a=[r for r in rows if r["kind"]=="allow"]
|
||||
t=a[0]["thenAnswers"] if a else None
|
||||
print("yes" if d["scope"]=="database" and order==["'"$HOR_NET"'","'"$HOR_IP"'","'"$HOR_INSIDE"'"] and t and t["verdict"]=="block_operator" and t["by"]=="'"$HOR_NET"'" else "no")')"
|
||||
check 'the shipped horizon says a block with nothing underneath leaves the source free' yes \
|
||||
"$(admin "$EDGE/admin-api/expiring?within=90" | python3 -c '
|
||||
import sys,json
|
||||
rows=[r for r in json.load(sys.stdin)["expiring"] if r["kind"]=="block" and r["match"]=="'"$HOR_IP"'"]
|
||||
t=rows[0]["thenAnswers"] if rows else None
|
||||
print("yes" if t and t["verdict"]=="pass" and not t["wouldBeRefused"] else "no")')"
|
||||
check 'the shipped horizon refuses a window of zero minutes or of more than a day' '400 400' \
|
||||
"$(code -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" "$EDGE/admin-api/expiring?within=0") \
|
||||
$(code -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" "$EDGE/admin-api/expiring?within=1441")"
|
||||
check 'the shipped read-only token reads the horizon, no token does not' '200 401' \
|
||||
"$(code -H "X-Admin-Token: $OPENWAF_READ_ONLY_TOKEN" "$EDGE/admin-api/expiring?within=90") \
|
||||
$(code "$EDGE/admin-api/expiring?within=90")"
|
||||
HOR_ALLOW_ID="$(admin "$EDGE/admin-api/allow?live=false" | python3 -c 'import sys,json;print([a["id"] for a in json.load(sys.stdin) if a["match"]=="'"$HOR_INSIDE"'"][0])')"
|
||||
check 'the shipped prediction holds: with the allow gone the wire refuses that address' block_operator \
|
||||
"$(admin -X DELETE "$EDGE/admin-api/allow/$HOR_ALLOW_ID" >/dev/null; \
|
||||
admin "$EDGE/admin-api/decide?ip=$HOR_INSIDE&path=/" \
|
||||
| python3 -c 'import sys,json;print(json.load(sys.stdin)["verdict"])')"
|
||||
check 'the scene cleans itself' 0 \
|
||||
"$(admin -X DELETE "$EDGE/admin-api/blocks?key=$HOR_IP" >/dev/null; \
|
||||
admin -X DELETE "$EDGE/admin-api/blocks?key=${HOR_NET//\//%2F}" >/dev/null; \
|
||||
admin "$EDGE/admin-api/blocks?live=false" \
|
||||
| python3 -c 'import sys,json;print(len([r for r in json.load(sys.stdin) if r["sourceKey"] in ("'"$HOR_IP"'","'"$HOR_NET"'")]))')"
|
||||
|
||||
echo
|
||||
printf 'compose smoke: %d passed, %d failed\n' "$PASS" "$FAIL"
|
||||
[ "$FAIL" -eq 0 ]
|
||||
|
||||
+193
-5
@@ -166,7 +166,17 @@ const rgb = (s) => s.match(/\d+/g).slice(0, 3).map(Number);
|
||||
check('a database inside the 90-day alarm is not marked stale',
|
||||
!warnPills.some((x) => /geo/.test(x)), JSON.stringify(warnPills));
|
||||
|
||||
const alertRows = await cells('#alerts tbody tr');
|
||||
// The alert row is written after the response that raised it — the seed has its
|
||||
// own retry loop for exactly that — and the page refreshes on an interval, so
|
||||
// one read of the table can land before the row reached storage and before the
|
||||
// next refresh drew it. Bounded retry: the assertion is about the page showing
|
||||
// the streak this run wrote, not about which refresh was in flight.
|
||||
let alertRows = [];
|
||||
for (let i = 0; i < 20; i++) {
|
||||
alertRows = await cells('#alerts tbody tr');
|
||||
if (alertRows.some((r) => r[0] === 'server_error_streak' && r[1] === SEED_ERROR)) break;
|
||||
await new Promise((r) => setTimeout(r, 500));
|
||||
}
|
||||
const errAlerts = alertRows.filter((r) => r[0] === 'server_error_streak' && r[1] === SEED_ERROR);
|
||||
check('the alerts table lists the server-error streak this run wrote',
|
||||
errAlerts.length >= 1 && errAlerts.some((r) => Number(r[2]) >= 3),
|
||||
@@ -588,12 +598,15 @@ const rgb = (s) => s.match(/\d+/g).slice(0, 3).map(Number);
|
||||
const letOut = await page.textContent('#status');
|
||||
check('one button lets one source out and says it is a counter reset, not an exemption',
|
||||
/window dropped for/.test(letOut) && /not an exemption/.test(letOut), letOut);
|
||||
// The probes this scene drew are refusals (404, 404, 429), so the streak pillar
|
||||
// has banned this address by now — and an engine ban outlives every retry loop
|
||||
// in this file. Both probes below are about the budget, so the one ban on this
|
||||
// one address is cleared by name first; clearing every engine ban would take the
|
||||
// netblock offers down with it, and a later scene reads those.
|
||||
await adminDelete(`/admin-api/blocks?source=engine&key=${encodeURIComponent(PATH_BUDGET_IP)}`);
|
||||
check('the source that was let out reaches the upstream again on that path',
|
||||
(await askPath(PATH_BUDGET_IP, PATH_BUDGET_PATH)) === 404,
|
||||
`probe from ${PATH_BUDGET_IP} on ${PATH_BUDGET_PATH} after being let out`);
|
||||
// Same reason as above: the probes this scene drew are refusals, and the streak
|
||||
// pillar has now banned this address too. The check below is about the budget
|
||||
// row, so the engine's own ban on this one address is cleared by name first.
|
||||
await adminDelete(`/admin-api/blocks?source=engine&key=${encodeURIComponent(PATH_BUDGET_IP)}`);
|
||||
|
||||
await page.evaluate((pat) => {
|
||||
@@ -605,7 +618,13 @@ const rgb = (s) => s.match(/\d+/g).slice(0, 3).map(Number);
|
||||
.some((tr) => tr.children[0].textContent === pat), `${PATH_BUDGET_PATH}*`, { timeout: 15000 }).catch(() => {});
|
||||
let reopened = await askPath(PATH_BUDGET_IP, PATH_BUDGET_PATH);
|
||||
for (let i = 0; i < 10 && reopened !== 404; i++) {
|
||||
await new Promise((r) => setTimeout(r, 1000)); reopened = await askPath(PATH_BUDGET_IP, PATH_BUDGET_PATH);
|
||||
await new Promise((r) => setTimeout(r, 1000));
|
||||
// Every probe in this loop is a refusal — 429 until the removal reaches the
|
||||
// snapshot, then the upstream's 404 — and three refusals in five minutes is
|
||||
// what the streak pillar bans on. The assertion is about the budget row, so
|
||||
// the ban this loop causes on this one address is cleared each time round.
|
||||
await adminDelete(`/admin-api/blocks?source=engine&key=${encodeURIComponent(PATH_BUDGET_IP)}`);
|
||||
reopened = await askPath(PATH_BUDGET_IP, PATH_BUDGET_PATH);
|
||||
}
|
||||
check('one remove button reopens the path for a source that was paused a moment ago',
|
||||
reopened === 404, `probe from ${PATH_BUDGET_IP} answered ${reopened}`);
|
||||
@@ -894,6 +913,12 @@ const rgb = (s) => s.match(/\d+/g).slice(0, 3).map(Number);
|
||||
() => /^off/.test(document.getElementById('ratenote').textContent),
|
||||
null, { timeout: 15000 }).catch(() => {});
|
||||
await clearEngineBan(RATE_IP);
|
||||
// The page refreshes on an interval, and a refresh that started before this
|
||||
// PUT lands answers with the mode that was true when it started. The wait above
|
||||
// can therefore be satisfied and then overwritten by the older answer, so the
|
||||
// line is waited for again after the ban clear rather than read once.
|
||||
await page.waitForFunction(() => /^off/.test(document.getElementById('ratenote').textContent),
|
||||
null, { timeout: 15000 }).catch(() => {});
|
||||
const backOff = await rateNoteOf();
|
||||
check('the budget can be switched off from the page',
|
||||
/^off/.test(backOff), JSON.stringify(backOff));
|
||||
@@ -1374,6 +1399,169 @@ const rgb = (s) => s.match(/\d+/g).slice(0, 3).map(Number);
|
||||
&& /\d+ of \d+ standing streaks listed/.test(clearedStreakNote),
|
||||
`${JSON.stringify(clearedObsNote)} | ${JSON.stringify(clearedStreakNote)}`);
|
||||
}
|
||||
// A listing the edge could not answer is not a listing with nothing in it.
|
||||
// Measured on a run where two of the page's fourteen calls lost the database
|
||||
// for a moment: the observation line printed "0 sources the edge has recorded"
|
||||
// and the streak line "0 of 0 standing streaks listed" over a map holding
|
||||
// twelve sources. The status line said the call failed; the tables an operator
|
||||
// actually reads said there was nothing to see.
|
||||
{
|
||||
const brokenRead = async (path) => page.route(path, (route) => route.fulfill({
|
||||
status: 503,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({ error: 'gate: this read did not run' })
|
||||
}));
|
||||
await brokenRead('**/admin-api/observations*');
|
||||
await brokenRead('**/admin-api/streaks*');
|
||||
await page.reload({ waitUntil: 'domcontentloaded' });
|
||||
await page.fill('#token', TOKEN);
|
||||
await page.click('#save');
|
||||
await page.waitForFunction(() => /NOT READ/.test(document.getElementById('obsnote').textContent),
|
||||
null, { timeout: 15000 }).catch(() => {});
|
||||
const brokenObsNote = (await page.textContent('#obsnote')).replace(/\s+/g, ' ').trim();
|
||||
const brokenStreakNote = (await page.textContent('#streaknote')).replace(/\s+/g, ' ').trim();
|
||||
const brokenRows = await page.$$eval('#obs tbody tr, #streaks tbody tr',
|
||||
(trs) => trs.map((tr) => (tr.children[0].textContent || '').trim()));
|
||||
check('a listing the edge could not answer says so instead of counting zero',
|
||||
brokenObsNote === 'NOT READ \u2014 gate: this read did not run. This is not an empty table.'
|
||||
&& brokenStreakNote === 'NOT READ \u2014 gate: this read did not run. This is not an empty table.',
|
||||
`${JSON.stringify(brokenObsNote)} | ${JSON.stringify(brokenStreakNote)}`);
|
||||
check('and neither table is drawn as an empty one',
|
||||
brokenRows.length === 2 && brokenRows.every((v) => v.startsWith('NOT READ')),
|
||||
JSON.stringify(brokenRows));
|
||||
await page.unroute('**/admin-api/observations*');
|
||||
await page.unroute('**/admin-api/streaks*');
|
||||
await page.waitForFunction(() => /sources the edge has recorded|newest \d+ of/.test(
|
||||
document.getElementById('obsnote').textContent), null, { timeout: 15000 }).catch(() => {});
|
||||
const healedObsNote = (await page.textContent('#obsnote')).replace(/\s+/g, ' ').trim();
|
||||
const healedStreakNote = (await page.textContent('#streaknote')).replace(/\s+/g, ' ').trim();
|
||||
check('and the count comes back when the read works again',
|
||||
!/NOT READ/.test(healedObsNote) && !/NOT READ/.test(healedStreakNote)
|
||||
&& /(sources the edge has recorded|recorded sources)/.test(healedObsNote)
|
||||
&& /standing streaks listed/.test(healedStreakNote),
|
||||
`${JSON.stringify(healedObsNote)} | ${JSON.stringify(healedStreakNote)}`);
|
||||
}
|
||||
|
||||
// The enforcement horizon (OPEN-72). A dated entry that is about to age out is
|
||||
// only interesting for what answers afterwards, so the row carries the real
|
||||
// decision the engine would take with that one entry removed. Seeded through
|
||||
// the page's own forms: a range expiring in 20 min, an allow inside it
|
||||
// expiring in 45, and a path rule expiring in 30.
|
||||
{
|
||||
const HORIZON_NET = '192.0.2.232/29'; // .232 - .239
|
||||
const HORIZON_ALLOW = '192.0.2.235'; // inside that range
|
||||
const HORIZON_RULE = '/horizon-gate*';
|
||||
|
||||
await page.fill('#blockIp', HORIZON_NET);
|
||||
await page.fill('#blockReason', 'console gate: horizon range');
|
||||
await page.fill('#blockTtl', '20');
|
||||
await page.click('#addBlock');
|
||||
await page.waitForFunction((k) => [...document.querySelectorAll('#blocks tbody button[data-act="delblock"]')]
|
||||
.some((b) => b.dataset.k === k), HORIZON_NET, { timeout: 15000 }).catch(() => {});
|
||||
|
||||
await page.fill('#allowMatch', HORIZON_ALLOW);
|
||||
await page.fill('#allowNote', 'console gate: horizon allow');
|
||||
await page.fill('#allowTtl', '45');
|
||||
await page.click('#addAllow');
|
||||
await page.waitForFunction((m) => [...document.querySelectorAll('#allow tbody tr')]
|
||||
.some((tr) => (tr.children[0].textContent || '').trim() === m), HORIZON_ALLOW,
|
||||
{ timeout: 15000 }).catch(() => {});
|
||||
|
||||
await page.fill('#rulePattern', HORIZON_RULE);
|
||||
await page.fill('#ruleNote', 'console gate: horizon rule');
|
||||
await page.fill('#ruleTtl', '30');
|
||||
await page.click('#addRule');
|
||||
await page.waitForFunction((x) => [...document.querySelectorAll('#pathrules tbody tr')]
|
||||
.some((tr) => (tr.children[0].textContent || '').trim() === x), HORIZON_RULE,
|
||||
{ timeout: 15000 }).catch(() => {});
|
||||
|
||||
const horizonRows = () => page.$$eval('#horizonanswer div', (ds) => ds.map((d) => d.textContent));
|
||||
const askHorizon = async (minutes) => {
|
||||
// The box is emptied first and the first line names the window that was
|
||||
// asked for, so a wait for "an answer is in the box" can never be satisfied
|
||||
// by the answer to the previous ask.
|
||||
await page.evaluate(() => { document.getElementById('horizonanswer').textContent = ''; });
|
||||
await page.fill('#horizonWithin', String(minutes));
|
||||
await page.click('#askHorizon');
|
||||
await page.waitForFunction((asked) => (document.getElementById('horizonanswer').textContent || '')
|
||||
.indexOf('asked: within ' + asked + ' minutes') === 0, String(minutes),
|
||||
{ timeout: 15000 }).catch(() => {});
|
||||
return horizonRows();
|
||||
};
|
||||
|
||||
const horizonBefore = await page.$$eval('#blocks tbody button[data-act="delblock"]',
|
||||
(bs) => bs.map((b) => b.dataset.k).sort());
|
||||
const wide = await askHorizon(60);
|
||||
const netLine = wide.find((l) => l.includes(HORIZON_NET));
|
||||
const allowLine = wide.find((l) => l.includes(HORIZON_ALLOW));
|
||||
const ruleLine = wide.find((l) => l.includes(HORIZON_RULE));
|
||||
|
||||
check('the horizon lists the range, the allow inside it and the path rule',
|
||||
!!netLine && !!allowLine && !!ruleLine, JSON.stringify(wide));
|
||||
check('the allow says what refuses its address once it ages out',
|
||||
!!allowLine && /then: block_operator by 192\.0\.2\.232\/29/.test(allowLine),
|
||||
JSON.stringify(allowLine));
|
||||
check('the range says nothing else refuses once it ages out',
|
||||
!!netLine && /then: pass by nothing/.test(netLine), JSON.stringify(netLine));
|
||||
check('a path rule says why it has no single answer and points at the dry run',
|
||||
!!ruleLine && /a path rule and a path budget describe a set of paths/.test(ruleLine)
|
||||
&& ruleLine.includes('/admin-api/decide?ip=&path='), JSON.stringify(ruleLine));
|
||||
check('the horizon is ordered by what ages out first',
|
||||
!!netLine && !!ruleLine && !!allowLine
|
||||
&& wide.indexOf(netLine) < wide.indexOf(ruleLine)
|
||||
&& wide.indexOf(ruleLine) < wide.indexOf(allowLine),
|
||||
JSON.stringify(wide.filter((l) => l.includes(' min left'))));
|
||||
check('the header names the window asked for and the counts of what is already past',
|
||||
/^asked: within 60 minutes of 2\d{3}-/.test(wide[0] || '')
|
||||
&& /^expiring: \d+ - already past: block \d+, range \d+, engine ban \d+, allow \d+, path rule \d+, path budget \d+$/.test(wide[1] || ''),
|
||||
JSON.stringify(wide.slice(0, 2)));
|
||||
|
||||
const narrow = await askHorizon(10);
|
||||
check('a window shorter than every TTL hides all three',
|
||||
!narrow.some((l) => l.includes(HORIZON_NET) || l.includes(HORIZON_ALLOW)
|
||||
|| l.includes(HORIZON_RULE)),
|
||||
JSON.stringify(narrow));
|
||||
|
||||
await page.fill('#horizonWithin', '0');
|
||||
await page.click('#askHorizon');
|
||||
await page.waitForFunction(() => /whole number of minutes/.test(document.getElementById('status').textContent),
|
||||
null, { timeout: 5000 }).catch(() => {});
|
||||
const horizonStatus = (await page.textContent('#status')).replace(/\s+/g, ' ').trim();
|
||||
const stillNarrow = await horizonRows();
|
||||
check('a window of zero minutes is refused by the page before the request goes out',
|
||||
/whole number of minutes from 1 to 1440/.test(horizonStatus)
|
||||
&& stillNarrow[0] === narrow[0],
|
||||
`${JSON.stringify(horizonStatus)} box=${JSON.stringify(stillNarrow[0])}`);
|
||||
|
||||
const horizonAfter = await page.$$eval('#blocks tbody button[data-act="delblock"]',
|
||||
(bs) => bs.map((b) => b.dataset.k).sort());
|
||||
check('reading the horizon wrote nothing to the operator list',
|
||||
JSON.stringify(horizonAfter) === JSON.stringify(horizonBefore),
|
||||
JSON.stringify(horizonAfter));
|
||||
|
||||
// Tear the seeds down by id, not by cell: the block row prints a range badge
|
||||
// where the key belongs, and the allow and rule rows key their remove button
|
||||
// on the row id.
|
||||
const rowId = (table, act, cellText) => page.$$eval(`#${table} tbody tr`,
|
||||
(trs, x) => {
|
||||
const tr = trs.find((r) => (r.children[0].textContent || '').trim() === x.cell);
|
||||
if (!tr) return null;
|
||||
const b = tr.querySelector(`button[data-act="${x.act}"]`);
|
||||
return b ? b.dataset.k : null;
|
||||
}, { act, cell: cellText });
|
||||
const allowId = await rowId('allow', 'delallow', HORIZON_ALLOW);
|
||||
const ruleId = await rowId('pathrules', 'delrule', HORIZON_RULE);
|
||||
if (allowId) await page.click(`#allow tbody button[data-act="delallow"][data-k="${allowId}"]`);
|
||||
if (ruleId) await page.click(`#pathrules tbody button[data-act="delrule"][data-k="${ruleId}"]`);
|
||||
await page.click(`#blocks tbody button[data-act="delblock"][data-k="${HORIZON_NET}"]`);
|
||||
await page.waitForFunction(() => ![...document.querySelectorAll('#blocks tbody button[data-act="delblock"]')]
|
||||
.some((b) => b.dataset.k === '192.0.2.232/29'), null, { timeout: 15000 }).catch(() => {});
|
||||
const horizonTorn = await page.$$eval('#blocks tbody button[data-act="delblock"]',
|
||||
(bs) => bs.map((b) => b.dataset.k));
|
||||
check('the horizon seeds left the operator list the way they were found',
|
||||
!horizonTorn.includes(HORIZON_NET), JSON.stringify(horizonTorn));
|
||||
}
|
||||
|
||||
// A phone in dark mode is the case an operator actually reaches the console
|
||||
// from — the address that got them blocked is the one they are typing about.
|
||||
// Both halves of this used to be broken and measured: the page overflowed a
|
||||
|
||||
@@ -913,6 +913,123 @@ check 'the scene cleans itself' 0 \
|
||||
curl -s -H "X-Admin-Token: $TOKEN" "http://127.0.0.1:$EDGE_PORT/admin-api/blocks?live=false" \
|
||||
| python3 -c 'import sys,json;print(len([r for r in json.load(sys.stdin) if r["sourceKey"] in ("192.0.2.121","192.0.2.128/29")]))')"
|
||||
|
||||
# What stops being enforced soon (OPEN-72). A list of expiry dates tells an
|
||||
# operator nothing about what the site will be doing tomorrow: the row has to
|
||||
# carry the answer that takes over when the entry ages out, or "expires at 06:00"
|
||||
# is a timestamp to interpret by hand at 05:55.
|
||||
echo '- the enforcement horizon'
|
||||
HOR_IP=192.0.2.151
|
||||
HOR_NET=192.0.2.152/29 # .152 - .159
|
||||
HOR_INSIDE=192.0.2.155
|
||||
horizon() { curl -s -H "X-Admin-Token: $TOKEN" \
|
||||
"http://127.0.0.1:$EDGE_PORT/admin-api/expiring?within=${1:-30}"; }
|
||||
check 'the operator writes a block, a range, an allow and a path rule that all expire today' '204 204 204 204' \
|
||||
"$(code -X POST -H "X-Admin-Token: $TOKEN" -H 'Content-Type: application/json' \
|
||||
--data-binary '{"ip":"'"$HOR_IP"'","reason":"horizon block","expiresInMinutes":45}' \
|
||||
"http://127.0.0.1:$EDGE_PORT/admin-api/blocks") \
|
||||
$(code -X POST -H "X-Admin-Token: $TOKEN" -H 'Content-Type: application/json' \
|
||||
--data-binary '{"ip":"'"$HOR_NET"'","reason":"horizon range","expiresInMinutes":20}' \
|
||||
"http://127.0.0.1:$EDGE_PORT/admin-api/blocks") \
|
||||
$(code -X POST -H "X-Admin-Token: $TOKEN" -H 'Content-Type: application/json' \
|
||||
--data-binary '{"match":"192.0.2.155","note":"horizon allow","expiresInMinutes":60}' \
|
||||
"http://127.0.0.1:$EDGE_PORT/admin-api/allow") \
|
||||
$(code -X POST -H "X-Admin-Token: $TOKEN" -H 'Content-Type: application/json' \
|
||||
--data-binary '{"pattern":"/horizon-gate*","action":"block","note":"horizon rule","expiresInMinutes":25}' \
|
||||
"http://127.0.0.1:$EDGE_PORT/admin-api/rules")"
|
||||
check 'the horizon lists them nearest first, from the database' yes \
|
||||
"$(horizon 90 | python3 -c '
|
||||
import sys,json
|
||||
d=json.load(sys.stdin)
|
||||
rows=[r for r in d["expiring"] if r["match"] in ("192.0.2.151","192.0.2.152/29","192.0.2.155") or r["pattern"]=="/horizon-gate*"]
|
||||
order=[r["match"] or r["pattern"] for r in rows]
|
||||
print("yes" if d["scope"]=="database" and d["count"]>=4 and order==["192.0.2.152/29","/horizon-gate*","192.0.2.151","192.0.2.155"] else "no")')"
|
||||
check 'the allow says which range refuses its address once it ages out' yes \
|
||||
"$(horizon 90 | python3 -c '
|
||||
import sys,json
|
||||
rows=[r for r in json.load(sys.stdin)["expiring"] if r["kind"]=="allow" and r["match"]=="192.0.2.155"]
|
||||
t=rows[0]["thenAnswers"] if rows else None
|
||||
print("yes" if t and t["verdict"]=="block_operator" and t["wouldBeRefused"] and t["by"]=="192.0.2.152/29" else "no")')"
|
||||
check 'a block with nothing underneath says the source goes free' yes \
|
||||
"$(horizon 90 | python3 -c '
|
||||
import sys,json
|
||||
rows=[r for r in json.load(sys.stdin)["expiring"] if r["kind"]=="block" and r["match"]=="192.0.2.151"]
|
||||
t=rows[0]["thenAnswers"] if rows else None
|
||||
print("yes" if t and t["verdict"]=="pass" and not t["wouldBeRefused"] and "nothing else refuses" in t["note"] else "no")')"
|
||||
check 'a range answers for its own network address, not for the notation' yes \
|
||||
"$(horizon 90 | python3 -c '
|
||||
import sys,json
|
||||
rows=[r for r in json.load(sys.stdin)["expiring"] if r["kind"]=="range" and r["match"]=="192.0.2.152/29"]
|
||||
t=rows[0]["thenAnswers"] if rows else None
|
||||
print("yes" if t and t["verdict"]=="pass" and not t["wouldBeRefused"] else "no")')"
|
||||
check 'a path rule says why it has no single answer and points at the dry run' yes \
|
||||
"$(horizon 90 | python3 -c '
|
||||
import sys,json
|
||||
rows=[r for r in json.load(sys.stdin)["expiring"] if r["pattern"]=="/horizon-gate*"]
|
||||
r=rows[0] if rows else None
|
||||
print("yes" if r and r["thenAnswers"] is None and "/admin-api/decide?ip=&path=" in (r["whyNoAnswer"] or "") else "no")')"
|
||||
check 'every row counts down in whole minutes from now' yes \
|
||||
"$(horizon 90 | python3 -c '
|
||||
import sys,json
|
||||
rows=[r for r in json.load(sys.stdin)["expiring"] if (r["match"] or r["pattern"]) in ("192.0.2.151","192.0.2.152/29","192.0.2.155","/horizon-gate*")]
|
||||
print("yes" if len(rows)==4 and all(0 < r["minutesLeft"] <= 60 for r in rows) else "no")')"
|
||||
check 'the answer separates "nothing expires soon" from "nothing is dated"' yes \
|
||||
"$(horizon 1 | python3 -c '
|
||||
import sys,json
|
||||
d=json.load(sys.stdin)
|
||||
mine=[r for r in d["expiring"] if (r["match"] or r["pattern"]) in ("192.0.2.151","192.0.2.152/29","192.0.2.155","/horizon-gate*")]
|
||||
print("yes" if not mine and d["withinMinutes"]==1 and all(k in d["alreadyExpired"] for k in ("block","range","engineBan","allow","pathRule","pathBudget")) else "no")')"
|
||||
check 'no window asked is answered with the default, and it says so' '30 200' \
|
||||
"$(horizon | python3 -c 'import sys,json;print(json.load(sys.stdin)["withinMinutes"])') \
|
||||
$(code -H "X-Admin-Token: $TOKEN" "http://127.0.0.1:$EDGE_PORT/admin-api/expiring")"
|
||||
check 'a window of zero minutes or of more than a day is refused by name' '400 400' \
|
||||
"$(code -H "X-Admin-Token: $TOKEN" "http://127.0.0.1:$EDGE_PORT/admin-api/expiring?within=0") \
|
||||
$(code -H "X-Admin-Token: $TOKEN" "http://127.0.0.1:$EDGE_PORT/admin-api/expiring?within=1441")"
|
||||
check 'a question it cannot answer is refused by name' 400 \
|
||||
"$(code -H "X-Admin-Token: $TOKEN" "http://127.0.0.1:$EDGE_PORT/admin-api/expiring?within=30&nonsense=1")"
|
||||
check 'the read-only token reads the horizon, no token does not' '200 401' \
|
||||
"$(code -H "X-Admin-Token: $RO_TOKEN" "http://127.0.0.1:$EDGE_PORT/admin-api/expiring?within=90") \
|
||||
$(code "http://127.0.0.1:$EDGE_PORT/admin-api/expiring?within=90")"
|
||||
check 'asking it six times wrote nothing: the dated rows are still the four it was shown' '2 1' \
|
||||
"$(for _ in 1 2 3 4 5 6; do horizon 90 >/dev/null; done; \
|
||||
curl -s -H "X-Admin-Token: $TOKEN" "http://127.0.0.1:$EDGE_PORT/admin-api/blocks?live=false" -o /tmp/hor-blocks.json; \
|
||||
curl -s -H "X-Admin-Token: $TOKEN" "http://127.0.0.1:$EDGE_PORT/admin-api/allow?live=false" -o /tmp/hor-allow.json; \
|
||||
python3 -c '
|
||||
import json
|
||||
b=json.load(open("/tmp/hor-blocks.json")); a=json.load(open("/tmp/hor-allow.json"))
|
||||
print(len([r for r in b if r["sourceKey"] in ("192.0.2.151","192.0.2.152/29")]),
|
||||
len([r for r in a if r["match"]=="192.0.2.155"]))')"
|
||||
# The prediction has to be true, not plausible: take the allow away for real and
|
||||
# ask the wire the same question the horizon answered.
|
||||
HOR_ALLOW_ID="$(curl -s -H "X-Admin-Token: $TOKEN" "http://127.0.0.1:$EDGE_PORT/admin-api/allow?live=false" \
|
||||
| python3 -c 'import sys,json;print([a["id"] for a in json.load(sys.stdin) if a["match"]=="192.0.2.155"][0])')"
|
||||
check 'the horizon was right: with the allow gone the wire refuses that address' 'block_operator 192.0.2.152/29' \
|
||||
"$(code -X DELETE -H "X-Admin-Token: $TOKEN" \
|
||||
"http://127.0.0.1:$EDGE_PORT/admin-api/allow/$HOR_ALLOW_ID" >/dev/null; \
|
||||
curl -s -H "X-Admin-Token: $TOKEN" \
|
||||
"http://127.0.0.1:$EDGE_PORT/admin-api/decide?ip=$HOR_INSIDE&path=/" -o /tmp/hor_decide.json; \
|
||||
curl -s -H "X-Admin-Token: $TOKEN" \
|
||||
"http://127.0.0.1:$EDGE_PORT/admin-api/source?ip=$HOR_INSIDE" -o /tmp/hor_dossier.json; \
|
||||
python3 -c '
|
||||
import json
|
||||
d=json.load(open("/tmp/hor_decide.json")); e=json.load(open("/tmp/hor_dossier.json"))["operatorBlock"]
|
||||
print(d["verdict"], e["match"] if e and e["cameFromRange"] else None)')"
|
||||
check 'the scene cleans itself' '0 0' \
|
||||
"$(code -X DELETE -H "X-Admin-Token: $TOKEN" \
|
||||
"http://127.0.0.1:$EDGE_PORT/admin-api/blocks?key=$HOR_IP" >/dev/null; \
|
||||
code -X DELETE -H "X-Admin-Token: $TOKEN" \
|
||||
"http://127.0.0.1:$EDGE_PORT/admin-api/blocks?key=${HOR_NET//\//%2F}" >/dev/null; \
|
||||
curl -s -H "X-Admin-Token: $TOKEN" "http://127.0.0.1:$EDGE_PORT/admin-api/rules?live=false" -o /tmp/hor-rules.json; \
|
||||
HOR_RULE_ID="$(python3 -c 'import json;print([r["id"] for r in json.load(open("/tmp/hor-rules.json")) if r["pattern"]=="/horizon-gate*"][0])')"; \
|
||||
code -X DELETE -H "X-Admin-Token: $TOKEN" \
|
||||
"http://127.0.0.1:$EDGE_PORT/admin-api/rules/$HOR_RULE_ID" >/dev/null; \
|
||||
curl -s -H "X-Admin-Token: $TOKEN" "http://127.0.0.1:$EDGE_PORT/admin-api/blocks?live=false" -o /tmp/hor-blocks2.json; \
|
||||
curl -s -H "X-Admin-Token: $TOKEN" "http://127.0.0.1:$EDGE_PORT/admin-api/rules?live=false" -o /tmp/hor-rules2.json; \
|
||||
python3 -c '
|
||||
import json
|
||||
b=json.load(open("/tmp/hor-blocks2.json")); r=json.load(open("/tmp/hor-rules2.json"))
|
||||
print(len([x for x in b if x["sourceKey"] in ("192.0.2.151","192.0.2.152/29")]),
|
||||
len([x for x in r if x["pattern"]=="/horizon-gate*"]))')"
|
||||
|
||||
echo '- admin surface'
|
||||
check 'no token is refused' 401 "$(code "http://127.0.0.1:$EDGE_PORT/admin-api/blocks")"
|
||||
check 'the policy is readable' Enforce \
|
||||
|
||||
Reference in New Issue
Block a user