Skip to content

fix(server): count a request refused in the authorization step in UserErrors and RequestCount - #1427

Open
LeeroyHannigan wants to merge 7 commits into
mainfrom
fix/1190-authorization-refusal-metrics
Open

LeeroyHannigan wants to merge 7 commits into
mainfrom
fix/1190-authorization-refusal-metrics

Conversation

@LeeroyHannigan

@LeeroyHannigan LeeroyHannigan commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Changes since the last review

Before that:

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, record UserErrors and RequestCount.

The arm now calls record_refused_request, which the point-in-time recovery refusal calls too. It records the error through record_error_metrics and calls state.metrics.record_request_count. 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, 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.md says which refusals record UserErrors and RequestCount, which record no metric, and what a throttled request records. docs/manuals/07-upgrade-manual.md has 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 UserErrors counted every AccessDeniedException from a resource policy, ValidationException and ResourceNotFoundException. 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 of UserErrors. An operator who watched UserErrors for a client that sends a refused request shape saw nothing, and RequestCount left 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-tree compared 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 TableName bad 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:

Refused by main this change
the table name gate (GetItem) no UserErrors or RequestCount row UserErrors 5, RequestCount 5
the IAM decision (Query) no UserErrors or RequestCount row UserErrors 5, RequestCount 5
the engine (PutItem) UserErrors 5, RequestCount 5 UserErrors 5, RequestCount 5

tests/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 the record_error_metrics call removed, it failed the same two rows with {'UserErrors': 0, 'RequestCount': 5}, and with the record_request_count call removed with {'UserErrors': 5, 'RequestCount': 0}. It is a slow wire 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.py into tests/metrics_helpers.py (new, 139 lines), which both import. new_user takes two flags, the full policy and client-side parameter checking. The accounts file keeps its 13 test ids.

At 3d5c742:

  • Against a SQLite server built from 3d5c742, tests/test_metrics_refused_requests.py and tests/test_metrics_accounts.py pass (16).
  • cargo +1.97.0 test -p extenddb-server --lib: 522 passed. The 5 backup_store spool 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_error is among the 522.
  • cargo +1.97.0 fmt --all -- --check: clean. The two clippy commands of .github/workflows/clippy.yml with -D warnings and cargo +1.94.0 check --all-targets are clean on extenddb-server. The first clippy command turns on test-hooks in the Cassandra and MongoDB crates. Cargo refuses that when those two crates are not selected, so the command ran without it.
  • The clippy step of .github/workflows/wasm.yml is 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-only collects 7,307 tests in tests/ and 820 in tests/python, with no error.

Checklist

  • I have read CONTRIBUTING.md
  • All tests pass (cargo test --workspace)
  • Code is formatted (cargo fmt --check)
  • Clippy is clean (cargo clippy -- -W clippy::pedantic)
  • I have added or updated tests for new functionality
  • I have updated documentation if behavior changed
  • Breaking changes are noted below (if any)
  • If this changes the wire protocol, Storage trait, auth model, on-disk
    format, 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 UserErrors or RequestCount from /metrics or 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 raises UserErrors where 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.

…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 demohan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread crates/server/src/handler.rs Outdated
// 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);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread docs/manuals/07-upgrade-manual.md Outdated

### 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`.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@LeeroyHannigan

Copy link
Copy Markdown
Collaborator Author

@demohan The storage fault test and the upgrade entry are in the threads on handler.rs and the upgrade manual. dd6d40d merges main at c8e66fb, which has #1482, so the wasm job runs with that fix.

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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A request refused in the authorization step records no UserErrors or RequestCount in /metrics

2 participants