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 crumb issue with Jenkins 2.176.2+/2.186+ #70

Merged

Conversation

tbouffard
Copy link
Contributor

@tbouffard tbouffard commented Oct 10, 2019

Always pass the JSESSIONID in addition to the crumb
See https://jenkins.io/security/advisory/2019-07-17/#SECURITY-626

closes #67

Implementation note
I am not used to playing with AutoValue and jclouds, so don't hesitate to spot any bad practices on these areas 😸


private static String sessionIdCookie(HttpResponse input) {
return input.getHeaders().get(HttpHeaders.SET_COOKIE).stream()
.filter(c -> c.startsWith("JSESSIONID"))
Copy link
Owner

Choose a reason for hiding this comment

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

Can we turn JSESSIONID into a static final String constant and put it somewhere that makes the most sense? Believe there is a static-variables class around here somewhere

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I found the com.cdancy.jenkins.rest.JenkinsConstants class. Is that the one you had in mind?

Copy link
Owner

Choose a reason for hiding this comment

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

Yeah exactly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done, see d0a16f2

@tbouffard
Copy link
Contributor Author

tbouffard commented Oct 11, 2019

Thanks @cdancy for the quick feedbacks, I will manage them soon
I have done some extra testing and the current implementation seems not working anymore after my 2 last commits. I am going to review them and come back to you when the integration tests pass

@cdancy
Copy link
Owner

cdancy commented Oct 11, 2019

@tbouffard sounds good and thanks! Let me know if you need any help one way or another.

@cdancy
Copy link
Owner

cdancy commented Oct 31, 2019

@tbouffard have you tested the impl yet? Are you happy with things? Any gotchas one way or another?

@tbouffard
Copy link
Contributor Author

tbouffard commented Oct 31, 2019

I didn't have much time to work on this PR except to ensure that I have a correct Jenkins instance for integration tests (see #72).
I still have a failling integration test (and dependent tests are then skipped) when running Jenkins 2.176.1 with the new implementation
I currently can't provide the error here but I will share it on the begining of next week

@tbouffard
Copy link
Contributor Author

I have some time today to work on this. The issue I mentionned in #70 (comment) was the one seen on #75
Here my tests results as of today

On Jenkins 2.164.3 without fix (master commit 401f4f3)
no CSRF: a single test is failing when retrieving the Crumb. This is the normal behaviour as in this case, no Crumb is available

java.lang.AssertionError: expected object to not be null
	at org.testng.Assert.fail(Assert.java:93)
	at org.testng.Assert.assertNotNull(Assert.java:422)
	at org.testng.Assert.assertNotNull(Assert.java:407)
	at com.cdancy.jenkins.rest.features.CrumbIssuerApiLiveTest.testGetCrumb(CrumbIssuerApiLiveTest.java:34)
16:43:47.721 [Test worker] DEBUG org.jclouds.rest.internal.InvokeHttpMethod - >> invoking crumb-issuer:crumb
16:43:47.726 [Test worker] DEBUG org.jclouds.http.internal.JavaUrlHttpCommandExecutorService - Sending request 559347004: GET http://127.0.0.1:8080/crumbIssuer/api/xml?xpath=concat%28//crumbRequestField,%22%3A%22,//crumb%29 HTTP/1.1
16:43:47.726 [Test worker] DEBUG jclouds.headers - >> GET http://127.0.0.1:8080/crumbIssuer/api/xml?xpath=concat%28//crumbRequestField,%22%3A%22,//crumb%29 HTTP/1.1
16:43:47.727 [Test worker] DEBUG jclouds.headers - >> Accept: text/plain
16:43:47.727 [Test worker] DEBUG jclouds.headers - >> Authorization: Basic YWRtaW46YWRtaW4=
16:43:47.820 [Test worker] DEBUG org.jclouds.http.internal.JavaUrlHttpCommandExecutorService - Receiving response 559347004: HTTP/1.1 404 Not Found
16:43:47.820 [Test worker] DEBUG jclouds.headers - << HTTP/1.1 404 Not Found
16:43:47.820 [Test worker] DEBUG jclouds.headers - << Server: Jetty(9.4.z-SNAPSHOT)
16:43:47.821 [Test worker] DEBUG jclouds.headers - << X-Content-Type-Options: nosniff
16:43:47.821 [Test worker] DEBUG jclouds.headers - << Date: Thu, 12 Dec 2019 15:43:47 GMT

2.164.3 with the fix (commit d0a16f2)

  • with CSRF: OK
  • without CSRF: OK (same Crumb test failing as without the fix)

2.190.3 with the fix (commit d0a16f2)

  • with CSRF: sessionId is not passed. This is strange I remember this worked with 2.176.3. New tests required
  • without CSRF: OK (same Crumb test failing as without the fix)

@cdancy
Copy link
Owner

cdancy commented Dec 12, 2019

@tbouffard let me know if you need any help here. Would be great to have this in and "just work" across the board.

@tbouffard tbouffard marked this pull request as ready for review December 13, 2019 09:24
@tbouffard
Copy link
Contributor Author

tbouffard commented Dec 13, 2019

@cdancy I have finally figured out the cause of the failure with Jenkins 2.176.2+, see
5d70101, so this should be ok now on Jenkins 2.190.3 with CSRF protection enabled

Can you run the tests on your side to ensure I didn't miss anything with my own testing?
I can also rebase the PR on the latest master commit to make Travis run integration tests and then update the Jenkins version to the latest available LTS.

@cdancy
Copy link
Owner

cdancy commented Dec 13, 2019

@tbouffard yes please rebase off of master and I'll run things as here as well.

My tests shown that there is no JSESSIONID in Jenkins 2.176.1 and as we
cannot set cookie with null value, put an empty String in that case
This avoids passing empty cookie in requestq
Fix regression introduced by 9d991e2
@tbouffard tbouffard force-pushed the issue_crumb_and_sessionId_with_Jenkins_2.176.2+ branch from 5d70101 to 0fe36fb Compare December 13, 2019 14:24
@tbouffard
Copy link
Contributor Author

Rebase done. If Travis tests pass, I will bump the jenkins version used in the Docker container to the latest one (2.190.3)

@cdancy cdancy self-requested a review December 16, 2019 16:49
Copy link
Owner

@cdancy cdancy left a comment

Choose a reason for hiding this comment

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

LGTM

@cdancy cdancy merged commit 6077aa4 into cdancy:master Dec 16, 2019
@cdancy
Copy link
Owner

cdancy commented Dec 16, 2019

@tbouffard thanks for the fix/enhancement!

@cdancy cdancy added this to the v0.0.22 milestone Dec 16, 2019
@cdancy
Copy link
Owner

cdancy commented Dec 16, 2019

@tbouffard release v0.0.22 has been released with this change.

@tbouffard
Copy link
Contributor Author

@cdancy Great and thanks for the support. Very helpful to make this contribution complete. I hope to be quicker next time 😄

@tbouffard tbouffard deleted the issue_crumb_and_sessionId_with_Jenkins_2.176.2+ branch December 17, 2019 13:06
@cdancy
Copy link
Owner

cdancy commented Dec 17, 2019

@tbouffard no worries. We all have lives and day-jobs to attend to. Just happy for the contribution either way.

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

Successfully merging this pull request may close these issues.

POST API calls '403 No valid crumb was included in the request'
3 participants