Repository navigation
fix(server): count a request refused in the authorization step in UserErrors and RequestCount - #1427
LeeroyHannigan wants to merge 7 commits into
Conversation
…rErrors and RequestCount authorize_request refuses some requests before the IAM decision and some by it (AccessDeniedException). The refusals before it are a table name or ARN that breaks the rules and a batch outside its count limits. It also refuses a malformed stream, backup, export or tag ARN, a shard iterator the server cannot read, and a resource in another account. The handler's error arm for them answered the HTTP 400 and recorded no metric. A request the engine refuses, and the point-in-time recovery refusal in the same function, record UserErrors and RequestCount. The DynamoDB metrics documentation counts every request answered with an HTTP 400 in UserErrors. The arm now calls record_error_metrics and record_request_count as the point-in-time recovery refusal does. It passes no table name: UserErrors carries none, and the handler resolves the metric table name after this step. record_error_metrics records a storage fault of the key info lookup as SystemErrors. The authentication arms, where the handler knows no account yet, and the missing catalog store arm stay as they are. Measured on 2026-11-24 against a SQLite server built from main and one built from this change. One account sent five GetItem requests with the TableName "bad name!" and five Query requests from a user with no policy. It also sent five PutItem requests to a table that does not exist. On main, /metrics had no UserErrors or RequestCount row for the GetItem and the Query, and 5 and 5 for the PutItem. With the change each of the three has UserErrors 5 and RequestCount 5. The new wire file tests/test_metrics_refused_requests.py sends those three rows and asserts both counts by equality. Fixes #1190 Signed-off-by: Lee Hannigan <29015211+LeeroyHannigan@users.noreply.github.com>
tests/test_metrics_accounts.py and the new tests/test_metrics_refused_requests.py each had a copy of the same helpers. Those are the admin environment check, the /metrics read, the dimension lookup and the sorted rows for the settle comparison. Both also built a user with an access key, the full policy and a boto3 client. The new file also had a count helper that the per-account sum of the other file gives. The copies move to tests/metrics_helpers.py, with the other shared modules of tests/, and both files import them. new_user takes whether the user gets the full policy and whether its client checks parameters. So the refused request test gets its user with no policy, and its client that sends the TableName "bad name!", from the same function. new_account creates the account and its full user through new_user. Each moved function keeps its behaviour, and the test ids of both files are the same before and after. Signed-off-by: Lee Hannigan <29015211+LeeroyHannigan@users.noreply.github.com>
Main is at 14ade59 (#864). One file conflicted: docs/manuals/07-upgrade-manual.md. #398 and this branch each add a v1.1.0 entry at the top of "Behavior Changes by Release". The merge keeps both entries whole, the #398 entry first and this branch's entry after it. The other files that both sides change merged without a conflict: - crates/server/src/handler.rs: main moves the pre-auth request checks into extenddb_engine::parse_request and the point-in-time refusal into admit (#1009). record_segments drops its table argument and takes the segments by reference (#398). This branch changes only the error arm of the authorization step. That arm still records UserErrors and RequestCount with the two calls that the point-in-time refusal makes. - docs/design/06-component-server.md: #398's segments text and this branch's RequestCount and UserErrors paragraph are in separate places. #398 records segments only for a request that reaches dispatch, so a request refused in the authorization step adds counts and no segments.
demohan
left a comment
There was a problem hiding this comment.
A request refused in the authorization step now counts as the service counts it at 61ec619. On SQLite and PostgreSQL, the table name gate, an IAM AccessDeniedException, a cross-account ARN, a batch over its count limit, a bad shard iterator, a bad StreamArn and a tag ARN naming an index each record UserErrors and RequestCount under the caller's account and the operation, with no table name, latency, capacity or segment; main recorded nothing for any of them. A caller naming another account's table is counted under its own account only, a request that fails authentication or does not parse records nothing, and a throttled request still records only ThrottledRequests and ReadThrottleEvents. In us-east-1, twice, the account's UserErrors counted every AccessDeniedException from a resource policy, ValidationException and ResourceNotFoundException, and none for a bad signature, an unrecognized client, a bad session token, a missing signature or a signed malformed body, so these choices match the service. fmt, both clippy commands, the 1.91.1 check, 519 server tests and the 16 metrics tests on each backend are clean, and removing or doubling each metric call fails them. The branch merges with main at 222d80a, where the 1.94.0 check, 526 server tests and the metrics tests pass; the wasm failure is main's, fixed by #1482.
I will approve once the storage fault case has a test, and the upgrade entry moves past v1.1.0, which is tagged without this change.
| // request the engine refuses does. A storage fault of the key | ||
| // info lookup is a system error, and `record_error_metrics` | ||
| // tells the two apart. | ||
| record_error_metrics(&state.metrics, &e, &account_id, None, &operation); |
There was a problem hiding this comment.
No test holds the storage fault half of this: with record_error_metrics replaced by record_user_error here, the new test passes 3 of 3, so a fault of the key info lookup could count as a user error unnoticed, though the upgrade manual and the design doc state it. A test that forces that fault and expects SystemErrors 1, UserErrors 0 and RequestCount 1 would hold it.
There was a problem hiding this comment.
35702bf adds the test. The two calls of this arm moved into record_refused_request in response.rs, which the point-in-time recovery arm above calls too. a_refused_request_counts_a_storage_fault_as_a_system_error sends a ServiceUnavailable and an InternalServerError, the two errors that key_info_for_authz makes of a storage fault, and expects SystemErrors 1, UserErrors 0 and RequestCount 1. A ValidationException and an AccessDeniedException expect UserErrors 1 instead.
With record_error_metrics replaced by record_user_error in the helper, the test fails at the first row with (0, 1, 1) where (1, 0, 1) is expected.
|
|
||
| ### v1.1.0: a request refused in the authorization step counts in `UserErrors` and `RequestCount` | ||
|
|
||
| **What changed.** A request the server refuses in its authorization step, before the IAM decision or by it, now records `UserErrors` and `RequestCount` under the account and the operation, as a request the engine refuses does. The refusals in that step are a `TableName`, index name or ARN that breaks the naming rules, a batch or transaction outside its count limits, a malformed stream, backup, export or tag ARN, a shard iterator the server cannot read, a resource in another account, and the IAM denial itself (`AccessDeniedException`). 1.0.0 answered each of them with the same HTTP 400 and recorded no metric for it. A storage fault during the key lookup of that step records `SystemErrors` and `RequestCount`. The DynamoDB metrics documentation counts every request answered with an HTTP 400 in `UserErrors`. |
There was a problem hiding this comment.
v1.1.0 is tagged at 222d80a without this change, so after the merge this entry sits in the v1.1.0 group saying "1.0.0 recorded nothing"; it would move to the next release and say "1.1.0 and earlier". The last sentence, also in the body and the comment in handler.rs, is broader than the service: its metrics page leaves out throttling and failed conditions, and a request that fails authentication or does not parse is not counted in us-east-1, as above. Saying what was measured would hold.
There was a problem hiding this comment.
3d5c742 moves the entry to the v1.2.0 group at the top of "Behavior Changes by Release", after the v1.2.0 entries of main. It says "1.1.0 and earlier" recorded nothing, and a rollback goes to 1.1.0.
The sentence about the documentation is gone from the entry, and the comment in handler.rs no longer says how CloudWatch counts an HTTP 400 (35702bf). The Why section of the body gives your us-east-1 measurement in its place, and the documentation's two exceptions, throttled requests and failed conditions.
|
|
||
|
|
||
| @pytest.mark.parametrize("operation, user, expected_type", ROWS, ids=[row[0] for row in ROWS]) | ||
| def test_a_refused_request_counts_once_in_user_errors_and_request_count( |
There was a problem hiding this comment.
Optional. This covers 2 of the 8 refusals the upgrade entry lists, and no case checks that a cross-account refusal counts only under the caller or that a refusal before authentication records nothing; both behave so at this head.
There was a problem hiding this comment.
This file stays at its three rows. Every refusal of the authorization step returns through the one arm that this PR changes. The table name row and the IAM row hold that arm. At 7120180 they failed with either of its two calls removed. The arm records under account_id, the caller's account, the only account it has, so a cross-account refusal counts under the caller, as your run showed. A request that fails authentication returns before this arm, in code that this PR does not change.
record_refused_request in response.rs records a request refused before dispatch: its error, with no table name, and its request count. The authorization arm and the point-in-time recovery arm of handle_request call it in place of the same two calls. A unit test checks the counts. A ServiceUnavailable or an InternalServerError, the faults of the key info lookup, counts once in SystemErrors and RequestCount and never in UserErrors. A refusal counts in UserErrors. With record_error_metrics replaced by record_user_error in the helper, the fault rows fail. The comment of the authorization arm no longer says how CloudWatch counts an HTTP 400.
The v1.1.0 release of 27 Nov 2026 does not include this change. The entry moves to the v1.2.0 group at the top of Behavior Changes by Release, after the v1.2.0 entries of main. It names 1.1.0 as the release before the change. The entry no longer says that the DynamoDB metrics documentation counts every request answered with an HTTP 400 in UserErrors. That sentence said more than the documentation and the measurements hold. The list of refusals is now a bulleted list.
Main is at 44a7b79, six commits past c8e66fb: #1446, #1531, #1466, #1087, #768 and #1296. In docs/manuals/07-upgrade-manual.md, #1446 and #1531 add v1.2.0 entries at the top of "Behavior Changes by Release", and git merged them with no conflict. #1087 adds its v1.2.0 entry after the other v1.2.0 entries of main, where this branch has its entry. That is the one conflict. The merge keeps both entries without change: the entry of #1087 first, then the entry of this branch, before the v1.1.0 entries. No other file has changes on both sides.
Changes since the last review
docs/manuals/07-upgrade-manual.md, fix(storage-mongodb): keep a DELETING table's tags until its document goes #1446 and fix(storage-cassandra): retry a lost UpdateItem version check over the PutItem and DeleteItem window #1531 add v1.2.0 entries at the top of "Behavior Changes by Release", and git merged them with no conflict. fix(storage-sqlite): keep each partition key in one parallel Scan segment #1087 adds its v1.2.0 entry after the other v1.2.0 entries of main, where this PR has its entry. That is the one conflict. The merge keeps both entries without change: the entry of fix(storage-sqlite): keep each partition key in one parallel Scan segment #1087 first, then the entry of this PR, above the v1.1.0 entries. No other file has changes on both sides, and the lines that this PR changes against main are the same before and after the merge. fix(server): ignore a TableName sent to an operation without one #1296 makes the table name checks and the cross-account refusal skip the six operations that have no table member, such as DescribeLimits. The tests of this PR send none of those six operations. The gates on c6d6d3d:cargo +1.97.0 fmt --all -- --check: clean. The two clippy commands of.github/workflows/clippy.ymlwith-D warnings, on the whole workspace as CI runs them: clean.cargo +1.97.0 test -p extenddb-server --lib: 523 passed,a_refused_request_counts_a_storage_fault_as_a_system_erroramong them. The 5backup_storespool tests fail on the build host, as on main (storage-sqlite: the two write_lock_tests fail when an ancestor of the Cargo target directory is owned by another user #1414).cargo test -p extenddb-wasm-adapter, with itsparitycorpus test: 4 passed.cargo test -p extenddb-storage-postgres --test doc_version_literals: 3 passed.tests/test_metrics_refused_requests.pyandtests/test_metrics_accounts.pypass (16 on each).pytest --collect-onlycollects 7,350 tests intests/and 820 intests/python, with no error.crates/server/src/handler.rs, feat: SearchVectors inequality filters #1449 added the SearchVectors checks before authorization, which record their own metrics. The error arm of the authorization step is unchanged by the merge. Main has fix(core): read the latency segment clock through web_time #1482 now, so the WebAssembly workflow runs with that fix.record_refused_requestincrates/server/src/response.rsrecords a request refused before dispatch: its error throughrecord_error_metrics, with no table name, and its request count. The error arm of the authorization step and the point-in-time recovery arm call it in place of the same two calls. A unit test sends the two errors that a storage fault of the key info lookup becomes,ServiceUnavailableandInternalServerError, and expectsSystemErrors1,UserErrors0 andRequestCount1. AValidationExceptionand anAccessDeniedExceptionexpectUserErrors1. Withrecord_error_metricsreplaced byrecord_user_errorin the helper, the test fails at the first row. The comment of the arm no longer says how CloudWatch counts an HTTP 400.UserErrors, is gone. Why now gives what demohan measured.Before that:
docs/manuals/07-upgrade-manual.mdconflicted: fix(metrics): bound latency segment memory by summing into fixed time buckets #398 adds its own v1.1.0 entry at the top of "Behavior Changes by Release", where this PR adds one. The merge keeps both entries whole, the fix(metrics): bound latency segment memory by summing into fixed time buckets #398 entry first.crates/server/src/handler.rsanddocs/design/06-component-server.mdmerged without a conflict. fix(metrics): bound latency segment memory by summing into fixed time buckets #398 records latency segments only for a request that reaches dispatch, so a request refused in the authorization step adds no segments.What
authorize_request(crates/server/src/request_helpers.rs) refuses some requests before the IAM decision and some by it. Before it: a table name, index name or ARN that breaks the naming rules, and a batch or transaction outside its count limits. Also before it: a malformed stream, backup, export or tag ARN, a shard iterator the server cannot read, and a resource in another account. By it:AccessDeniedException. The handler's error arm for these refusals (crates/server/src/handler.rs) answered the HTTP 400 and recorded no metric. A request the engine refuses, and the point-in-time recovery refusal a few lines above, recordUserErrorsandRequestCount.The arm now calls
record_refused_request, which the point-in-time recovery refusal calls too. It records the error throughrecord_error_metricsand callsstate.metrics.record_request_count. It passes no table name:UserErrorscarries none, and the handler resolves the metric table name after this step.record_error_metricsrecords a storage fault of the key info lookup asSystemErrors, as it does for the same fault in dispatch. The authentication arms, where the handler knows no account yet, and the missing catalog store arm stay as they are.#544, merged on 25 Nov, runs the Query request-time checks in
authorize_request, ahead of the engine. The arm that this change fixes answers a Query that those checks refuse. So on this head such a Query records the two metrics. Four open PRs move more request checks there: #484 for Query, #562, #850 and #854 for Scan. A request those checks refuse records the two metrics once this change and that PR are both on main, in either order.Docs:
docs/design/06-component-server.mdsays which refusals recordUserErrorsandRequestCount, which record no metric, and what a throttled request records.docs/manuals/07-upgrade-manual.mdhas a v1.2.0 entry.Why
A request refused in the authorization step is a request the account sent and an HTTP 400 it got back. demohan measured the service in us-east-1, twice, for the review of 28 Nov 2026. The account's
UserErrorscounted everyAccessDeniedExceptionfrom a resource policy,ValidationExceptionandResourceNotFoundException. It counted none for a bad signature, an unrecognized client, a bad session token, a missing signature or a signed malformed body. The DynamoDB metrics documentation also leaves throttled requests and failed conditions out ofUserErrors. An operator who watchedUserErrorsfor a client that sends a refused request shape saw nothing, andRequestCountleft those requests out.Fixes #1190
Other open PRs
In
docs/manuals/07-upgrade-manual.md, the v1.2.0 entry of this PR sits after the v1.2.0 entries of main, above the v1.1.0 entries. On 4 December 2026,git merge-treecompared c6d6d3d and main with each of the 219 open PRs. 31 of them conflict with c6d6d3d in the manual, and 23 of those conflict with main there too. The other eight are #550, #562, #831, #1110, #1131, #1220, #1249 and #1260. The PR that merges second keeps both entries. Outside the manual, this PR conflicts with no open PR in a file where that PR merges with main without a conflict.Testing done
Measured on 2026-11-24 against a SQLite server built from main (44cd436) and one built from this change. One account sent three rows of five requests. GetItem with the
TableNamebad name!, refused by the table name gate. Query from a user with no policy, refused by the IAM decision. PutItem to a table that does not exist, refused by the engine, as the control./metrics, read after the flush:UserErrorsorRequestCountrowUserErrors5,RequestCount5UserErrorsorRequestCountrowUserErrors5,RequestCount5UserErrors5,RequestCount5UserErrors5,RequestCount5tests/test_metrics_refused_requests.py(new, 197 lines) sends those three rows from its own account and asserts both counts by equality for each. It passed 3 of 3 against this change and failed 2 of 3 against main ({'UserErrors': 0, 'RequestCount': 0}for GetItem and Query). At 7120180, with therecord_error_metricscall removed, it failed the same two rows with{'UserErrors': 0, 'RequestCount': 5}, and with therecord_request_countcall removed with{'UserErrors': 5, 'RequestCount': 0}. It is aslowwire file like the two metrics files beside it, and runs in the pytest suite of every backend workflow.Its helpers moved from
tests/test_metrics_accounts.pyintotests/metrics_helpers.py(new, 139 lines), which both import.new_usertakes two flags, the full policy and client-side parameter checking. The accounts file keeps its 13 test ids.At 3d5c742:
tests/test_metrics_refused_requests.pyandtests/test_metrics_accounts.pypass (16).cargo +1.97.0 test -p extenddb-server --lib: 522 passed. The 5backup_storespool tests fail on the build host, on main and on this change alike. Their temp directory sits under a directory another user owns.a_refused_request_counts_a_storage_fault_as_a_system_erroris among the 522.cargo +1.97.0 fmt --all -- --check: clean. The two clippy commands of.github/workflows/clippy.ymlwith-D warningsandcargo +1.94.0 check --all-targetsare clean onextenddb-server. The first clippy command turns ontest-hooksin the Cassandra and MongoDB crates. Cargo refuses that when those two crates are not selected, so the command ran without it..github/workflows/wasm.ymlis clean. This host has no clang, so the run used a stand-in C compiler and archiver. Clippy does not link.cargo test -p extenddb-wasm-adapter --lib --test parity: 4 passed.cargo test -p extenddb-storage-postgres --test doc_version_literals: 3 passed.pytest --collect-onlycollects 7,307 tests intests/and 820 intests/python, with no error.Checklist
cargo test --workspace)cargo fmt --check)cargo clippy -- -W clippy::pedantic)Storagetrait, auth model, on-diskformat, or public CLI surface, an RFC has been accepted or is linked
below. Otherwise, an ADR captures the decision (link below).
ADR / RFC: n/a
Breaking changes
An operator who reads
UserErrorsorRequestCountfrom/metricsor the console sees requests refused in the authorization step counted from this release. 1.1.0 and earlier recorded nothing for them, so a client that sends a refused request shape in a loop raisesUserErrorswhere 1.1.0 showed no change. No catalog migration, and a rollback to 1.1.0 brings back the old counts.By submitting this pull request, I confirm that my contribution is made under
the terms of the Apache License 2.0 and I agree to the Developer Certificate of
Origin (DCO). See CONTRIBUTING.md for details.