one address in, and the edge answers everything it knows about it
An operator investigating one source had to open six admin calls — blocks,
allow, streaks, observations, alerts, the dry run — and hold the join in their
head. The join is where the wrong answers are: a v6 address looked up in full
when the ban is filed on the /64, a CIDR ban looked up by equality that never
finds it, an exemption that expired last week read as a live one, a streak
counted in one process read as the deployment's.
GET /admin-api/source?ip=<address>[&path=<path>] answers it in one call, by
asking the same objects the request path asks rather than a second copy of
their logic. Three rulings hold it together:
* Containment, not equality. operatorBlock carries cameFromRange and the
match that covered the address, through the same NetworkBanIndex the wire
matches with (longest prefix first) and NetworkMatch for the allowlist.
There is no second matcher in this build to drift.
* The key, not the address. sourceKey and the prefix lengths that produced
it travel in the answer: bans, streaks and budgets are filed under the key,
the allowlist and the range bans are matched against the address, and the
answer separates them.
* `none` and "not visible here" are different words. A live engine ban under
Observe mode reports applies: false with a verdict of none; an expired row
reports live: false rather than null, because "this address used to be
exempt" is a fact an operator acts on.
Nothing is written and nothing is spent — the dry run's rule applied to the
whole dossier. RateRuleTracker.WindowsFor is a new read that lists every path
budget a source is already inside without being handed a path, so the dossier
does not have to guess from a path it was not given, and N dossiers leave every
counter where they found it. ip is required and must be a full address: a typo
is a 400 naming the value, never a none. The read-only token may ask it.
What the run caught, on this tree: the console scene waited for "an answer is
in the box", which the previous answer still sitting there satisfies — three
assertions read the address asked one click earlier. The scene now empties the
box and waits for the address it asked by name, and matches a range row by the
key its delete button holds rather than by a cell that prints a `range` badge.
build 0 warnings / 0 errors, unit 374/374, integration 356/356 in 39 s,
console 126 assertions / 0 failed, smoke passed 192 / failed 0, compose 311
passed / 0 failed against the built image at 262 MB.
Refs OPEN-70.
This commit is contained in:
@@ -1754,6 +1754,40 @@ check 'the scene cleans itself, so the volume is left as it was found' 'not_coun
|
||||
admin "$EDGE/admin-api/decide?ip=$DRY_IP&path=/dryrun" \
|
||||
| python3 -c 'import sys,json;print(json.load(sys.stdin)["volume"]["verdict"])')"
|
||||
|
||||
|
||||
# One address, one answer (OPEN-70), on the shipped image. The point is the join:
|
||||
# an address the operator blocked on its own key, and an address a banned range
|
||||
# covers without any row naming it. The second is the one every single-table
|
||||
# listing answered "nothing".
|
||||
echo '- the shipped edge answers one address in one call'
|
||||
DOS_IP=198.51.100.141
|
||||
DOS_NET=198.51.100.144/29 # .144 - .151
|
||||
DOS_INSIDE=198.51.100.147
|
||||
DOS_OUTSIDE=198.51.100.152
|
||||
check 'the shipped edge takes an address block and a range block' '204 204' \
|
||||
"$(code -X POST -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" -H 'Content-Type: application/json' \
|
||||
--data-binary '{"ip":"'"$DOS_IP"'","reason":"dossier scene"}' "$EDGE/admin-api/blocks") \
|
||||
$(code -X POST -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" -H 'Content-Type: application/json' \
|
||||
--data-binary '{"ip":"'"$DOS_NET"'","reason":"dossier range"}' "$EDGE/admin-api/blocks")"
|
||||
check 'the shipped dossier answers on the key and names the row behind it' 'yes' \
|
||||
"$(admin "$EDGE/admin-api/source?ip=$DOS_IP" | python3 -c 'import sys,json;d=json.load(sys.stdin);b=d["operatorBlock"];print("yes" if d["verdict"]=="block_operator" and d["sourceKey"]=="'"$DOS_IP"'" and b and not b["cameFromRange"] and b["live"] else "no")')"
|
||||
check 'the shipped dossier finds the range that covers an address no row names' 'yes' \
|
||||
"$(admin "$EDGE/admin-api/source?ip=$DOS_INSIDE" | python3 -c 'import sys,json;d=json.load(sys.stdin);b=d["operatorBlock"];print("yes" if d["verdict"]=="block_operator" and b and b["cameFromRange"] and b["match"]=="'"$DOS_NET"'" else "no")')"
|
||||
check 'the shipped dossier says none for a source it knows nothing about' 'yes' \
|
||||
"$(admin "$EDGE/admin-api/source?ip=$DOS_OUTSIDE" | python3 -c 'import sys,json;d=json.load(sys.stdin);print("yes" if d["verdict"]=="none" and not d["operatorBlock"] and not d["allow"] and not d["engineBan"] else "no")')"
|
||||
check 'the shipped dossier refuses a question it cannot answer' '400 400' \
|
||||
"$(code -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" "$EDGE/admin-api/source?ip=198.51.100") \
|
||||
$(code -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" "$EDGE/admin-api/source")"
|
||||
check 'asking it six times wrote nothing to the operator list' 2 \
|
||||
"$(for _ in 1 2 3 4 5 6; do admin "$EDGE/admin-api/source?ip=$DOS_IP" >/dev/null; done; \
|
||||
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 ("'"$DOS_IP"'","'"$DOS_NET"'")]))')"
|
||||
check 'the scene cleans itself' 0 \
|
||||
"$(admin -X DELETE "$EDGE/admin-api/blocks?key=$DOS_IP" >/dev/null; \
|
||||
admin -X DELETE "$EDGE/admin-api/blocks?key=${DOS_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 ("'"$DOS_IP"'","'"$DOS_NET"'")]))')"
|
||||
|
||||
echo
|
||||
printf 'compose smoke: %d passed, %d failed\n' "$PASS" "$FAIL"
|
||||
[ "$FAIL" -eq 0 ]
|
||||
|
||||
@@ -578,6 +578,72 @@ const rgb = (s) => s.match(/\d+/g).slice(0, 3).map(Number);
|
||||
check('the volume switch is left off, as the stack was seeded',
|
||||
(await page.$$eval('#rateMode', (s) => s[0].value)) === 'off', await page.$$eval('#rateMode', (s) => s[0].value));
|
||||
|
||||
// One address, one answer (OPEN-70), asked from the page. Two shapes are worth
|
||||
// asserting because they are the two the six separate listings got wrong: a
|
||||
// block written on the address itself, and a block written on a network that
|
||||
// contains the address - the second is invisible to anything that compares keys.
|
||||
const DOSSIER_IP = '192.0.2.211';
|
||||
const DOSSIER_NET = '192.0.2.216/29'; // .216 - .223
|
||||
const DOSSIER_INSIDE = '192.0.2.219';
|
||||
const DOSSIER_OUTSIDE = '192.0.2.224';
|
||||
|
||||
await page.fill('#blockIp', DOSSIER_IP);
|
||||
await page.fill('#blockReason', 'console gate: dossier address');
|
||||
await page.click('#addBlock');
|
||||
await page.waitForFunction((ip) => [...document.querySelectorAll('#blocks tbody tr')]
|
||||
.some((tr) => tr.children[0].textContent === ip), DOSSIER_IP, { timeout: 15000 }).catch(() => {});
|
||||
await page.fill('#blockIp', DOSSIER_NET);
|
||||
await page.fill('#blockReason', 'console gate: dossier range');
|
||||
await page.click('#addBlock');
|
||||
// The row's first cell carries the `range` badge, so the row is matched by the
|
||||
// key its delete button holds - the same name the delete is keyed by.
|
||||
const blockKeys = () => page.$$eval('#blocks tbody button[data-act="delblock"]',
|
||||
(bs) => bs.map((b) => b.dataset.k));
|
||||
await page.waitForFunction((net) => [...document.querySelectorAll('#blocks tbody button[data-act="delblock"]')]
|
||||
.some((b) => b.dataset.k === net), DOSSIER_NET, { timeout: 15000 }).catch(() => {});
|
||||
|
||||
const askDossier = async (ip) => {
|
||||
// The box is emptied first and then waited on for this address by name. The
|
||||
// console gate caught why: waiting only for "an answer is there" is satisfied
|
||||
// by the previous answer still sitting in the box, so every assertion after
|
||||
// the first reads the address asked one click earlier.
|
||||
await page.evaluate(() => { document.getElementById('dossieranswer').textContent = ''; });
|
||||
await page.fill('#dossierIp', ip);
|
||||
await page.click('#askSource');
|
||||
await page.waitForFunction((asked) => (document.getElementById('dossieranswer').textContent || '')
|
||||
.indexOf('key: ' + asked) === 0, ip, { timeout: 15000 }).catch(() => {});
|
||||
return (await page.textContent('#dossieranswer')).replace(/\s+/g, ' ');
|
||||
};
|
||||
|
||||
const onKey = await askDossier(DOSSIER_IP);
|
||||
check('the page answers for an address the operator blocked on its own key',
|
||||
/block_operator/.test(onKey) && /written on this key/.test(onKey) && /dossier address/.test(onKey),
|
||||
onKey.slice(0, 300));
|
||||
|
||||
const fromRange = await askDossier(DOSSIER_INSIDE);
|
||||
check('an address inside a banned range is answered by that range, not by a row that does not exist',
|
||||
/block_operator/.test(fromRange) && /from the range 192\.0\.2\.216\/29/.test(fromRange),
|
||||
fromRange.slice(0, 300));
|
||||
|
||||
const outside = await askDossier(DOSSIER_OUTSIDE);
|
||||
check('an address on no list is answered as none rather than as a verdict',
|
||||
/- none -/.test(outside) && /operator block: none/.test(outside),
|
||||
outside.slice(0, 300));
|
||||
|
||||
// A read, like the dry run: the dossier wrote nothing, so the operator's table
|
||||
// still holds exactly the two rows the page wrote and no third one.
|
||||
const dossierRows = await blockKeys();
|
||||
check('asking the dossier wrote nothing to the operator list',
|
||||
dossierRows.filter((k) => k === DOSSIER_IP || k === DOSSIER_NET).length === 2,
|
||||
JSON.stringify(dossierRows));
|
||||
|
||||
await page.click(`#blocks tbody button[data-act="delblock"][data-k="${DOSSIER_IP}"]`);
|
||||
await page.click(`#blocks tbody button[data-act="delblock"][data-k="${DOSSIER_NET}"]`);
|
||||
await page.waitForFunction((pair) => ![...document.querySelectorAll('#blocks tbody tr')]
|
||||
.some((tr) => pair.indexOf(tr.children[0].textContent) !== -1),
|
||||
[DOSSIER_IP, DOSSIER_NET], { timeout: 15000 }).catch(() => {});
|
||||
|
||||
|
||||
|
||||
await page.fill('#allowMatch', WRITE_CIDR);
|
||||
await page.fill('#allowNote', 'console gate: allow entry');
|
||||
|
||||
@@ -799,6 +799,58 @@ check 'the scene cleans itself, so the rest of the gate runs on the stack it exp
|
||||
| python3 -c 'import sys,json;print(len(json.load(sys.stdin)))')"
|
||||
rm -f /tmp/openwaf-upstream/dryrun.txt
|
||||
|
||||
# One address, one answer (OPEN-70). Every other listing here answers one table;
|
||||
# an operator investigating one source had to open six and hold the join in their
|
||||
# head. The two shapes this scene checks are the two that join got wrong: a block
|
||||
# written on the address itself, and a block written on a network that contains
|
||||
# the address - the second is invisible to anything that compares keys.
|
||||
echo '- one address, one answer'
|
||||
DOS_IP=192.0.2.121
|
||||
DOS_NET=192.0.2.128/29 # .128 - .135
|
||||
DOS_INSIDE=192.0.2.131
|
||||
DOS_OUTSIDE=192.0.2.136
|
||||
dossier() { curl -s -H "X-Admin-Token: $TOKEN" \
|
||||
"http://127.0.0.1:$EDGE_PORT/admin-api/source?ip=$1${2:+&path=$2}"; }
|
||||
check 'the operator writes an address and a range' '204 204' \
|
||||
"$(code -X POST -H "X-Admin-Token: $TOKEN" -H 'Content-Type: application/json' \
|
||||
--data-binary '{"ip":"192.0.2.121","reason":"dossier scene"}' \
|
||||
"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":"'"$DOS_NET"'","reason":"dossier range"}' \
|
||||
"http://127.0.0.1:$EDGE_PORT/admin-api/blocks")"
|
||||
check 'the dossier answers on the key, and names the rule that made it' yes \
|
||||
"$(dossier "$DOS_IP" | python3 -c 'import sys,json;d=json.load(sys.stdin);print("yes" if d["sourceKey"]=="192.0.2.121" and d["keyRule"]["ipv4PrefixLength"]==32 else "no")')"
|
||||
check 'an address the operator blocked on its own key is answered by that row' yes \
|
||||
"$(dossier "$DOS_IP" | python3 -c 'import sys,json;d=json.load(sys.stdin);b=d["operatorBlock"];print("yes" if d["verdict"]=="block_operator" and b and not b["cameFromRange"] and b["live"] and b["reason"]=="dossier scene" else "no")')"
|
||||
check 'an address inside a banned range is answered by that range, not by a row that does not exist' yes \
|
||||
"$(dossier "$DOS_INSIDE" | python3 -c 'import sys,json;d=json.load(sys.stdin);b=d["operatorBlock"];print("yes" if d["verdict"]=="block_operator" and b and b["cameFromRange"] and b["match"]=="192.0.2.128/29" else "no")')"
|
||||
check 'an address on no list is answered as none, with nothing invented for it' yes \
|
||||
"$(dossier "$DOS_OUTSIDE" | python3 -c 'import sys,json;d=json.load(sys.stdin);print("yes" if d["verdict"]=="none" and d["operatorBlock"] is None and d["allow"] is None and d["engineBan"] is None and d["streak"] is None else "no")')"
|
||||
check 'the answer says which store each part came from' yes \
|
||||
"$(dossier "$DOS_IP" | python3 -c 'import sys,json;d=json.load(sys.stdin);print("yes" if d["operatorBlock"]["scope"]=="database" and d["volume"]["scope"]=="this-process" and "allow" in d["scope"]["database"] else "no")')"
|
||||
check 'with a path the dossier and the dry run give the same verdict' yes \
|
||||
"$(python3 -c '
|
||||
import json,subprocess
|
||||
d=json.loads(subprocess.run(["curl","-s","-H","X-Admin-Token: '$TOKEN'",
|
||||
"http://127.0.0.1:'$EDGE_PORT'/admin-api/source?ip='$DOS_INSIDE'&path=/wp-admin"],capture_output=True,text=True).stdout)
|
||||
p=json.loads(subprocess.run(["curl","-s","-H","X-Admin-Token: '$TOKEN'",
|
||||
"http://127.0.0.1:'$EDGE_PORT'/admin-api/decide?ip='$DOS_INSIDE'&path=/wp-admin"],capture_output=True,text=True).stdout)
|
||||
print("yes" if d["wouldAnswer"]["verdict"]==p["verdict"]==d["verdict"]=="block_operator" else "no")')"
|
||||
check 'a question it cannot answer is refused by name' '400 400' \
|
||||
"$(code -H "X-Admin-Token: $TOKEN" "http://127.0.0.1:$EDGE_PORT/admin-api/source?ip=192.0.2") \
|
||||
$(code -H "X-Admin-Token: $TOKEN" "http://127.0.0.1:$EDGE_PORT/admin-api/source")"
|
||||
check 'asking it six times wrote nothing: the operator list still holds those two rows' 2 \
|
||||
"$(for _ in 1 2 3 4 5 6; do dossier "$DOS_IP" >/dev/null; dossier "$DOS_INSIDE" >/dev/null; done; \
|
||||
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")]))')"
|
||||
check 'the scene cleans itself' 0 \
|
||||
"$(code -X DELETE -H "X-Admin-Token: $TOKEN" \
|
||||
"http://127.0.0.1:$EDGE_PORT/admin-api/blocks?key=192.0.2.121" >/dev/null; \
|
||||
code -X DELETE -H "X-Admin-Token: $TOKEN" \
|
||||
"http://127.0.0.1:$EDGE_PORT/admin-api/blocks?key=${DOS_NET//\//%2F}" >/dev/null; \
|
||||
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")]))')"
|
||||
|
||||
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