[Experiment] feat(auth): backport rsa by daniel-sanche · Pull Request #16788 · googleapis/google-cloud-python · GitHub
Skip to content

[Experiment] feat(auth): backport rsa#16788

Draft
daniel-sanche wants to merge 3 commits intomainfrom
auth_backport_rsa
Draft

[Experiment] feat(auth): backport rsa#16788
daniel-sanche wants to merge 3 commits intomainfrom
auth_backport_rsa

Conversation

@daniel-sanche
Copy link
Copy Markdown
Contributor

Test revert commits that removed rsa, to see if the build passes

This will not be released, but may be useful as a temporary branch

@daniel-sanche daniel-sanche added the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Apr 24, 2026
Copy link
Copy Markdown
Contributor

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

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 cryptography module to simplify RSA signer and verifier implementations by replacing dynamic wrapper classes with direct aliasing based on library availability. It also promotes the rsa library to a core dependency, removes associated deprecation warnings, and streamlines the CI configuration. The review feedback identifies several critical issues: a potential side-effect in noxfile.py caused by in-place list modification, a regression in the test runner's ability to accept positional arguments, and a packaging bug in setup.py resulting in a nested dependency list. Additionally, improvements were suggested for type-hinting specificity and minor documentation grammar.

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.

high

Removing .copy() causes ALL_PYTHON to be a reference to the UNIT_TEST_PYTHON_VERSIONS list. The subsequent extend call on line 46 will modify the global UNIT_TEST_PYTHON_VERSIONS list in place, which can lead to unexpected side effects in other sessions that rely on the original list.

Suggested change
ALL_PYTHON = UNIT_TEST_PYTHON_VERSIONS
ALL_PYTHON = UNIT_TEST_PYTHON_VERSIONS.copy()

"tests",
"tests_async",
*session.posargs,
)
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.

high

The removal of *session.posargs prevents users from passing additional arguments to pytest (e.g., to run specific tests or use specific flags). This is a regression in developer experience.

Suggested change
)
*session.posargs,
)

enterprise_cert_extra_require = ["cryptography", "pyopenssl"]

pyopenssl_extra_require = ["pyopenssl>=20.0.0"]
pyopenssl_extra_require = ["pyopenssl>=20.0.0", cryptography_base_require]
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.

high

This creates a nested list: ["pyopenssl>=20.0.0", ["cryptography >= 38.0.3"]]. Setuptools expects a flat list of requirement strings. You should unpack cryptography_base_require using the * operator.

Suggested change
pyopenssl_extra_require = ["pyopenssl>=20.0.0", cryptography_base_require]
pyopenssl_extra_require = ["pyopenssl>=20.0.0", *cryptography_base_require]

Comment on lines +49 to +50
es = None # type: ignore
es256 = None # type: ignore
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.

medium

According to the general rules, when assigning None to a variable in an except ImportError block to handle optional dependencies, type: ignore[assignment] should be used instead of a plain type: ignore to be more specific for static analysis tools.

Suggested change
es = None # type: ignore
es256 = None # type: ignore
es = None # type: ignore[assignment]
es256 = None # type: ignore[assignment]
References
  1. When handling an optional dependency by assigning None in an except ImportError block, type: ignore[assignment] is necessary on the assignment to prevent a mypy error, as using typing.TYPE_CHECKING alone is insufficient.

@classmethod
def from_string(cls, public_key: Union[str, bytes]) -> "EsVerifier":
"""Construct a Verifier instance from a public key or public
"""Construct an Verifier instance from a public key or public
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.

medium

Grammar error: 'Verifier' starts with a consonant sound, so 'a' should be used instead of 'an'.

Suggested change
"""Construct an Verifier instance from a public key or public
"""Construct a Verifier instance from a public key or public

Comment on lines +29 to +30
RSASigner = _python_rsa.RSASigner # type: ignore
RSAVerifier = _python_rsa.RSAVerifier # type: ignore
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.

medium

Similar to the rule for optional dependencies, using a more specific type: ignore[assignment] is preferred over a broad type: ignore when aliasing classes from different implementations to the same name, as static analysis tools like mypy will flag the type mismatch on reassignment.

Suggested change
RSASigner = _python_rsa.RSASigner # type: ignore
RSAVerifier = _python_rsa.RSAVerifier # type: ignore
RSASigner = _python_rsa.RSASigner # type: ignore[assignment]
RSAVerifier = _python_rsa.RSAVerifier # type: ignore[assignment]
References
  1. When handling an optional dependency by assigning None in an except ImportError block, type: ignore[assignment] is necessary on the assignment to prevent a mypy error, as using typing.TYPE_CHECKING alone is insufficient.

# TODO(https://github.com/googleapis/google-auth-library-python/issues/1738): Add bounds for pyopenssl dependency.
enterprise_cert_extra_require = ["pyopenssl"]
# TODO(https://github.com/googleapis/google-auth-library-python/issues/1738): Add bounds for cryptography and pyopenssl dependencies.
enterprise_cert_extra_require = ["cryptography", "pyopenssl"]
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.

medium

To satisfy the TODO regarding adding bounds for cryptography, and for consistency with other extra requirements in this file, consider using the cryptography_base_require list.

Suggested change

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not merge Indicates a pull request not ready for merge, due to either quality or timing.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant