Repository navigation
Commit 8166325
authored
fix(auth): use an unencrypted key for mTLS certificate rotation (#18709)
`call_client_cert_callback()` in `google/auth/transport/_mtls_helper.py`
called `get_client_ssl_credentials(generate_encrypted_key=True)` and
then dropped the passphrase. With SecureConnect
(`context_aware_metadata.json`) that adds `--with_passphrase` to the
cert provider command, so the key it returns is encrypted.
Its only caller is `check_parameters_for_unauthorized_response()`, which
the 401 certificate rotation in `AuthorizedSession.request()` and
`AuthorizedHttp.urlopen()` uses. Both pass the key to
`configure_mtls_channel()` without a passphrase, so `load_cert_chain()`
gets an encrypted key with `password=None`.
This passes `generate_encrypted_key=False`, as
`get_client_cert_and_key()` already does for the initial mTLS setup, and
updates `test_call_client_cert_callback` to expect it. A new test drives
the SecureConnect path through a fake cert provider that returns an
encrypted key only for `--with_passphrase`, and checks that the returned
key loads without a passphrase. Workload certificates from
`certificate_config.json` are returned before the flag is read, so they
are not affected, and the async rotation path does not use this
function.
The change does not touch `requests.py` or `urllib3.py`, so it is
independent of #18381. The rotation paths added there also go through
`check_parameters_for_unauthorized_response()` and get the unencrypted
key too.
Testing (Python 3.13 on Windows, Python 3.12 on Linux):
- The updated `test_call_client_cert_callback` and the new
`test_call_client_cert_callback_secure_connect_unencrypted_key` fail
against `_mtls_helper.py` from `main` (the first with `Expected:
get_client_ssl_credentials(generate_encrypted_key=False)`, `Actual:
...(generate_encrypted_key=True)`; the second gets the encrypted key
back) and pass with the change.
- `pytest tests/transport/test__mtls_helper.py
tests/transport/test_requests.py tests/transport/test_urllib3.py
tests/transport/test_mtls.py`: 371 passed.
- `pytest tests tests_async` on Linux: 2263 passed, 7 skipped.
- `ruff check --select I` and `ruff format --check` (ruff 0.14.14 with
the flags from the `lint` session) and `flake8` on the two changed
files: no findings.
- On Linux, passing an encrypted key with no passphrase to
`_MutualTlsAdapter` with no terminal attached printed `Enter PEM pass
phrase:` and raised `MutualTLSChannelError` (caused by `OSError(22,
'Invalid argument')`); with a terminal it waits for input. The same key
unencrypted loads fine.
- [x] Make sure to open an issue as a
[bug/issue](https://github.com/googleapis/google-cloud-python/issues)
before writing your code! That way we can discuss the change, evaluate
designs, and agree on the general idea
- [x] Ensure the tests and linter pass
- [x] Code coverage does not decrease (if any source code was changed)
- [x] Appropriate docs were updated (if necessary)
Fixes #18467 🦕.
Closes #185381 parent e801bb0 commit 8166325
2 files changed
Lines changed: 40 additions & 4 deletions
File tree
- packages/google-auth
- google/auth/transport
- tests/transport
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
911 | 911 | | |
912 | 912 | | |
913 | 913 | | |
914 | | - | |
915 | | - | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
916 | 918 | | |
917 | 919 | | |
918 | 920 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1332 | 1332 | | |
1333 | 1333 | | |
1334 | 1334 | | |
1335 | | - | |
| 1335 | + | |
1336 | 1336 | | |
1337 | 1337 | | |
1338 | 1338 | | |
1339 | 1339 | | |
1340 | 1340 | | |
1341 | 1341 | | |
1342 | 1342 | | |
1343 | | - | |
| 1343 | + | |
1344 | 1344 | | |
1345 | 1345 | | |
| 1346 | + | |
| 1347 | + | |
| 1348 | + | |
| 1349 | + | |
| 1350 | + | |
| 1351 | + | |
| 1352 | + | |
| 1353 | + | |
| 1354 | + | |
| 1355 | + | |
| 1356 | + | |
| 1357 | + | |
| 1358 | + | |
| 1359 | + | |
| 1360 | + | |
| 1361 | + | |
| 1362 | + | |
| 1363 | + | |
| 1364 | + | |
| 1365 | + | |
| 1366 | + | |
| 1367 | + | |
| 1368 | + | |
| 1369 | + | |
| 1370 | + | |
| 1371 | + | |
| 1372 | + | |
| 1373 | + | |
| 1374 | + | |
| 1375 | + | |
| 1376 | + | |
| 1377 | + | |
| 1378 | + | |
| 1379 | + | |
1346 | 1380 | | |
1347 | 1381 | | |
1348 | 1382 | | |
| |||
0 commit comments