Repository navigation
fix(authz): authorize SearchVectors against the vector index ARN #999
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
145a4a2
fix(authz): authorize SearchVectors against the vector index ARN
c6a2700
fix(authz): refuse a bad SearchVectors IndexName before authorization
dfb32f3
style(server): format the SearchVectors gate test
cc43a0b
fix(authz): name the vector index in a cross-account SearchVectors de…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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}"); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
IndexNameoutside[a-zA-Z0-9_.-]+intable_name_gate.rsbefore the IAM decision (the change in #830). SearchVectors is not in that arm, so with this change an IndexName likevidx/extragoes into the resource as sent and a caller with a Deny ontable/T/index/*, or one allowed onlytable/T, gets AccessDeniedException. On a run (both backends) Query answeredValidationException ... 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. AddingSearchVectorsto 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.
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 intable_name_gate.rs, sovidx/extragets the pattern ValidationException atindexNamebefore 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, renamedtest_index_name_outside_the_pattern_is_refused_before_authorization, now expects ValidationException for both the allow-all caller and the caller with a Deny ontable/T/index/*. A unit test compares SearchVectors with Query forvidx/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.