Skip to content

Conversation

@sfc-gh-snoonan
Copy link
Contributor

Our current python connector does not support a configuration with intermediate certificates in a trust store as roots of trust. This is allowed by RFCs; the root does not need to be self signed, and this is the behavior we have in our Go client.

These changes enable partial chain validation to normalize behavior across clients.

  • I am adding a new automated test(s) to verify correctness of my new code
  • I am adding new logging messages
  • I am adding a new telemetry message
  • I am modifying authorization mechanisms
  • I am adding new credentials
  • I am modifying OCSP code
  • I am adding a new dependency

@sfc-gh-snoonan sfc-gh-snoonan requested a review from a team as a code owner September 5, 2025 16:46
Copy link
Contributor

@sfc-gh-jkasten sfc-gh-jkasten left a comment

Choose a reason for hiding this comment

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

Thanks!

LGTM - though it has been many years since I wrote production Python.

Comment on lines +82 to +85
try:
ctx.verify_mode = ssl.CERT_REQUIRED
except Exception:
pass
Copy link
Contributor

Choose a reason for hiding this comment

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

optional: According to the documentation, PROTOCOL_TLS_CLIENT enables CERT_REQUIRED and check_hostname by default.
https://docs.python.org/3/library/ssl.html#ssl.PROTOCOL_TLS_CLIENT

I guess I would either be explicit with both options or maybe drop this addtional code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As it is today, we do hostname verification in urllib3 rather than the SSLContext. (src/snowflake/connector/vendored/urllib3/util/ssl_.py). We might want to change that, but one thing at a time I think. This is another stdlib vs PyOpenSSL distinction. The context here just maps to the OpenSSL method used; we could probably get away with just PROTOCOL_TLS. They both map to OpenSSL.SSL.SSLv23_METHOD.

Yes, this is janky.

Comment on lines +68 to +73
from OpenSSL import crypto as _crypto

if hasattr(_crypto, "X509StoreFlags") and hasattr(
_crypto.X509StoreFlags, "PARTIAL_CHAIN"
):
store.set_flags(_crypto.X509StoreFlags.PARTIAL_CHAIN)
Copy link
Contributor

Choose a reason for hiding this comment

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

Note/optional: There is an ssl.VERIFY_X509_PARTIAL_CHAIN which can be set on the SSLContext directly under SSLContext.verify_flags I think? (Version 3.10)

It might simplify some of this code. My apologies if I missed something.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is PyOpenSSL versus the stdlib. We're working with pretty old code here, so I try all the things :-).

@sfc-gh-snoonan sfc-gh-snoonan added the DO_NOT_PORT_CHANGES_TO_SP Add this label when changes in this PR do not need to be port to SP connector label Sep 8, 2025
Copy link
Collaborator

@sfc-gh-pczajka sfc-gh-pczajka left a comment

Choose a reason for hiding this comment

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

Left two nits

@sfc-gh-snoonan sfc-gh-snoonan merged commit 3838fb0 into main Sep 18, 2025
96 of 100 checks passed
@sfc-gh-snoonan sfc-gh-snoonan deleted the SNOW-2176203-partial-chains branch September 18, 2025 14:05
@github-actions github-actions bot locked and limited conversation to collaborators Sep 18, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

DO_NOT_PORT_CHANGES_TO_SP Add this label when changes in this PR do not need to be port to SP connector

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants