Repository navigation
fix: keep auth tokens, secret values and statement text out of debug logs, errors and reprs - #1340
Merged
Merged
Conversation
…logs, errors and reprs
karenc-bq
approved these changes
Nov 5, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
With DEBUG logging on, the wrapper writes the RDS auth token that
iam,federated_authandoktaconnect with into its own log lines, and the Secrets Manager plugin's fetch lets botocore log the wholeGetSecretValueresponse, password included. Two error paths leak as well: the old-connectionAwsWrapperErrorquotes a mysql-connector cursor's last statement with its values, andPropertiesprints the raw password inrepr(), tracebacks and pytest reports.This PR removes each value where it enters the text and leaves the rest of what is logged or raised as it was.
IamAuthUtils.generate_authentication_token,IamAuthPlugin._connect,FederatedAuthPlugin._connect,OktaAuthPlugin._connectandAsyncFederatedAuthPlugin._resolve_credentialspassed the token tologger.debug, and four message texts printed it with= {}. The token works as the database password until it expires, so the DEBUG log held a working credential. The calls now pass no argument and the texts drop= {}, so the lines still say that a token was generated or reused. Reproduced on Aurora PostgreSQL and Aurora MySQL with IAM database authentication: the token was in the DEBUG records before this change and in none after.botocore.parserslogger, and aGetSecretValuebody holdsSecretString. A new helper,_get_secret_valueinaws_secrets_manager_plugin.py, now makes the call for bothAwsSecretsManagerPluginandAsyncAwsSecretsManagerPlugin. While the call runs, a filter onbotocore.parsersdrops records on the calling thread only, so records from other threads and records after the call are kept, and an application's own boto3 calls still log. The filter is added on each call and never removed, becauseaddFilterskips a filter already present and removing it could race with another thread's logging. Reproduced with LocalStack Secrets Manager and with an RDS-managed master secret on Aurora, sync and async.PluginManager.executeandAbstractReadWriteSplittingPlugin.executeformatted the driver object into thePluginManager.MethodInvokedAgainstOldConnectionmessage. A mysql-connector cursor'sstr()is its class name plus the first 40 characters of its last statement with the values filled in, so literals and bound parameters reached error text, logs and error reporters, and a psycopg cursor's showed the host, user and database. Both sites now passtype(target).__name__, so the message names the class ('CMySQLCursor'). Reproduced with mysql-connector's C extension and pure builds throughsrw, on MySQL 8 and on Aurora MySQL.Propertiesis adictsubclass with no__repr__, sorepr(),str(), f-strings,tracebackwithcapture_localsand pytest's failure reports showed every value, password included, although the wrapper's logs already mask it withPropertiesUtils.mask_properties.Properties.__repr__now returns thedictrepr of the masked copy, and the stored values don't change. On PostgreSQL 16 and MySQL 8, a failed connect's traceback had 19 and 17Propertieslocals showing the password before this change and none after.Behaviour changes
GetSecretValuecalls leave nobotocore.parsersrecords on their thread, headers included.aio/plugin_manager.pyis unchanged, because psycopg's async cursor text holds no statement and aiomysql's cursor has no text of its own, so the sync and async messages now differ.repr(),str()and f-strings of aPropertiesshow'***'for every key containingpasswordorpasswd, as the logs already do.Not in scope
Each of these needs a filter on a third-party logger, so they're left for a separate change.
botocore.auth, botocore'sCanonicalRequestandSignaturerecords hold every token parameter and the signature, which is enough to rebuild the token.federated_authandokta, botocore can log the STSAssumeRoleWithSAMLresponse, which holds temporary AWS credentials (from readingbotocore/parsers.py; not reproduced).sha256_passwordormysql_clear_password. Withiamthat password is the token. It does this without the wrapper too, andlogging.getLogger("mysql.connector").setLevel(logging.INFO)avoids it.The drivers' own frames in a traceback still hold their unmasked dicts.
Tests
The 14 new unit test cases (7 for the token lines, 2 for Secrets Manager, 3 for the old-connection message, 2 for
Properties) fail onmainand pass with this change. The token tests also check that noLogger.debugcall receives the token, and a guard checks that another thread'sbotocore.parsersrecord and one logged after the fetch still appear.pytest tests/unit -Werrorpasses 2458 tests on Python 3.12 and 3.10, with flake8, isort and mypy clean. Live checks outside this PR fail onmainand pass with this change: 27 cases against PostgreSQL 16, MySQL 8 and LocalStack Secrets Manager, and 15 on Aurora PostgreSQL and Aurora MySQL (Serverless v2, IAM database authentication, RDS-managed secrets). A differential run of 783 cases across plugin chains found only the expected old-connection message change (6 cases), and 51 cases on Aurora found none. The integration test suite wasn't run. No CHANGELOG entry, message key or docs change.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.