Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix values for host, port for proxy connection #1095

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

loelkes
Copy link

@loelkes loelkes commented Dec 11, 2024

This pull request includes a small change to the pyVmomi/SoapAdapter.py file. The change modifies the GetConnection method to correctly set the tunnel using the host and port attributes.

The command mitmproxy --showhost was used to setup a proxy. Tested with python3.11 on macOS 15.1.1.

instance = SmartConnect(
    host="myhostname",
    user="myusername",
    pwd="supersecret",
    disableSslCertValidation=True,
    httpProxyHost="127.0.0.1",
    httpProxyPort=8080,
)

Leads to

pyVmomi.VmomiSupport.vim.fault.HostConnectFault: (vim.fault.HostConnectFault) {
   dynamicType = <unset>,
   dynamicProperty = (vmodl.DynamicProperty) [],
   msg = 'Tunnel connection failed: 502 Bad Gateway',
   faultCause = <unset>,
   faultMessage = (vmodl.LocalizableMessage) []
}

The issue is rooted at:

pyvmomi/pyVmomi/SoapAdapter.py

Lines 1541 to 1542 in 9a8956f

host = getattr(self, 'httpProxyHost', self.host.rsplit(":", 1)[0])
port = getattr(self, 'httpProxyPort', self.port)

pyvmomi/pyVmomi/SoapAdapter.py

Lines 1549 to 1555 in 9a8956f

conn = self.scheme(host=host, port=port, **self.schemeArgs)
if self.is_tunnel:
if hasattr(self, 'sslProxyPath'):
conn.setVcTunnel(self.sslProxyPath)
elif hasattr(self, 'httpProxyHost'):
customHeaders = self._customHeaders if self._customHeaders else {}
conn.set_tunnel(host, port, customHeaders)

Python documentation states

HTTPConnection.set_tunnel(host, port=None, headers=None)
Set the host and the port for HTTP Connect Tunnelling. This allows running the connection through a proxy server.

The host and port arguments specify the endpoint of the tunneled connection (i.e. the address included in the CONNECT request, not the address of the proxy server).

Line 1555 sets the the proxy host and port from line 1541 and 1542 as endpoint, which leads to the Tunnel connection failed: 502 Bad Gateway error. This should be self.host (formatted) and self.port

@vmwclabot
Copy link
Member

@loelkes, you must sign our contributor license agreement before your changes are merged. Click here to sign the agreement. If you are a VMware employee, read this for further instruction.

@loelkes
Copy link
Author

loelkes commented Dec 11, 2024

Fixes bug introduced in 9a8956f

Related #1095 #1085

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants