Check attribute reads and reset the salt in alter_user_scram_credentials() #2442
All Vouch review confidence checks passed
Residual risk 0.28 = Change Risk (0.52) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #2442"
general
weight: 0.35
pylaterreur
What
----
Problems in the C
alter_user_scram_credentials():1. An upsertion without a salt got the salt of the previous upsertion in the same call.
c_saltandc_salt_sizewere only set when the alteration had a salt, and librdkafka copies the salt it is given, so it only generates a random salt when it gets none. With anLD_PRELOADshim logging the arguments ofrd_kafka_UserScramCredentialUpsertion_new(),AdminClient.alter_user_scram_credentials([UserScramCredentialUpsertion("alice", info, b"password-a", b"0123456789abcdef"), UserScramCredentialUpsertion("bob", info, b"password-b")])passes the salt0123456789abcdeffor bob too on master and #2439, on 3.11 and 3.14t. With this branch, bob's upsertion gets no salt, so librdkafka generates a random one, asUserScramCredentialUpsertiondocuments.2. The function ignored the result of every attribute read.
AdminClient.alter_user_scram_credentials()validates most of the alterations first, but the C method, when called directly or given alterations changed after that validation, crashed on a missing attribute:- Most reads were optional, so a missing attribute came back as NULL with the
AttributeErrorstill set, and went toPyObject_IsInstance()orPy_TYPE(). This happened forscram_credential_info,password,salt, the mechanism of aScramCredentialInfo, and the mechanism of a deletion.- A missing
usercrashed inPy_DECREF()on the first alteration. On a later alteration, it reused the previous alteration's user name and released it a second time.- A missing or non-
intiterationsleft the C value uninitialized, and the call went on with the exception set.- An alteration that was neither an upsertion nor a deletion left its librdkafka alteration uninitialized:
free(): invalid size.- An error from
PyObject_IsInstance()counted as a match.3.
AdminClient's check of the iteration count isiterations < 1, so a non-intone such as4096.0, anIntEnummember orTruereaches the C method through the public API. It left the count uninitialized and passed it to librdkafka. The call then raisedSystemErroron 3.14t, and returned normally on 3.11, where the next attribute read cleared the pendingTypeError(PyErr_Clear()inPyObject_GenericGetAttr()). Depending on what the count held, librdkafka rejected the request (Non-positive iterations at index 0) or went on to send it: in a run under gdb, it waited for the controller.cfl_PyObject_GetInt()also truncated a value that fits in a Clongbut not in anint(232 + 4096became 4096,231became negative), and for one that does not fit in along, such as2100, returned success with anOverflowErrorset.The attributes are now read as required ones, and each read and each
PyObject_IsInstance()result is checked. An alteration that is neither an upsertion nor a deletion raisesTypeError, and the user is released if a check on it fails. A non-intiteration count raisesTypeError, andcfl_PyObject_GetInt()raisesOverflowErrorfor a value outside the range of a Cint. The error messages usePy_TYPE(), sincePyObject_Type()leaked a reference to the type, as in #2440.Checklist
------------------
- The salt fix, and
TypeError/OverflowErrorfor iteration counts thatAdminClientlets through. CHANGELOG entries under Unreleased.- New tests in
tests/test_Admin.pycallAdminClient.alter_user_scram_credentials()with the iteration counts its checks let through:4096.0, anIntEnummember andTrueraiseTypeError,231and2100raiseOverflowError, and231 - 1is accepted.- New
tests/test_admin_scram_alterations.pycalls the C method directly with 14 alterations: 3 valid ones, one of them with an iteration count of-231, the lowest that fits, and 11 thatAdminClientrejects itself, with an attribute missing, of the wrong type or out of range (-231 - 1), or of the wrong class. Each runs in a subprocess, since most of them crashed, and closes its client before the interpreter exits.- The salt fix has no unit test: only the broker sees the salt, and the mock cluster of librdkafka 2.16.0 doesn't implement AlterUserScramCredentials. I checked it with the shim described above.
References
----------
list_consumer_group_offsets()andalter_consumer_group_offsets().Test & Review
------------
tests/test_admin_scram_alterations.py: on #2439, 11 of the 14 cases fail on both: 7 by segfault, 1 by abort (free(): invalid size), the 2iterationsattribute cases are accepted on 3.11 and raiseSystemErroron 3.14t, and-231 - 1is accepted. With this branch, all 14 pass on both.tests/test_Admin.pytests: on master, the 5 rejection cases fail on both. On 3.11, all 5 calls return normally. On 3.14t,4096.0, theIntEnummember,Trueand2100raiseSystemError, and231is accepted. Before thecfl_PyObject_GetInt()change,231and2100still failed (on 3.14t,2100raisedTypeError: Required attribute .value missing). With this branch, all 6 tests pass on both.tests/test_*.pyandtests/concurrency: 697 passed and 5 skipped on 3.11; 603 passed and 7 skipped on 3.14t. On 3.14t I deselectedtest_kafkaError_unknown_error, whoseKafkaErrorescapes pytest with the pluggy 1.7.0 of my environment and ends the session (#2444 fixes that test).tools/style-format.shandflake8pass on the changed test files. clang-format 18.1.3 and 20.1.8 report no new differences inAdmin.candconfluent_kafka.c.🤖 Generated with Claude Code
https://claude.ai/code/session_01GwUvhmzgfkiZ6vo4uGyesN