the dry run says what the volume pillar would answer for that source
`GET /admin-api/decide` answers what would happen to a named request and which pillar said so, and it stayed silent about the one pillar whose number the operator is choosing. The count is kept in the guard rather than read off a snapshot, so the preview printed `rate: not_evaluated` and left "would this source be rate-limited" as the one question the surface exists to answer could not ask. The rulings this had to make, and the answer each one got: * Reading, never spending, is the invariant. The section is built from peek reads of both trackers, so N dry runs leave `count` exactly where it was and write no alert. A preview that answered by counting its own question would refuse the next real request because somebody pressed a button — the tool for finding an over-tight budget would itself be the cause of it. * Four silences stay apart: `not_counted` (the pillar is off, so there is no budget to cross), `no_source` (no address was asked, and a budget is a claim about a source), `refused_now`, `would_be_counted`. A fifth, `over_budget_not_enforced`, exists because "over budget" and "would be refused" are two answers separated by the mode, and collapsing them is how an observe budget becomes a surprise the day someone switches it on. * `reached: false` says an earlier pillar answers the request, so the guard would never consult the counter for it. The volume section still reports the counters — they are true — but the note stops talking about a budget this request would never touch. * A budget in force for the path with nothing counted for this source yet prints `counted: false`, not `count: 0`. "0 of 2" and "nothing yet" are answers an operator acts on differently. * The path budgets are matched by the same `PathPattern.Matches`, in the same order, as the guard: a preview that matched differently would be a preview of a different edge. * The counters are this process's (`scope: "this-process"`), said in the answer rather than left for the operator to remember. * The `rate` pillar row keeps `not_evaluated` — the engine really did not evaluate it — and its note now points at the section that did, instead of ending as a silence. What the runs caught, in order: * The first version answered `refused_now` for an Observe crossing. The counters were right and the sentence was wrong: observe enforces nothing. The mode is now part of the verdict. * An integration expectation asserted the note of the `rate` pillar row after a crossing, and read the engine ban the crossing itself had written instead — the request was no longer reaching the volume pillar. The assertion moved to the preview taken before the crossing, and the ban case now asserts the honest note. * Rewording that note broke an older preview test that keyed on the word "preview" in it; the wording keeps the word, and the older test is the one that caught the rewording. * The smoke scene compared a listing's over-budget count against a request count, which would have passed for the wrong reason; it now asserts the pair (tracked, over) before and after six previews. Gates at this commit, each stage on its own: build 0 warnings / 0 errors, unit 371/371, integration 345/345 in 43 s, console 122 assertions 0 failed, smoke passed 182 failed 0, compose 304 passed 0 failed against the built image at 262 MB, 0 containers left behind. Refs OPEN-69.
This commit is contained in:
@@ -1727,6 +1727,33 @@ check 'removing the budget reopens the path, and the volume is left as it was' '
|
||||
"$EDGE/admin-api/policy" >/dev/null; \
|
||||
code -H "X-Forwarded-For: $PATH_BUDGET_IP" "$EDGE/budgeted")"
|
||||
|
||||
# The dry run answers the volume pillar (OPEN-69), on the shipped image: the
|
||||
# preview used to answer every pillar and stay silent about the one whose number
|
||||
# the operator is choosing.
|
||||
echo '- the shipped dry run answers the volume pillar'
|
||||
DRY_ON_JSON='{"rateMode":"enforce","rateLimitPerWindow":1000,"rateWindowSeconds":120}'
|
||||
DRY_RULE_JSON='{"pattern":"/dryrun*","limitPerWindow":2,"windowSeconds":120}'
|
||||
DRY_IP=198.51.100.92
|
||||
admin -X PUT -H 'Content-Type: application/json' --data-binary "$DRY_ON_JSON" \
|
||||
"$EDGE/admin-api/policy" >/dev/null
|
||||
code -X POST -H "X-Admin-Token: $OPENWAF_ADMIN_TOKEN" -H 'Content-Type: application/json' \
|
||||
--data-binary "$DRY_RULE_JSON" "$EDGE/admin-api/rate-rules" >/dev/null
|
||||
check 'the shipped preview answers the volume pillar for a source with nothing counted' 'yes' \
|
||||
"$(admin "$EDGE/admin-api/decide?ip=$DRY_IP&path=/dryrun" | python3 -c 'import sys,json;v=json.load(sys.stdin)["volume"];print("yes" if v["verdict"]=="would_be_counted" and v["edgeBudget"] is None and v["pathBudgets"][0]["counted"] is False else "no")')"
|
||||
for _ in 1 2 3; do code -H "X-Forwarded-For: $DRY_IP" "$EDGE/dryrun" >/dev/null; done
|
||||
check 'the shipped preview says this source is over that budget now' 'yes' \
|
||||
"$(admin "$EDGE/admin-api/decide?ip=$DRY_IP&path=/dryrun" | python3 -c 'import sys,json;v=json.load(sys.stdin)["volume"];b=v["pathBudgets"][0];print("yes" if v["verdict"]=="refused_now" and b["count"]==3 and b["overBudget"] else "no")')"
|
||||
check 'six shipped previews leave the counters exactly where they were' '1 1' \
|
||||
"$(for _ in 1 2 3 4 5 6; do admin "$EDGE/admin-api/decide?ip=$DRY_IP&path=/dryrun" >/dev/null; done; \
|
||||
admin "$EDGE/admin-api/rate-rules" | python3 -c 'import sys,json;r=json.load(sys.stdin)[0];print(r["trackedSources"], r["overBudgetNow"])')"
|
||||
DRY_RULE_ID="$(admin "$EDGE/admin-api/rate-rules" | python3 -c 'import sys,json;print(json.load(sys.stdin)[0]["id"])')"
|
||||
check 'the scene cleans itself, so the volume is left as it was found' 'not_counted' \
|
||||
"$(admin -X DELETE "$EDGE/admin-api/rate-rules/$DRY_RULE_ID" >/dev/null; \
|
||||
admin -X PUT -H 'Content-Type: application/json' --data-binary '{"rateMode":"Off"}' \
|
||||
"$EDGE/admin-api/policy" >/dev/null; \
|
||||
admin "$EDGE/admin-api/decide?ip=$DRY_IP&path=/dryrun" \
|
||||
| python3 -c 'import sys,json;print(json.load(sys.stdin)["volume"]["verdict"])')"
|
||||
|
||||
echo
|
||||
printf 'compose smoke: %d passed, %d failed\n' "$PASS" "$FAIL"
|
||||
[ "$FAIL" -eq 0 ]
|
||||
|
||||
@@ -529,6 +529,29 @@ const rgb = (s) => s.match(/\d+/g).slice(0, 3).map(Number);
|
||||
// first: otherwise the answer is the streak's 403 and the scene proves
|
||||
// nothing about the row it removed.
|
||||
await adminDelete('/admin-api/blocks?source=engine');
|
||||
|
||||
// The same question asked from the page (OPEN-69). The dry run answers the
|
||||
// volume pillar from the counters the checks above have already shown to be one
|
||||
// over budget — and asking it here is a read, so the counters still say the same
|
||||
// afterwards.
|
||||
await page.fill('#askIp', PATH_BUDGET_IP);
|
||||
await page.fill('#askPath', PATH_BUDGET_PATH);
|
||||
await page.click('#askDecide');
|
||||
await page.waitForFunction(() => /volume:/.test(document.getElementById('askanswer').textContent),
|
||||
null, { timeout: 15000 }).catch(() => {});
|
||||
const asked = (await page.textContent('#askanswer')).replace(/\s+/g, ' ');
|
||||
check('the page can ask what the edge would answer, and the volume pillar answers it',
|
||||
/volume: Enforce . refused_now/.test(asked) && /OVER/.test(asked), asked.slice(0, 240));
|
||||
const beforeRerender = (await cells('#raterules tbody tr')).find((r) => (r[0] || '') === `${PATH_BUDGET_PATH}*`);
|
||||
await page.click('#refresh');
|
||||
await page.waitForFunction((pat) => {
|
||||
const tr = [...document.querySelectorAll('#raterules tbody tr')].find((r) => r.children[0].textContent === pat);
|
||||
return !!tr && Number(tr.children[5].textContent) >= 1;
|
||||
}, `${PATH_BUDGET_PATH}*`, { timeout: 15000 }).catch(() => {});
|
||||
const afterRerender = (await cells('#raterules tbody tr')).find((r) => (r[0] || '') === `${PATH_BUDGET_PATH}*`);
|
||||
check('asking the dry run from the page did not move the counters',
|
||||
!!beforeRerender && !!afterRerender && beforeRerender.join('|') === afterRerender.join('|'),
|
||||
`${JSON.stringify(beforeRerender)} then ${JSON.stringify(afterRerender)}`);
|
||||
const countedRow = (await cells('#raterules tbody tr')).find((r) => (r[0] || '') === `${PATH_BUDGET_PATH}*`);
|
||||
check('the page says who the budget counted and who is over it now',
|
||||
!!countedRow && Number(countedRow[3]) >= 1 && Number(countedRow[4]) >= 1 && Number(countedRow[5]) >= 1,
|
||||
|
||||
@@ -737,6 +737,68 @@ rm -f /tmp/openwaf-upstream/login.txt
|
||||
curl -s -X PUT -H "X-Admin-Token: $TOKEN" -H 'Content-Type: application/json' \
|
||||
--data-binary "$RATE_OFF_JSON" "http://127.0.0.1:$EDGE_PORT/admin-api/policy" >/dev/null
|
||||
|
||||
# The dry run answers the volume pillar (OPEN-69). The preview used to answer
|
||||
# every pillar and stay silent about the one whose number the operator is choosing;
|
||||
# the claim worth testing on the wire is that it answers it without spending it.
|
||||
echo '- the dry run answers the volume pillar'
|
||||
echo 'dry run' > /tmp/openwaf-upstream/dryrun.txt
|
||||
DRY_ON_JSON='{"rateMode":"enforce","rateLimitPerWindow":1000,"rateWindowSeconds":120}'
|
||||
DRY_RULE_JSON='{"pattern":"/dryrun*","limitPerWindow":2,"windowSeconds":120}'
|
||||
DRY_IP=192.0.2.88
|
||||
decide() { curl -s -H "X-Admin-Token: $TOKEN" \
|
||||
"http://127.0.0.1:$EDGE_PORT/admin-api/decide?ip=$1&path=$2"; }
|
||||
check 'the volume switch is on for this scene' Enforce \
|
||||
"$(curl -s -X PUT -H "X-Admin-Token: $TOKEN" -H 'Content-Type: application/json' \
|
||||
--data-binary "$DRY_ON_JSON" "http://127.0.0.1:$EDGE_PORT/admin-api/policy" \
|
||||
| python3 -c 'import sys,json;print(json.load(sys.stdin)["rateMode"])')"
|
||||
check 'a source with no running window is answered as nothing counted, not as zero of the limit' yes \
|
||||
"$(decide "$DRY_IP" /dryrun.txt \
|
||||
| python3 -c 'import sys,json;v=json.load(sys.stdin)["volume"];print("yes" if v["verdict"]=="would_be_counted" and v["edgeBudget"] is None and v["pathBudgets"]==[] else "no")')"
|
||||
check 'a written path budget appears in the preview for its path' 204 \
|
||||
"$(code -X POST -H "X-Admin-Token: $TOKEN" -H 'Content-Type: application/json' \
|
||||
--data-binary "$DRY_RULE_JSON" "http://127.0.0.1:$EDGE_PORT/admin-api/rate-rules")"
|
||||
check 'and it says so before it has counted anything for this source' yes \
|
||||
"$(decide "$DRY_IP" /dryrun.txt \
|
||||
| python3 -c 'import sys,json;b=json.load(sys.stdin)["volume"]["pathBudgets"][0];print("yes" if b["pattern"]=="/dryrun*" and not b["counted"] and b["count"] is None else "no")')"
|
||||
check 'the first two requests on that path are proxied' '200 200' \
|
||||
"$(code -H "X-Forwarded-For: $DRY_IP" "$(from dryrun.txt)") $(code -H "X-Forwarded-For: $DRY_IP" "$(from dryrun.txt)")"
|
||||
check 'the third crosses the budget' 429 \
|
||||
"$(code -H "X-Forwarded-For: $DRY_IP" "$(from dryrun.txt)")"
|
||||
check 'the preview now says this source is over that budget' yes \
|
||||
"$(decide "$DRY_IP" /dryrun.txt \
|
||||
| python3 -c 'import sys,json;v=json.load(sys.stdin)["volume"];b=v["pathBudgets"][0];print("yes" if v["verdict"]=="refused_now" and b["count"]==3 and b["overBudget"] and b["secondsLeft"]>=1 else "no")')"
|
||||
check 'a path the budget does not name is answered without it' yes \
|
||||
"$(decide "$DRY_IP" /wp-admin \
|
||||
| python3 -c 'import sys,json;v=json.load(sys.stdin)["volume"];print("yes" if v["pathBudgets"]==[] and v["verdict"]=="would_be_counted" else "no")')"
|
||||
# The counters of the listing are the same counters the preview reads, so the pair
|
||||
# is compared before and after: a preview that answered by counting its own
|
||||
# question would move them, and the next real request would be refused because
|
||||
# somebody pressed a button.
|
||||
BUDGET_COUNTERS='import sys,json;r=json.load(sys.stdin)[0];print(r["trackedSources"], r["overBudgetNow"])'
|
||||
check 'the listing says one source is over that budget' '1 1' \
|
||||
"$(curl -s -H "X-Admin-Token: $TOKEN" "http://127.0.0.1:$EDGE_PORT/admin-api/rate-rules" \
|
||||
| python3 -c "$BUDGET_COUNTERS")"
|
||||
check 'six previews leave those counters exactly where they were' '1 1' \
|
||||
"$(for _ in 1 2 3 4 5 6; do decide "$DRY_IP" /dryrun.txt >/dev/null; done; \
|
||||
curl -s -H "X-Admin-Token: $TOKEN" "http://127.0.0.1:$EDGE_PORT/admin-api/rate-rules" \
|
||||
| python3 -c "$BUDGET_COUNTERS")"
|
||||
check 'the pillar row that used to be a silence names the volume section' yes \
|
||||
"$(decide "$DRY_IP" /dryrun.txt \
|
||||
| python3 -c 'import sys,json;d=json.load(sys.stdin);print("yes" if any("volume" in (p.get("note") or "") for p in d["pillars"] if p["pillar"]=="rate") else "no")')"
|
||||
check 'with the pillar off the preview says nothing is counted' yes \
|
||||
"$(curl -s -X PUT -H "X-Admin-Token: $TOKEN" -H 'Content-Type: application/json' \
|
||||
--data-binary "$RATE_OFF_JSON" "http://127.0.0.1:$EDGE_PORT/admin-api/policy" >/dev/null; \
|
||||
decide "$DRY_IP" /dryrun.txt \
|
||||
| python3 -c 'import sys,json;v=json.load(sys.stdin)["volume"];print("yes" if v["verdict"]=="not_counted" and v["edgeBudget"] is None else "no")')"
|
||||
DRY_RULE_ID="$(curl -s -H "X-Admin-Token: $TOKEN" "http://127.0.0.1:$EDGE_PORT/admin-api/rate-rules" \
|
||||
| python3 -c 'import sys,json;print(json.load(sys.stdin)[0]["id"])')"
|
||||
check 'the scene cleans itself, so the rest of the gate runs on the stack it expects' 0 \
|
||||
"$(code -X DELETE -H "X-Admin-Token: $TOKEN" \
|
||||
"http://127.0.0.1:$EDGE_PORT/admin-api/rate-rules/$DRY_RULE_ID" >/dev/null; \
|
||||
curl -s -H "X-Admin-Token: $TOKEN" "http://127.0.0.1:$EDGE_PORT/admin-api/rate-rules" \
|
||||
| python3 -c 'import sys,json;print(len(json.load(sys.stdin)))')"
|
||||
rm -f /tmp/openwaf-upstream/dryrun.txt
|
||||
|
||||
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