Repository navigation
fix(authz): authorize SearchVectors against the vector index ARN - #999
Conversation
The DynamoDB developer guide documents table/<T>/index/<I> as the resource for dynamodb:SearchVectors: a search is authorized against the vector index it reads, as Query and Scan with an IndexName are. This match comes from the developer guide. It has not been measured against the live service. ExtendDB sent SearchVectors through the generic single-table path, which authorized the table ARN. A Deny on table/<T>/index/<I>, or on table/<T>/index/*, never matched, and the search ran. SearchVectors now takes the Query and Scan index path in authz_targets: the policy match uses the canonical index ARN, the denial names the TableName as written with the index appended when TableName is a table ARN, and resource tags are read from the base table. An IndexName that is not one index segment is authorized as written, so a Deny on table/<T>/index/* refuses it, and no vector index can carry such a name, so the engine finds no index to search. This changes policy behavior in two ways. Existing policies that allow SearchVectors only on table/<T> stop permitting it and now need table/<T>/index/<I> or table/<T>/index/*. A Deny written only on table/<T> no longer blocks SearchVectors; fencing a table needs table/<T>/* as well. The admin guide lists the new resource and both effects. Verified with Rust unit tests on the derived targets, including adversarial IndexName values, and wire tests against a running server: a principal with dynamodb:* plus a Deny on the vector index, on the index wildcard, on the bare table ARN, or on another index; and an Allow on only the bare table ARN (refused) or on the table's indexes (permitted). The wire tests check the refusal by error type.
LeeroyHannigan
left a comment
There was a problem hiding this comment.
I built this branch, ran the SearchVectors authorization tests on SQLite and PostgreSQL with vector indexes enabled, ran the IndexName and policy cases as probes on both, and checked the change against the admin guide, the upgrade manual and the other open PRs.
What I ran
- The 3 unit tests and the 7 wire tests in
tests/test_authz_search_vectors_index.pypass on SQLite and on PostgreSQL withEXTENDDB_EXPECT_VECTORS=1. Reverting the one-line change fails 5 of the 7 wire tests and 2 unit tests, so the tests catch the fix. fmt, clippy 1.97 with-D warnings, and the 1.88 build are clean, and CI is 58 of 58. - The derived resource for a SearchVectors with an IndexName is
table/<T>/index/<IndexName>, and the resource tags resolve to the base table. Both hold on a run, on both backends.
Before merge
- A SearchVectors
IndexNameoutside[a-zA-Z0-9_.-]+reaches the IAM decision, while Query and Scan refuse it first.crates/server/src/table_name_gate.rschecks the IndexName pattern for Query and Scan ahead of the policy decision, because the service answers a member-pattern failure before the IAM decision (the change in #830). SearchVectors is not in that arm, so with this PR a caller with a Deny ontable/T/index/*, or one allowed onlytable/T, gets AccessDeniedException for an IndexName likevidx/extra, where Query gets the pattern ValidationException atindexNameand main returned a ValidationException. The SearchVectors API reference gives its IndexName the same pattern and length as Query. I could not call SearchVectors against the live service from here, so the error order the service uses for SearchVectors is unmeasured: if the service answers the pattern failure first, this is a client-visible change the PR introduces; if it answers AccessDeniedException, it is an inconsistency with Query and Scan on our own server. Routing SearchVectors through the same gate arm is the safe fix either way, and the slash test should then expect that ValidationException for both callers. As written,test_index_name_with_a_slash_is_authorized_as_writtenasserts the AccessDeniedException and cements the divergence. The inline comment onauthz_resource.rshas the measured responses.
Minor
crates/server/src/authz_resource.rs:765: the arm comment says a SearchVectors request names a vector index, but the arm authorizes the table when IndexName is missing or empty, which the second unit test asserts and a run confirms.docs/manuals/05-admin-guide.md:750: the resource-tags bullet names only Query and Scan; SearchVectors reads the base table's tags too, confirmed by an ABAC run on both backends. The "follows the DynamoDB developer guide" sentence at 736 now also covers Query and Scan, which were measured against the service; only the SearchVectors resource rests on the developer guide. The upgrade manual's "Index reads need an index grant" item (docs/manuals/07-upgrade-manual.md:794) names only Query and Scan and gains no entry for the SearchVectors change, so a table-only Allow loses SearchVectors at upgrade with nothing in the behaviour-change list.- The 7 wire cases are one function per policy row; one parametrized table over (effect, resource, status, error type) would be shorter (code-size rule 4), and
_expect_vectorsis copied fromtests/test_search_vectors_condition_limit.py.
Checked and matched the documentation
- The resource
table/<T>/index/<I>fordynamodb:SearchVectorsmatches the AWS developer guide and the IAM policy example page. SearchVectors reuses the Query and Scan authorization path, with no second copy. An adversarial IndexName (a slash,%2f, NUL, a trailing space) named no real index on either backend and never returned 200. The change shares no file with #998 or #1000.
| // names that ARN with the index appended; any other ARN in TableName | ||
| // (an index ARN, a malformed resource) names the canonical index ARN, | ||
| // so the denial never names a resource the caller did not write. | ||
| "Query" | "Scan" | "SearchVectors" => { |
There was a problem hiding this comment.
Query and Scan refuse an IndexName outside [a-zA-Z0-9_.-]+ in table_name_gate.rs before the IAM decision (the change in #830). SearchVectors is not in that arm, so with this change an IndexName like vidx/extra goes into the resource as sent and a caller with a Deny on table/T/index/*, or one allowed only table/T, gets AccessDeniedException. On a run (both backends) Query answered ValidationException ... at 'indexName' ... pattern: [a-zA-Z0-9_.-]+ for the same value, and main returned a ValidationException here. The SearchVectors API reference gives IndexName the same pattern and length. I could not call SearchVectors against the live service to settle which error it returns first, so this is at least an inconsistency with Query and Scan on our server, and a client-visible change if the service answers the pattern failure first. Adding SearchVectors to the "Query" | "Scan" arm of the gate reuses the pattern check, and the slash test would then expect the ValidationException for both the denied and the allowed caller.
There was a problem hiding this comment.
Fixed in c6a2700. SearchVectors now takes the "Query" | "Scan" arm in table_name_gate.rs, so vidx/extra gets the pattern ValidationException at indexName before the IAM decision, for every caller. Like Query, the gate checks the pattern only, because the length rules for an index name are unmeasured.
Evidence, with EXTENDDB_EXPECT_VECTORS=1: the three authz wire files pass on SQLite and PostgreSQL (78 each). The slash test, renamed test_index_name_outside_the_pattern_is_refused_before_authorization, now expects ValidationException for both the allow-all caller and the caller with a Deny on table/T/index/*. A unit test compares SearchVectors with Query for vidx/extra, NUL, a space and %2f. With the gate change reverted, the Deny-on-index-wildcard case fails (1 failed, 9 passed). The allow-all case passes either way, because the engine already answers ValidationException.
I did not call SearchVectors on the live service, so which error it returns first is still unmeasured. This change makes ExtendDB consistent with Query and Scan, and matches main's ValidationException for a bad name.
Query and Scan refuse an IndexName outside [a-zA-Z0-9_.-]+ with a ValidationException at indexName before the policy decision, because the service answers a member-pattern failure before the IAM decision. SearchVectors was not in that check, so an IndexName such as vidx/extra reached the policy: a caller with a Deny on table/<T>/index/*, or one allowed only table/<T>, got AccessDeniedException where Query answers ValidationException. Whether the service orders the errors the same way for SearchVectors has not been measured; the SearchVectors API reference gives IndexName the same pattern as Query. SearchVectors now takes the Query and Scan arm of the name gate, so every caller gets the same ValidationException. The gate checks the pattern only, as it does for Query: the length rules for an index name are unmeasured. Also correct the arm comment in authz_resource.rs (a request with no IndexName authorizes the table), state in the admin guide that only the SearchVectors resource rests on the developer guide, name SearchVectors in the resource-tags bullet, and add the SearchVectors change to the upgrade manual: a table-only Allow loses SearchVectors, and a table-only Deny no longer blocks it. The wire tests are one parametrized table over (effect, resource, status, error type) plus the IndexName cases, and reuse _expect_vectors. A unit test covers the gate for SearchVectors. Wire tests assert the error type, not the message.
|
Pushed c6a2700 and dfb32f3 on top of 145a4a2, no force-push. The minor items:
The PR description lists the pattern check and the unmeasured error order. |
…nial A SearchVectors request that names a table in another account is refused either way, but the denial named table/<T> where Query and Scan name table/<T>/index/<I>. The cross-account check read the resource for Query and Scan only, so SearchVectors fell through to the table. SearchVectors now takes the Query and Scan arm of the cross-account check, so the denial names the vector index ARN, as the policy check already does. A request with no IndexName still names the table. The service has no SearchVectors answer to measure; it keeps the DescribeTable answers and only the resource named changes. Verified with a unit test on the resource found for a SearchVectors request and the denial message it produces.
eliseong
left a comment
There was a problem hiding this comment.
@navareamol Thanks for this. The core change is right. SearchVectors now authorizes against the vector index resource, so a Deny on table/<T>/index/<I> or table/<T>/index/* is enforced, and a table-only Deny no longer blocks the search. I confirmed a Deny on the index resource refuses the search where the base branch allowed it, that an Allow on only the table no longer permits it, and that no crafted IndexName or TableName ARN gets past a Deny on the index wildcard. SearchVectors now matches Query and Scan for allow, deny, and malformed index names.
I will approve once the cross-account path names the index resource too. In crates/server/src/authz_resource/cross_account.rs a SearchVectors request still falls through to the table resource, so a cross-account denial names table/<T> rather than table/<T>/index/<I>. The request is refused either way, but the resource in the message should match Query and Scan. Adding SearchVectors to the Query and Scan arm there is the change.
One item is out of scope for this PR and tracked in #1014: an index name shorter than 3 or longer than 255 is not refused before authorization, and that applies to Query and Scan as well.
|
@eliseong Fixed in cc43a0b. SearchVectors is now in the A unit test, The service has no SearchVectors answer I could measure, so SearchVectors keeps the DescribeTable answers and only the named resource changes. The PR description has the new line. @LeeroyHannigan the earlier points from your review are in dfb32f3 and c6a2700. Could you re-review? |
LeeroyHannigan
left a comment
There was a problem hiding this comment.
I re-reviewed at cc43a0b, built the branch, and ran the unit and wire tests. The round-1 items are resolved.
Verified
- The gate: a SearchVectors
IndexNameoutside[a-zA-Z0-9_.-]+is now refused before the IAM decision, as Query and Scan are.table_name_gate.rsadds SearchVectors to that arm, and the new unit test checks thatvidx/extra, a NUL, a space and%2fget the pattern ValidationException for SearchVectors and for Query alike. On a PostgreSQL server with vector indexes,vidx/extrareturns ValidationException both for an allow-all caller and for a caller with a Deny on the index wildcard, so the error no longer depends on the policy. - The cross-account denial now names
table/<T>/index/<I>for SearchVectors, with a unit test; a request with no IndexName names the table. - The arm comment no longer says SearchVectors always names an index. The admin guide's resource-tags and index-grant bullets name SearchVectors, the "follows the DynamoDB developer guide" sentence is scoped to the SearchVectors resource, and the upgrade manual lists the table-only Allow and Deny change. The wire cases are one parametrized table over the policy rows, and
_expect_vectorsis imported rather than copied.
Runs
- Server unit tests for the gate, authz, cross-account and search paths: 27 pass, including
search_vectors_index_name_outside_the_pattern_is_refused_as_query_isanda_cross_account_search_vectors_names_the_index_arn. - Authz wire tests on PostgreSQL with
EXTENDDB_EXPECT_VECTORS=1: 10 pass. CI is 58 of 58.
Notes, not blocking
- An IndexName shorter than 3 or longer than 255 is still not refused before authorization, for Query and Scan as well, which #1014 tracks.
- The admin guide and upgrade manual edits touch files other open documentation PRs also edit, so a trivial rebase may be needed depending on merge order.
docs/manuals/05-admin-guide.md keeps the bulk operations and resource tags entry from this branch. The entries around it take the SearchVectors index ARN text from main (#999).
What this changes
SearchVectorswas authorized against the table ARN. The DynamoDB developer guide documentstable/<T>/index/<I>as the resource fordynamodb:SearchVectors, the same asQueryandScanwith anIndexName. So a Deny on the vector index (table/<T>/index/<I>ortable/<T>/index/*) never matched, and the search ran.SearchVectorsnow takes the same index path asQueryandScaninauthz_targets.Workflow
Policy behavior that changes
This is a behavior change. Please read it before approving.
table/T/index/Iortable/T/index/*table/Ttable/T/index/Iortable/T/index/*.table/Ttable/T/*too.*The admin guide lists the new resource and both effects.
Use cases handled
table/T/index/*: every vector index of the table is refused.IndexName: authorized against the table, as before.IndexNameoutside[a-zA-Z0-9_.-]+(extra slashes, spaces,%2f, NUL): refused with the same patternValidationExceptionas Query and Scan, before the permission check. SearchVectors is now in the"Query" | "Scan"arm oftable_name_gate.rs. Without that, a denied caller would getAccessDeniedExceptionwhere main gave aValidationException. Like Query, the gate checks the pattern only; the length rules for an index name are not measured.TableNamegiven as a full table ARN: the denial names the ARN with the index appended.Failure cases and limits
table/Tfor SearchVectors. If the service does apply a table-only Deny, this PR loosens that Deny. Please say here if anyone can measure it.table/<T>/index/<I>in the denial, as Query and Scan do. The refusal itself is unchanged. A request with noIndexName, or an empty one, still names the table.Testing
IndexNamevalues (3 tests insearch_vectors_tests.rs).tests/test_authz_search_vectors_index.pyagainst a running server: Deny on the index, on the wildcard, on the bare table ARN, on another index; Allow on only the bare table ARN (refused); Allow on the table's indexes (permitted). They check the error type, not the message. 75 pass on SQLite and 75 on PostgreSQL across the three authz test files.authz_resource.rsrestored to the base, 5 vector tests fail, including both table-ARN tests.cargo fmt --check, clippy 1.97 with-D warnings, build on 1.88: clean. 507 server unit tests pass.Docs
docs/manuals/05-admin-guide.md: the resource for SearchVectors, the "Fencing a whole table with a Deny" bullet, the resource-tags bullet, and the "Index reads" bullet.docs/manuals/07-upgrade-manual.md: three behavior-change items now name SearchVectors, so a table-only Allow losing SearchVectors at upgrade is listed.