diff --git a/crates/server/src/authz_resource.rs b/crates/server/src/authz_resource.rs index 7b1d4c95c..4261d9efb 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. 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. + "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/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] 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/crates/server/src/table_name_gate.rs b/crates/server/src/table_name_gate.rs index bb92f5ba5..1268878ed 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,32 @@ 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 fe5f402b7..35037e9e7 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,20 +733,25 @@ 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 - fence a whole table adds `table//*` to the `Deny` alongside +- **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 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 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 new file mode 100644 index 000000000..f379bb1a3 --- /dev/null +++ b/tests/test_authz_search_vectors_index.py @@ -0,0 +1,266 @@ +# 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 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 +``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 +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"}] + +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 + + +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 _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): + 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_also_applies_to_the_table_arn_name( + principal, vector_table +): + p = principal(_allow_all_deny(vector_table["table_arn"] + "/index/vidx")) + resp = _search(p, vector_table["table_arn"]) + assert resp.status_code == 400, resp.text + assert _error_type(resp) == "AccessDeniedException", resp.text + + +@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