Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions crates/server/src/authz_resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
//! | `ExportTableToPointInTime` | same | the `TableArn` |
//! | `ImportTable` | same | the new table ARN |
//! | `Query`/`Scan` (with `IndexName`) | same | `table/<T>/index/<I>` |
//! | `SearchVectors` | same | `table/<T>/index/<I>` |
//! | `ListTables` | `ListTables` | `table/*` |
//! | item/table ops | same | the table ARN (from `TableName`, name or ARN) |
//!
Expand Down Expand Up @@ -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/<T>/index/<I>` 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" => {

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.

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.

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.

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.

let base = table_resource_arn(&table_name, region, account_id);
match str_field(input, "IndexName") {
Some(idx) if !idx.is_empty() => {
Expand Down Expand Up @@ -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;
8 changes: 5 additions & 3 deletions crates/server/src/authz_resource/cross_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -127,8 +128,9 @@ pub(crate) fn find(operation: &str, input: &Value, account_id: &str) -> Option<O
"ListStreams" | "ImportTable" | "ListTables" | "DescribeLimits" | "DescribeEndpoints"
| "GetRecords" => None,
// An index query names the index ARN, built from the table ARN as
// written (measured: `.../table/<T>/index/<I>`).
"Query" | "Scan" => {
// written (measured: `.../table/<T>/index/<I>`). 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)
Expand Down
29 changes: 29 additions & 0 deletions crates/server/src/authz_resource/cross_account/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
72 changes: 72 additions & 0 deletions crates/server/src/authz_resource/search_vectors_tests.rs
Original file line number Diff line number Diff line change
@@ -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/<T>/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}");
}
}
30 changes: 28 additions & 2 deletions crates/server/src/table_name_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.<n>.member.<op>.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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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";
Expand Down
32 changes: 19 additions & 13 deletions docs/manuals/05-admin-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/<name>` |
| Query and Scan with an `IndexName` | `table/<name>/index/<index>` |
| SearchVectors | `table/<name>/index/<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 |
Expand All @@ -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/<name>/index/<index>`. A policy that granted a principal only
`table/<name>` no longer allows reads of that table's indexes. Grant
`table/<name>/index/<index>` or `table/<name>/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/<name>/index/*`, `table/<name>/stream/*`,
`table/<name>/backup/*`), not the bare `table/<name>`. A `Deny` written only
on `table/<name>` therefore does not cover them. An operator who means to
fence a whole table adds `table/<name>/*` to the `Deny` alongside
- **Index reads.** Query and Scan with an `IndexName`, and SearchVectors, are
authorized against `table/<name>/index/<index>`. A policy that granted a
principal only `table/<name>` no longer allows reads or searches of that
table's indexes. Grant `table/<name>/index/<index>` or
`table/<name>/index/*` as needed. This matches DynamoDB for Query and Scan.
For SearchVectors it follows the DynamoDB developer guide, which gives
`table/<name>/index/<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/<name>/index/*`,
`table/<name>/stream/*`, `table/<name>/backup/*`), not the bare
`table/<name>`. A `Deny` written only on `table/<name>` therefore does not
cover them, and `SearchVectors` needs the index ARN
(`table/<name>/index/<index>`) in the `Allow` as well. An operator who means
to fence a whole table adds `table/<name>/*` to the `Deny` alongside
`table/<name>`.
- **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.
Expand Down
17 changes: 9 additions & 8 deletions docs/manuals/07-upgrade-manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/<name>/index/<index>`. A policy granting only
`table/<name>` no longer allows that table's index reads; grant
`table/<name>/index/<index>` or `table/<name>/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/<name>/index/<index>`. A policy
granting only `table/<name>` no longer allows that table's index reads or
SearchVectors; grant `table/<name>/index/<index>` or `table/<name>/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/<name>/index/*`, `table/<name>/stream/*`,
`table/<name>/backup/*`), not the bare `table/<name>`. A `Deny` on
`table/<name>` does not cover them: add `table/<name>/*` to the `Deny`
`table/<name>` does not cover them, so it no longer blocks SearchVectors: add `table/<name>/*` to the `Deny`
alongside `table/<name>` 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/*`
Expand Down
Loading
Loading