Repository navigation
fix(storage-mongodb): look up an IAM user by its ARN index - #1570
hitesh96db wants to merge 3 commits into
Conversation
The MongoDB catalog's only index on iam_users is the unique one on user_arn. get_user_detail, verify_iam_user_password, create_access_key, change_user_password, fetch_user_created_at and get_user_password_hash filtered on account_id and user_name, so each was a collection scan, and a lookup of a user that does not exist read every document. The filter now also carries user_arn, which create_user builds from the same two fields, so the unique index answers it. account_id and user_name stay in the filter. Signed-off-by: Hitesh Sharma <hts@amazon.com>
delete_user and the undo of a failed create_user filtered iam_users by account_id and user_name, which is a collection scan, as the lookups fixed for #841 were. Build their filter with user_filter. The plan test now covers every single-user operation, including delete_user and a user stored as 0.1.4 and later releases stored it. It checks each call on its own: the call must reach iam_users, read an index, and find a user that exists. The design doc names the ARN form the lookups depend on. Signed-off-by: Hitesh Sharma <hts@amazon.com>
…ert message CodeQL flagged the Debug output of change_user_password's result as cleartext logging of sensitive data. The message now names the call only. Signed-off-by: Hitesh Sharma <hts@amazon.com>
navareamol
left a comment
There was a problem hiding this comment.
I found nothing that blocks this. I built it and ran iam_user_lookup_plan against a single node replica set: it passes. I then took the user_arn line out of user_filter on a clean tree and ran the same test: it fails with a COLLSCAN entry for get_user_detail on the filter { account_id, user_name }, so the test does detect the change. The other three test files named in the description pass too, 7 tests in all. I also checked the claim that create_user is the only insert into iam_users and that the ARN form has not changed since the backend was added, and both hold in the code and history.
One question, not a condition for this PR. fetch_user_tags, fetch_user_group_policies and the tag and member reads in get_user_detail still filter on { account_id, user_name } on iam_user_tags, iam_group_members and iam_policies, and I see no index on those fields for those three collections in m0001_baseline.rs. I did not run an explain on them. Do you want to file that as a separate issue?
I will approve once you have answered that question.
|
Thanks, @navareamol. Yes, filed as #1580. From reading the code: Also, the CodeQL cleartext-logging alert on |
What
On MongoDB, the lookups of one IAM user by account and name now filter on
user_arnas well asaccount_idanduser_name.user_arncarries the unique index ofiam_users, so the server answers each lookup with an index scan. The new helperuser_filterincrates/storage-mongodb/src/management_store.rsbuilds the filter, andcreate_userbuilds the ARN with the same function. The seven methods that read, update or delete one user use it:get_user_detail,verify_iam_user_password,create_access_key,change_user_password,get_user_password_hash,fetch_user_created_atanddelete_user(also the undo of a failedcreate_user, throughprincipal_filter).This takes the first of the two options in the issue, so there is no catalog migration. The check the issue asks for:
create_useris the only code that inserts intoiam_users(grepovercrates/), and it has builtarn:aws:iam::{account_id}:user/{user_name}since the backend was added (c1f3de3).account_idanduser_namestay in the filter, so a document whose ARN differed from its fields would not be matched by another user's lookup.Why
Fixes #841. The only index on
iam_usersis the unique one onuser_arn, so a filter onaccount_idanduser_namealone was a collection scan, and a lookup of a user that does not exist read every document. #847 made the login run one bcrypt check whether or not the name exists but did not touch the query.Not done: the issue's timing measurement at 1,000, 10,000 and 100,000 users, and the
{ account_id, user_name }index. The index would need a catalog migration across four backends for the same effect.Testing done
crates/storage-mongodb/tests/iam_user_lookup_plan.rs. It turns the profiler on, calls the seven methods for a user created bycreate_user, one stored in the shape every release since 0.1.4 stored it, and one that does not exist. After each call it asserts that the call sent at least one command toiam_users, that every such command has aplanSummarystarting withIXSCAN, and that the existing users are found.COLLSCANentry forfindwith filter{ account_id, user_name }. With only the first commit, it fails onCOLLSCANfordelete_user.cargo test -p extenddb-storage-mongodb --test iam_leftovers --test session_data --test secret_rows --test iam_user_lookup_planagainst a local single-node replica set: 7 passed.cargo test -p extenddb-storage-mongodb --lib: 197 passed, 86 ignored.cargo fmt --all -- --checkis clean.cargo +1.97.0 clippy -p extenddb-storage-mongodb --all-targets -- -D warningsis clean.cargo test --workspace, the--ignoredlive tests of the crate, and the Python suite against MongoDB.Checklist
cargo test --workspace)cargo fmt --check)cargo clippy -- -W clippy::pedantic)Storagetrait, auth model, on-diskformat, or public CLI surface, an RFC has been accepted or is linked
below. Otherwise, an ADR captures the decision (link below).
ADR / RFC: n/a
By submitting this pull request, I confirm that my contribution is made under
the terms of the Apache License 2.0 and I agree to the Developer Certificate of
Origin (DCO). See CONTRIBUTING.md for details.