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

Add option to select http client #133

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

Conversation

lifemanship
Copy link

@lifemanship lifemanship commented Nov 2, 2022

The plugin depends on network library yavijava
https://github.com/jenkinsci/vsphere-cloud-plugin/blob/master/pom.xml#L95-L96
The yavijava supports two types of http clients:
CloseableHttpClient
HttpURLConnection - is default

The HttpURLConnection client's behaviour can be impacted by system-wide cookie handler CookieManager:
https://docs.oracle.com/javase/8/docs/api/java/net/CookieManager.html The major problem is that the CookieManager overlaps logic provided by HttpURLConnection to setup http header Cookie. Global CookieManager know nothing about logic of vsphere-cloud-plugin and fill all http headers with stored cookies, as result vsphere center rejects login requests with error:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<soapenv:Body>
		<soapenv:Fault>
			<faultcode>ServerFaultCode</faultcode>
			<faultstring>Cannot complete login due to an incorrect user name or password.</faultstring>
			<detail>
				<InvalidLoginFault xmlns="urn:vim25" xsi:type="InvalidLogin">
					<faultMessage>
						<key>vim.fault.InvalidLoginWithReason</key>
						<arg>
							<key>1</key>
							<value xsi:type="xsd:string">vim.fault.InvalidLoginReasonRegisterFailed</value>
						</arg>
						<message>Login failed because the session could not be re-registered.</message>
					</faultMessage>
				</InvalidLoginFault>
			</detail>
		</soapenv:Fault>
	</soapenv:Body>
</soapenv:Envelope>

The vsphere-cloud-plugin does not use CookieManager, but there is no guarantee that other plugins avoid it. Example:
https://github.com/jenkinsci/parameterized-remote-trigger-plugin/blob/master/src/main/java/org/jenkinsci/plugins/ParameterizedRemoteTrigger/RemoteBuildConfiguration.java#L158-L159

As workaroud we can switch to CloseableHttpClient http client.
Issue in Jira:
https://issues.jenkins.io/browse/JENKINS-69999

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests - that demonstrates feature works or fixes the issue

@lifemanship lifemanship force-pushed the master branch 4 times, most recently from ec1207e to 1a24523 Compare November 4, 2022 14:34
The plugin depends on network library yavijava
https://github.com/jenkinsci/vsphere-cloud-plugin/blob/master/pom.xml#L95-L96
The yavijava supports two types of http clients:
`CloseableHttpClient`
`HttpURLConnection` - is default
The HttpURLConnection client's behaviour can be impacted by system-wide
cookie handler CookieManager:
https://docs.oracle.com/javase/8/docs/api/java/net/CookieManager.html
The major problem is that the CookieManager overlaps logic provided by
HttpURLConnection to setup http header `Cookie`. Global CookieManager
know nothing about logic of vsphere-cloud-plugin and fill all http
headers with stored cookies, as result vsphere center rejects login
requests with error:
```
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<soapenv:Body>
		<soapenv:Fault>
			<faultcode>ServerFaultCode</faultcode>
			<faultstring>Cannot complete login due to an incorrect user name or password.</faultstring>
			<detail>
				<InvalidLoginFault xmlns="urn:vim25" xsi:type="InvalidLogin">
					<faultMessage>
						<key>vim.fault.InvalidLoginWithReason</key>
						<arg>
							<key>1</key>
							<value xsi:type="xsd:string">vim.fault.InvalidLoginReasonRegisterFailed</value>
						</arg>
						<message>Login failed because the session could not be re-registered.</message>
					</faultMessage>
				</InvalidLoginFault>
			</detail>
		</soapenv:Fault>
	</soapenv:Body>
</soapenv:Envelope>
```

The vsphere-cloud-plugin does not use CookieManager, but there is no
guarantee that other plugins avoid it. Example:
https://github.com/jenkinsci/parameterized-remote-trigger-plugin/blob/master/src/main/java/org/jenkinsci/plugins/ParameterizedRemoteTrigger/RemoteBuildConfiguration.java#L158-L159

As workaroud we can switch to CloseableHttpClient http client.

Issue in Jira:
https://issues.jenkins.io/browse/JENKINS-69999
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.

1 participant