Skip to content

refactor(auth): replace pyOpenSSL with standard ssl and cryptography#16976

Open
nbayati wants to merge 9 commits into
googleapis:mainfrom
nbayati:remove-pyopenssl-dependency
Open

refactor(auth): replace pyOpenSSL with standard ssl and cryptography#16976
nbayati wants to merge 9 commits into
googleapis:mainfrom
nbayati:remove-pyopenssl-dependency

Conversation

@nbayati

@nbayati nbayati commented May 7, 2026

Copy link
Copy Markdown
Contributor

Replace pyOpenSSL with standard library ssl for mTLS transport and update key decryption to use cryptography library.

This change also enhances security for handling private keys by:

  • Using Linux memfd_create for RAM-backed in-memory files to avoid writing secrets to physical storage.
  • Encrypting plaintext keys on-the-fly before writing to fallback temporary files on disk.
  • Securely wiping temporary files with null bytes before deletion.

Fixes #16920
Closes #16921
fixes #17412

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the library to remove the pyOpenSSL dependency, migrating certificate and key management to the cryptography library and Python's standard ssl module. It introduces a secure three-tier fallback strategy for handling mTLS credentials via the new secure_cert_key_paths utility, which utilizes RAM-backed virtual files on Linux to minimize disk exposure. Review feedback suggests simplifying the manual context manager orchestration within this utility and using os.fdopen instead of os.write for more robust and idiomatic file descriptor operations.

Comment thread packages/google-auth/google/auth/transport/_mtls_helper.py
Comment thread packages/google-auth/google/auth/transport/_mtls_helper.py Outdated
Comment thread packages/google-auth/google/auth/transport/_mtls_helper.py Outdated
@parthea

parthea commented May 26, 2026

Copy link
Copy Markdown
Contributor

@nbayati , Please could you address the failing presubmits?

@nbayati nbayati marked this pull request as ready for review June 10, 2026 05:59
@nbayati nbayati requested review from a team as code owners June 10, 2026 05:59
@nbayati nbayati added kokoro:run Add this label to force Kokoro to re-run the tests. kokoro:force-run Add this label to force Kokoro to re-run the tests. and removed kokoro:run Add this label to force Kokoro to re-run the tests. labels Jun 10, 2026
nbayati and others added 4 commits June 10, 2026 06:07
Replace pyOpenSSL with standard library ssl for mTLS transport and update key decryption to use cryptography library.

This change also enhances security for handling private keys by:
- Using Linux memfd_create for RAM-backed in-memory files to avoid writing secrets to physical storage.
- Encrypting plaintext keys on-the-fly before writing to fallback temporary files on disk.
- Securely wiping temporary files with null bytes before deletion.
@nbayati nbayati force-pushed the remove-pyopenssl-dependency branch from f7e5146 to 1704dd8 Compare June 10, 2026 06:11
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jun 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants