Security: TLS certificate verification is explicitly disabled for vSphere requests#9258
Conversation
The helper creates a requests session with `verify = False` and suppresses TLS warnings. This permits man-in-the-middle interception and credential theft when communicating with vSphere endpoints. Affected files: ssl_helper.py Signed-off-by: tuanaiseo <221258316+tuanaiseo@users.noreply.github.com>
There was a problem hiding this comment.
Code Review
This pull request updates the get_unverified_session function to enable SSL certificate verification by default, allowing users to opt-out via a new insecure parameter. Feedback includes suggestions to rename the function for clarity, apply consistent security patterns to other SSL helpers, support custom CA bundles, and add explicit logging for insecure connections.
| @@ -22,13 +22,14 @@ def get_unverified_context(): | |||
| return context | |||
There was a problem hiding this comment.
While this PR updates get_unverified_session, the get_unverified_context function still provides an unverified SSL context by default. To fully address the security concerns described in the PR title, consider applying a similar insecure opt-in pattern to this function as well to ensure a consistent security posture across all SSL helpers.
| def get_unverified_session(insecure: bool = False): | ||
| """ Get a requests session. | ||
| Certificate verification is enabled by default. | ||
| Set insecure=True only for explicit debug usage. | ||
| @return: a requests session. | ||
| """ | ||
| session = requests.session() | ||
| session.verify = False | ||
| requests.packages.urllib3.disable_warnings() # type: ignore[attr-defined] | ||
| session.verify = not insecure | ||
| if insecure: | ||
| requests.packages.urllib3.disable_warnings() # type: ignore[attr-defined] | ||
| return session |
There was a problem hiding this comment.
The function name get_unverified_session is now a misnomer because the default behavior is to return a verified session. Renaming it to get_requests_session (or similar) would more accurately reflect its updated functionality and improve code clarity. Note that this change will require updating all call sites.
| def get_unverified_session(insecure: bool = False): | |
| """ Get a requests session. | |
| Certificate verification is enabled by default. | |
| Set insecure=True only for explicit debug usage. | |
| @return: a requests session. | |
| """ | |
| session = requests.session() | |
| session.verify = False | |
| requests.packages.urllib3.disable_warnings() # type: ignore[attr-defined] | |
| session.verify = not insecure | |
| if insecure: | |
| requests.packages.urllib3.disable_warnings() # type: ignore[attr-defined] | |
| return session | |
| def get_requests_session(insecure: bool = False): | |
| """ Get a requests session. | |
| Certificate verification is enabled by default. | |
| Set insecure=True only for explicit debug usage. | |
| @return: a requests session. | |
| """ | |
| session = requests.session() | |
| session.verify = not insecure | |
| if insecure: | |
| requests.packages.urllib3.disable_warnings() # type: ignore[attr-defined] | |
| return session |
| session = requests.session() | ||
| session.verify = False | ||
| requests.packages.urllib3.disable_warnings() # type: ignore[attr-defined] | ||
| session.verify = not insecure |
There was a problem hiding this comment.
The PR description mentions the goal to "require a trusted CA bundle". To support environments with private CAs (common in vSphere deployments), it would be beneficial to allow the insecure parameter to accept a path to a CA bundle or to add a dedicated verify parameter that supports both boolean and string paths, similar to how the requests library handles it.
| if insecure: | ||
| requests.packages.urllib3.disable_warnings() # type: ignore[attr-defined] |
There was a problem hiding this comment.
The PR description states that insecure mode should include "prominent warnings and audit logging". However, the current implementation only suppresses the default urllib3 warnings. To align with the security requirements described, consider adding a log message or a visible warning when insecure=True is used.
Problem
The helper creates a requests session with
verify = Falseand suppresses TLS warnings. This permits man-in-the-middle interception and credential theft when communicating with vSphere endpoints.Severity:
highFile:
sky/provision/vsphere/common/ssl_helper.pySolution
Enable certificate verification by default, require a trusted CA bundle, and only allow insecure mode via an explicit opt-in debug flag with prominent warnings and audit logging.
Changes
sky/provision/vsphere/common/ssl_helper.py(modified)Testing