From 145a4a2fc997016dbabe6e431a3255ba2958547b Mon Sep 17 00:00:00 2001 From: Amol Navare Date: Sat, 14 Nov 2026 11:40:15 -0800 Subject: [PATCH 1/4] fix(authz): authorize SearchVectors against the vector index ARN The DynamoDB developer guide documents table//index/ 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//index/, or on table//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//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/ stop permitting it and now need table//index/ or table//index/*. A Deny written only on table/ no longer blocks SearchVectors; fencing a table needs table//* 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. --- crates/server/src/authz_resource.rs | 19 +- .../authz_resource/search_vectors_tests.rs | 72 +++++ docs/manuals/05-admin-guide.md | 23 +- tests/test_authz_search_vectors_index.py | 279 ++++++++++++++++++ 4 files changed, 377 insertions(+), 16 deletions(-) create mode 100644 crates/server/src/authz_resource/search_vectors_tests.rs create mode 100644 tests/test_authz_search_vectors_index.py diff --git a/crates/server/src/authz_resource.rs b/crates/server/src/authz_resource.rs index 7b1d4c95c..437713199 100644 --- a/crates/server/src/authz_resource.rs +++ b/crates/server/src/authz_resource.rs @@ -26,6 +26,7 @@ //! | `ExportTableToPointInTime` | same | the `TableArn` | //! | `ImportTable` | same | the new table ARN | //! | `Query`/`Scan` (with `IndexName`) | same | `table//index/` | +//! | `SearchVectors` | same | `table//index/` | //! | `ListTables` | `ListTables` | `table/*` | //! | item/table ops | same | the table ARN (from `TableName`, name or ARN) | //! @@ -760,12 +761,14 @@ pub(crate) fn authz_targets( v.extend(restore); v } - // Query and Scan on an index authorize the index ARN. With a table ARN - // in TableName the denial 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" => { + // Query and Scan on an index, and SearchVectors, authorize the index + // ARN. SearchVectors always names a vector index, and the service + // documents `table//index/` as the resource for + // dynamodb:SearchVectors. With a table ARN in TableName the denial + // 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" => { let base = table_resource_arn(&table_name, region, account_id); match str_field(input, "IndexName") { Some(idx) if !idx.is_empty() => { @@ -1543,3 +1546,7 @@ mod supplied_resource_tests; /// A point-in-time restore authorizes its target before its source (issue #446). #[cfg(test)] mod restore_order_tests; + +/// SearchVectors authorizes the vector index it searches. +#[cfg(test)] +mod search_vectors_tests; diff --git a/crates/server/src/authz_resource/search_vectors_tests.rs b/crates/server/src/authz_resource/search_vectors_tests.rs new file mode 100644 index 000000000..b62db494d --- /dev/null +++ b/crates/server/src/authz_resource/search_vectors_tests.rs @@ -0,0 +1,72 @@ +// Copyright 2026 ExtendDB contributors +// SPDX-License-Identifier: Apache-2.0 + +//! SearchVectors authorizes the vector index it searches, as Query and Scan on +//! an index do. + +use super::{AuthzTarget, authz_targets, resource_tag_lookup_arn}; +use extenddb_core::validation::validate_index_name; +use serde_json::json; + +const R: &str = "us-east-1"; +const A: &str = "444455556666"; +const TABLE: &str = "arn:aws:dynamodb:us-east-1:444455556666:table/bb"; + +fn single(input: serde_json::Value) -> AuthzTarget { + let mut t = authz_targets("SearchVectors", &input, R, A); + assert_eq!(t.len(), 1, "{t:?}"); + assert_eq!(t[0].action, "SearchVectors"); + t.remove(0) +} + +#[test] +fn search_vectors_authorizes_the_index_arn() { + let index = format!("{TABLE}/index/vidx"); + let t = single(json!({ "TableName": "bb", "IndexName": "vidx" })); + assert_eq!(t.resource, index); + assert_eq!(t.supplied, index); + assert_eq!(t.policy_resource(), index); + // The index inherits the table's tags, as a secondary index does. + assert_eq!(resource_tag_lookup_arn(&t.resource).as_deref(), Some(TABLE)); + + // A table ARN in TableName: the policy match is canonical and the denial + // names the ARN as written with the index appended, as for Query. + let respelled = "arn:aws-cn:dynamodb:us-west-2:444455556666:table/bb"; + let t = single(json!({ "TableName": respelled, "IndexName": "vidx" })); + assert_eq!(t.resource, index); + assert_eq!(t.supplied, format!("{respelled}/index/vidx")); +} + +/// An empty or missing IndexName authorizes the table, as Query and Scan do; +/// the engine refuses it before it reads the table. +#[test] +fn search_vectors_without_an_index_name_authorizes_the_table() { + assert_eq!(single(json!({ "TableName": "bb" })).resource, TABLE); + assert_eq!( + single(json!({ "TableName": "bb", "IndexName": "" })).resource, + TABLE + ); +} + +/// An IndexName that does not read as one index segment is authorized as +/// written: a Deny on `table//index/*` still matches it. Such a name reads +/// no resource tags, and no vector index can carry it, so the engine answers +/// that the table has no such index and reads no item. +#[test] +fn search_vectors_adversarial_index_names_name_no_real_index() { + let long = "a".repeat(300); + for name in [ + "vidx/extra", + "vidx/index/other", + "arn:aws:dynamodb:us-east-1:444455556666:table/other", + long.as_str(), + ] { + let t = single(json!({ "TableName": "bb", "IndexName": name })); + assert_eq!(t.resource, format!("{TABLE}/index/{name}"), "{name}"); + assert!(validate_index_name(name).is_err(), "{name}"); + } + for name in ["vidx/extra", "vidx/index/other"] { + let t = single(json!({ "TableName": "bb", "IndexName": name })); + assert_eq!(resource_tag_lookup_arn(&t.resource), None, "{name}"); + } +} diff --git a/docs/manuals/05-admin-guide.md b/docs/manuals/05-admin-guide.md index fe5f402b7..32b9f7566 100755 --- a/docs/manuals/05-admin-guide.md +++ b/docs/manuals/05-admin-guide.md @@ -707,6 +707,7 @@ DynamoDB. The `Resource` element of a policy is matched field by field, and a |-----------|-------------------------| | Item and table operations (GetItem, PutItem, Query and Scan on the base table, CreateTable, UpdateTable, DescribeTable, and so on) | `table/` | | Query and Scan with an `IndexName` | `table//index/` | +| SearchVectors | `table//index/` (the vector index searched) | | TagResource, UntagResource, ListTagsOfResource | the `ResourceArn` (a table or stream ARN) | | DescribeStream, GetShardIterator | the `StreamArn` | | GetRecords | the stream the shard iterator reads | @@ -732,16 +733,18 @@ Earlier builds authorized several of these operations against `table/*` instead of the specific resource. Review existing policies before upgrading: -- **Index reads.** Query and Scan with an `IndexName` are authorized against - `table//index/`. A policy that granted a principal only - `table/` no longer allows reads of that table's indexes. Grant - `table//index/` or `table//index/*` as needed. This - matches DynamoDB. -- **Fencing a whole table with a Deny.** Index reads, `ListStreams` with a - TableName, and `ListBackups` with a TableName are authorized against a - sub-resource ARN (`table//index/*`, `table//stream/*`, - `table//backup/*`), not the bare `table/`. A `Deny` written only - on `table/` therefore does not cover them. An operator who means to +- **Index reads.** Query and Scan with an `IndexName`, and SearchVectors, are + authorized against `table//index/`. A policy that granted a + principal only `table/` no longer allows reads or searches of that + table's indexes. Grant `table//index/` or + `table//index/*` as needed. This follows the DynamoDB developer guide. +- **Fencing a whole table with a Deny.** Index reads, `SearchVectors`, + `ListStreams` with a TableName, and `ListBackups` with a TableName are + authorized against a sub-resource ARN (`table//index/*`, + `table//stream/*`, `table//backup/*`), not the bare + `table/`. A `Deny` written only on `table/` therefore does not + cover them, and `SearchVectors` needs the index ARN + (`table//index/`) in the `Allow` as well. An operator who means to fence a whole table adds `table//*` to the `Deny` alongside `table/`. - **Index reads and resource tags.** An index Query or Scan evaluates the base diff --git a/tests/test_authz_search_vectors_index.py b/tests/test_authz_search_vectors_index.py new file mode 100644 index 000000000..23b4f5f7e --- /dev/null +++ b/tests/test_authz_search_vectors_index.py @@ -0,0 +1,279 @@ +# Copyright 2026 ExtendDB contributors +# SPDX-License-Identifier: Apache-2.0 + +"""SearchVectors is authorized against the vector index it searches. + +The service documents ``arn:aws:dynamodb:::table//index/`` +as the resource for ``dynamodb:SearchVectors``. ExtendDB authorized every +SearchVectors request against the table ARN, so a Deny on one vector index +never matched and the search ran. Each case below gives a principal +``dynamodb:*`` on ``*`` plus one Deny, and checks the refusal and its error +type against a running server. + +An IndexName that is not one index segment (``vidx/extra``) is authorized as +written, so a Deny on ``table//index/*`` refuses it; a caller allowed to +search gets ValidationException from the engine, because no vector index can +carry such a name. + +The principals are builtin-IAM users provisioned through the management API. +The module skips when the backend does not support vector indexes, unless +``EXTENDDB_EXPECT_VECTORS=1``, which makes that a failure. + +Prerequisites: + - extenddb running with ``auth.provider = "builtin"`` on EXTENDDB_TEST_ENDPOINT + - Admin credentials in EXTENDDB_ADMIN_USER / EXTENDDB_ADMIN_PASSWORD + +REQ-TEST-001, REQ-AUTH-002 +""" + +from __future__ import annotations + +import json +import os +import time +import uuid + +import pytest +import requests +from botocore.auth import SigV4Auth +from botocore.awsrequest import AWSRequest +from botocore.credentials import Credentials + +from management_helpers import ManagementClient + +REGION = os.environ.get("AWS_DEFAULT_REGION", "us-east-1") +VECTOR = [{"N": "0.1"}, {"N": "0.2"}, {"N": "0.3"}, {"N": "0.4"}] + +ALLOW_ALL = { + "Version": "2012-10-17", + "Statement": [{"Effect": "Allow", "Action": "dynamodb:*", "Resource": "*"}], +} + + +def _allow_all_deny(resource: str) -> dict: + return { + "Version": "2012-10-17", + "Statement": [ + {"Effect": "Allow", "Action": "dynamodb:*", "Resource": "*"}, + {"Effect": "Deny", "Action": "dynamodb:SearchVectors", "Resource": resource}, + ], + } + + +def _require_auth_env() -> tuple[str, str, str]: + endpoint = os.environ.get("EXTENDDB_TEST_ENDPOINT", "").strip() + admin_user = os.environ.get("EXTENDDB_ADMIN_USER", "").strip() + admin_pass = os.environ.get("EXTENDDB_ADMIN_PASSWORD", "").strip() + if not endpoint or not admin_user or not admin_pass: + pytest.fail( + "MISCONFIGURED: SearchVectors authz tests require EXTENDDB_TEST_ENDPOINT, " + "EXTENDDB_ADMIN_USER, and EXTENDDB_ADMIN_PASSWORD. " + "These must be set by devtools/run-tests before test execution." + ) + return endpoint, admin_user, admin_pass + + +def _expect_vectors() -> bool | None: + """``EXTENDDB_EXPECT_VECTORS``: 1 requires vector support, 0 forbids it.""" + value = os.environ.get("EXTENDDB_EXPECT_VECTORS") + if value is None: + return None + if value not in ("0", "1"): + pytest.fail(f"EXTENDDB_EXPECT_VECTORS must be 0 or 1, got {value!r}") + return value == "1" + + +class Principal: + """A builtin-IAM user that posts SigV4-signed DynamoDB JSON requests.""" + + def __init__(self, endpoint: str, ak: str, sk: str) -> None: + self.endpoint = endpoint + self.creds = Credentials(ak, sk) + + def post(self, operation: str, body: dict) -> requests.Response: + data = json.dumps(body).encode("utf-8") + req = AWSRequest( + method="POST", + url=self.endpoint, + data=data, + headers={ + "X-Amz-Target": f"DynamoDB_20120810.{operation}", + "Content-Type": "application/x-amz-json-1.0", + }, + ) + SigV4Auth(self.creds, "dynamodb", REGION).add_auth(req) + return requests.post( + self.endpoint, + data=data, + headers=dict(req.headers), + verify=not self.endpoint.startswith("https://"), + timeout=30, + ) + + +def _error_type(resp: requests.Response) -> str: + return resp.json().get("__type", "").rsplit("#", 1)[-1] + + +@pytest.fixture(scope="module") +def mgmt() -> ManagementClient: + endpoint, admin_user, admin_pass = _require_auth_env() + return ManagementClient(endpoint, admin_user, admin_pass) + + +@pytest.fixture(scope="module") +def account_id(mgmt): + acct = f"{uuid.uuid4().int % 10**12:012d}" + resp = mgmt.create_account(acct, f"svauthz-{acct}") + assert resp.status_code == 201, resp.text + yield acct + mgmt.delete_account(acct) + + +@pytest.fixture(scope="module") +def principal(mgmt, account_id): + """Return a factory: policy -> Principal holding a fresh user's keys.""" + endpoint = _require_auth_env()[0] + + def make(policy: dict) -> Principal: + user = f"u{uuid.uuid4().hex[:10]}" + assert mgmt.create_user(account_id, user, "TestPass123!").status_code == 201 + assert mgmt.put_user_policy(account_id, user, "p", policy).status_code == 204 + resp = mgmt.create_access_key(account_id, user) + assert resp.status_code == 201, resp.text + keys = resp.json() + return Principal(endpoint, keys["access_key_id"], keys["secret_access_key"]) + + return make + + +@pytest.fixture(scope="module") +def vector_table(principal): + """A table with one item and an ACTIVE vector index ``vidx``.""" + expected = _expect_vectors() + admin = principal(ALLOW_ALL) + name = f"sv{uuid.uuid4().hex[:10]}" + resp = admin.post( + "CreateTable", + { + "TableName": name, + "AttributeDefinitions": [{"AttributeName": "pk", "AttributeType": "S"}], + "KeySchema": [{"AttributeName": "pk", "KeyType": "HASH"}], + "BillingMode": "PAY_PER_REQUEST", + "VectorIndexes": [ + { + "IndexName": "vidx", + "Dimensions": 4, + "DistanceFunction": "COSINE", + "VectorAttribute": {"AttributeName": "emb"}, + "Projection": {"ProjectionType": "ALL"}, + } + ], + }, + ) + body = resp.json() if resp.status_code == 400 else {} + if "not supported" in body.get("message", body.get("Message", "")): + if expected is True: + pytest.fail("EXTENDDB_EXPECT_VECTORS=1 but the backend refuses vector indexes") + pytest.skip("target backend does not support vector indexes") + assert resp.status_code == 200, resp.text + try: + deadline = time.monotonic() + 60 + while True: + table = admin.post("DescribeTable", {"TableName": name}).json()["Table"] + if table["TableStatus"] == "ACTIVE" and all( + vi.get("IndexStatus") == "ACTIVE" for vi in table.get("VectorIndexes", []) + ) and table.get("VectorIndexes"): + break + assert time.monotonic() < deadline, f"{name} did not become ACTIVE: {table}" + time.sleep(0.05) + item = {"pk": {"S": "p1"}, "emb": {"L": VECTOR}} + put = admin.post("PutItem", {"TableName": name, "Item": item}) + assert put.status_code == 200, put.text + yield {"name": name, "table_arn": table["TableArn"]} + finally: + admin.post("DeleteTable", {"TableName": name}) + + +def _search(p: Principal, table: str, index: str = "vidx") -> requests.Response: + return p.post( + "SearchVectors", + {"TableName": table, "IndexName": index, "SearchVector": VECTOR, "TopK": 5}, + ) + + +def _assert_denied(resp: requests.Response) -> None: + assert resp.status_code == 400, resp.text + assert _error_type(resp) == "AccessDeniedException", resp.text + + +def test_allowed_principal_searches_the_index(principal, vector_table): + resp = _search(principal(ALLOW_ALL), vector_table["name"]) + assert resp.status_code == 200, resp.text + assert len(resp.json()["SearchResults"]) == 1, resp.text + + +def test_deny_on_the_vector_index_refuses_search(principal, vector_table): + p = principal(_allow_all_deny(vector_table["table_arn"] + "/index/vidx")) + _assert_denied(_search(p, vector_table["name"])) + # The same table named by its ARN reaches the same Deny. + _assert_denied(_search(p, vector_table["table_arn"])) + + +def test_deny_on_the_index_wildcard_refuses_search(principal, vector_table): + p = principal(_allow_all_deny(vector_table["table_arn"] + "/index/*")) + _assert_denied(_search(p, vector_table["name"])) + + +def test_deny_on_another_index_permits_search(principal, vector_table): + p = principal(_allow_all_deny(vector_table["table_arn"] + "/index/other")) + resp = _search(p, vector_table["name"]) + assert resp.status_code == 200, resp.text + + +def test_index_name_with_a_slash_is_authorized_as_written(principal, vector_table): + # A Deny on every index of the table matches an IndexName with an extra + # segment, so the request never reaches the engine. + denied = principal(_allow_all_deny(vector_table["table_arn"] + "/index/*")) + _assert_denied(_search(denied, vector_table["name"], "vidx/extra")) + # A caller allowed to search gets ValidationException: no vector index + # carries that name, so the engine searches nothing. + resp = _search(principal(ALLOW_ALL), vector_table["name"], "vidx/extra") + assert resp.status_code == 400, resp.text + assert _error_type(resp) == "ValidationException", resp.text + + +def test_deny_on_the_bare_table_arn_does_not_block_search(principal, vector_table): + # SearchVectors is authorized against the index ARN, so a Deny written only + # on table/ no longer applies to it. Fencing a table needs table//*. + p = principal(_allow_all_deny(vector_table["table_arn"])) + resp = _search(p, vector_table["name"]) + assert resp.status_code == 200, resp.text + + +def test_allow_on_the_bare_table_arn_does_not_permit_search(principal, vector_table): + # An Allow written only on table/ no longer covers SearchVectors. + only_table = { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Action": "dynamodb:SearchVectors", + "Resource": vector_table["table_arn"], + } + ], + } + _assert_denied(_search(principal(only_table), vector_table["name"])) + # An Allow on the table's indexes does cover it. + on_indexes = { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Action": "dynamodb:SearchVectors", + "Resource": vector_table["table_arn"] + "/index/*", + } + ], + } + resp = _search(principal(on_indexes), vector_table["name"]) + assert resp.status_code == 200, resp.text From c6a2700470242ee05ee089345bc7f438b48c8462 Mon Sep 17 00:00:00 2001 From: Amol Navare Date: Mon, 16 Nov 2026 09:47:25 -0800 Subject: [PATCH 2/4] fix(authz): refuse a bad SearchVectors IndexName before authorization 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//index/*, or one allowed only table/, 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. --- crates/server/src/authz_resource.rs | 6 +- crates/server/src/table_name_gate.rs | 26 ++++- docs/manuals/05-admin-guide.md | 13 ++- docs/manuals/07-upgrade-manual.md | 17 +-- tests/test_authz_search_vectors_index.py | 139 ++++++++++------------- 5 files changed, 107 insertions(+), 94 deletions(-) diff --git a/crates/server/src/authz_resource.rs b/crates/server/src/authz_resource.rs index 437713199..4261d9efb 100644 --- a/crates/server/src/authz_resource.rs +++ b/crates/server/src/authz_resource.rs @@ -762,9 +762,9 @@ pub(crate) fn authz_targets( v } // Query and Scan on an index, and SearchVectors, authorize the index - // ARN. SearchVectors always names a vector index, and the service - // documents `table//index/` as the resource for - // dynamodb:SearchVectors. With a table ARN in TableName the denial + // ARN. The service documents `table//index/` as the resource for + // dynamodb:SearchVectors. A request that names no index (IndexName + // missing or empty) authorizes the table, as Query and Scan do. With a table ARN in TableName the denial // 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. diff --git a/crates/server/src/table_name_gate.rs b/crates/server/src/table_name_gate.rs index bb92f5ba5..00b96ff61 100644 --- a/crates/server/src/table_name_gate.rs +++ b/crates/server/src/table_name_gate.rs @@ -24,7 +24,7 @@ //! `; ` under `2 validation errors detected:` (measured at `tableName`; //! derived for the other locations). Locations: `tableName` for `TableName`, //! `targetTableName`, `sourceTableName`, `tableCreationParameters.tableName`, -//! `exclusiveStartTableName`, `indexName` for `Query` and `Scan`, and +//! `exclusiveStartTableName`, `indexName` for `Query`, `Scan` and `SearchVectors`, and //! `transactItems..member..tableName` (1-based, `put`, `get`, //! `delete`, `update`, `conditionCheck`). A name inside the pattern but of a //! bad length is left to the engine handlers, whose answer the service's @@ -142,7 +142,7 @@ pub(crate) fn check_table_name_chars( // service refuses U+0000 in either (measured 2026-11-06). with_str(input, "ExclusiveStartStreamArn", arn_gate::check_stream_arn) } - "Query" | "Scan" => { + "Query" | "Scan" | "SearchVectors" => { check_name(input.get("TableName"), "tableName", operation, account_id)?; match input.get("IndexName").and_then(Value::as_str) { // Pattern only: the length clauses for an index name are unmeasured. @@ -451,6 +451,28 @@ mod tests { ); } + #[test] + fn search_vectors_index_name_outside_the_pattern_is_refused_as_query_is() { + for bad in ["vidx/extra", "g\u{0}2", "a b", "v%2fx"] { + let input = json!({ "TableName": "ok", "IndexName": bad }); + let expected = one(bad, "indexName", PAT); + assert_eq!(message("SearchVectors", input.clone()).unwrap(), expected); + assert_eq!(message("Query", input).unwrap(), expected); + } + for input in [ + json!({ "TableName": "ok", "IndexName": "vidx" }), + json!({ "TableName": "ok", "IndexName": "" }), + json!({ "TableName": "ok" }), + ] { + assert!(message("SearchVectors", input.clone()).is_none(), "{input}"); + } + // The table name is checked as for any operation. + assert_eq!( + message("SearchVectors", json!({ "TableName": NUL, "IndexName": "vidx" })).unwrap(), + one(NUL, "tableName", PAT) + ); + } + #[test] fn members_read_as_names_pass_an_arn_on_unless_it_carries_nul() { let good = "arn:aws:dynamodb:us-east-1:123456789012:table/t367name"; diff --git a/docs/manuals/05-admin-guide.md b/docs/manuals/05-admin-guide.md index 32b9f7566..35037e9e7 100755 --- a/docs/manuals/05-admin-guide.md +++ b/docs/manuals/05-admin-guide.md @@ -737,18 +737,21 @@ upgrading: authorized against `table//index/`. A policy that granted a principal only `table/` no longer allows reads or searches of that table's indexes. Grant `table//index/` or - `table//index/*` as needed. This follows the DynamoDB developer guide. + `table//index/*` as needed. This matches DynamoDB for Query and Scan. + For SearchVectors it follows the DynamoDB developer guide, which gives + `table//index/` as the resource; it has not been measured + against the service. - **Fencing a whole table with a Deny.** Index reads, `SearchVectors`, `ListStreams` with a TableName, and `ListBackups` with a TableName are authorized against a sub-resource ARN (`table//index/*`, `table//stream/*`, `table//backup/*`), not the bare `table/`. A `Deny` written only on `table/` therefore does not cover them, and `SearchVectors` needs the index ARN - (`table//index/`) in the `Allow` as well. An operator who means to - fence a whole table adds `table//*` to the `Deny` alongside + (`table//index/`) in the `Allow` as well. An operator who means + to fence a whole table adds `table//*` to the `Deny` alongside `table/`. -- **Index reads and resource tags.** An index Query or Scan evaluates the base - table's resource tags (`aws:ResourceTag/*`; `dynamodb:ResourceTag/*` is +- **Index reads and resource tags.** An index Query or Scan, and SearchVectors, + evaluate the base table's resource tags (`aws:ResourceTag/*`; `dynamodb:ResourceTag/*` is absent for every resource), because a secondary index inherits the tags of its table. An ABAC `Deny` or `Allow` conditioned on the table's tags applies to its indexes. diff --git a/docs/manuals/07-upgrade-manual.md b/docs/manuals/07-upgrade-manual.md index 1444a7944..d93692d16 100755 --- a/docs/manuals/07-upgrade-manual.md +++ b/docs/manuals/07-upgrade-manual.md @@ -791,18 +791,19 @@ effect where it was previously bypassed. **Who is affected and what to change** (no catalog migration is required): -- **Index reads need an index grant.** Query and Scan with an `IndexName` are - authorized against `table//index/`. A policy granting only - `table/` no longer allows that table's index reads; grant - `table//index/` or `table//index/*`. -- **Fencing a whole table with a Deny.** Index reads, `ListStreams` with a +- **Index reads need an index grant.** Query and Scan with an `IndexName`, and + SearchVectors, are authorized against `table//index/`. A policy + granting only `table/` no longer allows that table's index reads or + SearchVectors; grant `table//index/` or `table//index/*`. +- **Fencing a whole table with a Deny.** Index reads, SearchVectors, + `ListStreams` with a TableName, and `ListBackups` with a TableName are authorized against a sub-resource ARN (`table//index/*`, `table//stream/*`, `table//backup/*`), not the bare `table/`. A `Deny` on - `table/` does not cover them: add `table//*` to the `Deny` + `table/` does not cover them, so it no longer blocks SearchVectors: add `table//*` to the `Deny` alongside `table/` to fence the whole table. -- **Index reads and resource tags.** An index Query or Scan evaluates the base - table's resource tags, because an index inherits its table's tags. An ABAC +- **Index reads and resource tags.** An index Query or Scan, and SearchVectors, + evaluate the base table's resource tags, because an index inherits its table's tags. An ABAC `Deny` or `Allow` conditioned on the table's tags now applies to its indexes. - **ListStreams, ListBackups, and resource tags.** ListStreams and ListBackups with a TableName are authorized against the table's `stream/*` or `backup/*` diff --git a/tests/test_authz_search_vectors_index.py b/tests/test_authz_search_vectors_index.py index 23b4f5f7e..f379bb1a3 100644 --- a/tests/test_authz_search_vectors_index.py +++ b/tests/test_authz_search_vectors_index.py @@ -10,10 +10,8 @@ ``dynamodb:*`` on ``*`` plus one Deny, and checks the refusal and its error type against a running server. -An IndexName that is not one index segment (``vidx/extra``) is authorized as -written, so a Deny on ``table//index/*`` refuses it; a caller allowed to -search gets ValidationException from the engine, because no vector index can -carry such a name. +An IndexName outside ``[a-zA-Z0-9_.-]+`` (``vidx/extra``) gets ValidationException +for every caller, before the policy decision, as Query and Scan do. The principals are builtin-IAM users provisioned through the management API. The module skips when the backend does not support vector indexes, unless @@ -40,6 +38,7 @@ from botocore.credentials import Credentials from management_helpers import ManagementClient +from test_search_vectors_condition_limit import _expect_vectors REGION = os.environ.get("AWS_DEFAULT_REGION", "us-east-1") VECTOR = [{"N": "0.1"}, {"N": "0.2"}, {"N": "0.3"}, {"N": "0.4"}] @@ -73,16 +72,6 @@ def _require_auth_env() -> tuple[str, str, str]: return endpoint, admin_user, admin_pass -def _expect_vectors() -> bool | None: - """``EXTENDDB_EXPECT_VECTORS``: 1 requires vector support, 0 forbids it.""" - value = os.environ.get("EXTENDDB_EXPECT_VECTORS") - if value is None: - return None - if value not in ("0", "1"): - pytest.fail(f"EXTENDDB_EXPECT_VECTORS must be 0 or 1, got {value!r}") - return value == "1" - - class Principal: """A builtin-IAM user that posts SigV4-signed DynamoDB JSON requests.""" @@ -202,9 +191,44 @@ def _search(p: Principal, table: str, index: str = "vidx") -> requests.Response: ) -def _assert_denied(resp: requests.Response) -> None: - assert resp.status_code == 400, resp.text - assert _error_type(resp) == "AccessDeniedException", resp.text +def _policy(effect: str, resource: str) -> dict: + """Allow: SearchVectors on ``resource`` only. Deny: allow-all plus a Deny on it.""" + if effect == "Allow": + return { + "Version": "2012-10-17", + "Statement": [ + {"Effect": "Allow", "Action": "dynamodb:SearchVectors", "Resource": resource} + ], + } + return _allow_all_deny(resource) + + +# (effect, resource suffix on the table ARN, status, error type) +POLICY_CASES = [ + ("Deny", "/index/vidx", 400, "AccessDeniedException"), + ("Deny", "/index/*", 400, "AccessDeniedException"), + ("Deny", "/index/other", 200, None), + ("Deny", "", 200, None), # a table-only Deny does not cover SearchVectors + ("Allow", "", 400, "AccessDeniedException"), # a table-only Allow loses it + ("Allow", "/index/*", 200, None), +] + + +@pytest.mark.parametrize( + ("effect", "suffix", "status", "error"), + POLICY_CASES, + ids=[f"{e}-table{s or ''}" for e, s, _, _ in POLICY_CASES], +) +def test_search_is_authorized_against_the_index_arn( + principal, vector_table, effect, suffix, status, error +): + p = principal(_policy(effect, vector_table["table_arn"] + suffix)) + resp = _search(p, vector_table["name"]) + assert resp.status_code == status, resp.text + if error: + assert _error_type(resp) == error, resp.text + else: + assert len(resp.json()["SearchResults"]) == 1, resp.text def test_allowed_principal_searches_the_index(principal, vector_table): @@ -213,67 +237,30 @@ def test_allowed_principal_searches_the_index(principal, vector_table): assert len(resp.json()["SearchResults"]) == 1, resp.text -def test_deny_on_the_vector_index_refuses_search(principal, vector_table): +def test_deny_on_the_vector_index_also_applies_to_the_table_arn_name( + principal, vector_table +): p = principal(_allow_all_deny(vector_table["table_arn"] + "/index/vidx")) - _assert_denied(_search(p, vector_table["name"])) - # The same table named by its ARN reaches the same Deny. - _assert_denied(_search(p, vector_table["table_arn"])) - - -def test_deny_on_the_index_wildcard_refuses_search(principal, vector_table): - p = principal(_allow_all_deny(vector_table["table_arn"] + "/index/*")) - _assert_denied(_search(p, vector_table["name"])) - - -def test_deny_on_another_index_permits_search(principal, vector_table): - p = principal(_allow_all_deny(vector_table["table_arn"] + "/index/other")) - resp = _search(p, vector_table["name"]) - assert resp.status_code == 200, resp.text + resp = _search(p, vector_table["table_arn"]) + assert resp.status_code == 400, resp.text + assert _error_type(resp) == "AccessDeniedException", resp.text -def test_index_name_with_a_slash_is_authorized_as_written(principal, vector_table): - # A Deny on every index of the table matches an IndexName with an extra - # segment, so the request never reaches the engine. - denied = principal(_allow_all_deny(vector_table["table_arn"] + "/index/*")) - _assert_denied(_search(denied, vector_table["name"], "vidx/extra")) - # A caller allowed to search gets ValidationException: no vector index - # carries that name, so the engine searches nothing. - resp = _search(principal(ALLOW_ALL), vector_table["name"], "vidx/extra") +@pytest.mark.parametrize( + "policy_resource", + [None, "/index/*"], + ids=["allow-all", "deny-index-wildcard"], +) +def test_index_name_outside_the_pattern_is_refused_before_authorization( + principal, vector_table, policy_resource +): + # Query and Scan refuse such a name with ValidationException before the + # policy decision; SearchVectors does the same for every caller. + policy = ( + ALLOW_ALL + if policy_resource is None + else _allow_all_deny(vector_table["table_arn"] + policy_resource) + ) + resp = _search(principal(policy), vector_table["name"], "vidx/extra") assert resp.status_code == 400, resp.text assert _error_type(resp) == "ValidationException", resp.text - - -def test_deny_on_the_bare_table_arn_does_not_block_search(principal, vector_table): - # SearchVectors is authorized against the index ARN, so a Deny written only - # on table/ no longer applies to it. Fencing a table needs table//*. - p = principal(_allow_all_deny(vector_table["table_arn"])) - resp = _search(p, vector_table["name"]) - assert resp.status_code == 200, resp.text - - -def test_allow_on_the_bare_table_arn_does_not_permit_search(principal, vector_table): - # An Allow written only on table/ no longer covers SearchVectors. - only_table = { - "Version": "2012-10-17", - "Statement": [ - { - "Effect": "Allow", - "Action": "dynamodb:SearchVectors", - "Resource": vector_table["table_arn"], - } - ], - } - _assert_denied(_search(principal(only_table), vector_table["name"])) - # An Allow on the table's indexes does cover it. - on_indexes = { - "Version": "2012-10-17", - "Statement": [ - { - "Effect": "Allow", - "Action": "dynamodb:SearchVectors", - "Resource": vector_table["table_arn"] + "/index/*", - } - ], - } - resp = _search(principal(on_indexes), vector_table["name"]) - assert resp.status_code == 200, resp.text From dfb32f3c333bef0fcb7a735a6beddaa5c7b959ca Mon Sep 17 00:00:00 2001 From: Amol Navare Date: Mon, 16 Nov 2026 09:51:18 -0800 Subject: [PATCH 3/4] style(server): format the SearchVectors gate test --- crates/server/src/table_name_gate.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/server/src/table_name_gate.rs b/crates/server/src/table_name_gate.rs index 00b96ff61..1268878ed 100644 --- a/crates/server/src/table_name_gate.rs +++ b/crates/server/src/table_name_gate.rs @@ -468,7 +468,11 @@ mod tests { } // The table name is checked as for any operation. assert_eq!( - message("SearchVectors", json!({ "TableName": NUL, "IndexName": "vidx" })).unwrap(), + message( + "SearchVectors", + json!({ "TableName": NUL, "IndexName": "vidx" }) + ) + .unwrap(), one(NUL, "tableName", PAT) ); } From cc43a0bd19279ec98eb124778b8becb9bb2b31a5 Mon Sep 17 00:00:00 2001 From: Amol Navare Date: Mon, 16 Nov 2026 13:35:32 -0800 Subject: [PATCH 4/4] fix(authz): name the vector index in a cross-account SearchVectors denial A SearchVectors request that names a table in another account is refused either way, but the denial named table/ where Query and Scan name table//index/. 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. --- .../src/authz_resource/cross_account.rs | 8 +++-- .../src/authz_resource/cross_account/tests.rs | 29 +++++++++++++++++++ 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/crates/server/src/authz_resource/cross_account.rs b/crates/server/src/authz_resource/cross_account.rs index c61f8b0b6..d15016dbf 100644 --- a/crates/server/src/authz_resource/cross_account.rs +++ b/crates/server/src/authz_resource/cross_account.rs @@ -24,7 +24,8 @@ //! `DeleteTable`, `DeleteItem` and `DeleteBackup` were not sent to the //! service; they take the answers of `UpdateTable`, `UpdateItem` and //! `DescribeBackup`. `SearchVectors` has no service counterpart and takes the -//! answers of `DescribeTable`. +//! answers of `DescribeTable`, naming the vector index ARN as `Query` and +//! `Scan` name theirs. //! //! On the service a `StreamArn` that is not a stream ARN (a table, index or //! backup ARN included), or has an empty partition, service or account field, @@ -127,8 +128,9 @@ pub(crate) fn find(operation: &str, input: &Value, account_id: &str) -> Option None, // An index query names the index ARN, built from the table ARN as - // written (measured: `.../table//index/`). - "Query" | "Scan" => { + // written (measured: `.../table//index/`). SearchVectors names + // its index the same way, as `authz_targets` does. + "Query" | "Scan" | "SearchVectors" => { let table = field("TableName")?; let resource = match field("IndexName") { Some(index) diff --git a/crates/server/src/authz_resource/cross_account/tests.rs b/crates/server/src/authz_resource/cross_account/tests.rs index bd39b1565..1a66cd484 100644 --- a/crates/server/src/authz_resource/cross_account/tests.rs +++ b/crates/server/src/authz_resource/cross_account/tests.rs @@ -105,6 +105,35 @@ fn an_index_query_names_the_index_arn() { } } +/// SearchVectors in another account names the vector index ARN, as Query does, +/// and a request with no index names the table. +#[test] +fn a_cross_account_search_vectors_names_the_index_arn() { + let input = json!({ "TableName": FOREIGN, "IndexName": "vidx" }); + assert_eq!( + find("SearchVectors", &input, A), + other("SearchVectors", &format!("{FOREIGN}/index/vidx")) + ); + for input in [ + json!({ "TableName": FOREIGN }), + json!({ "TableName": FOREIGN, "IndexName": "" }), + ] { + assert_eq!( + find("SearchVectors", &input, A), + other("SearchVectors", FOREIGN) + ); + } + // The denial for a known account names that resource. + let p = "arn:aws:iam::444455556666:user/u"; + let index = format!("{FOREIGN}/index/vidx"); + let DynamoDbError::AccessDeniedException(m) = + refusal("SearchVectors", "SearchVectors", &index, true, p) + else { + panic!("expected AccessDeniedException"); + }; + assert!(m.contains(&format!("on resource: {index} ")), "{m}"); +} + /// The caller's own resources, bare names, ARNs that are not a table resource /// and fields the service reads as a name are left to authorization. #[test]