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

[JENKINS-18114] Fixing CLI crumbs #3019

Merged
merged 4 commits into from
Sep 22, 2017

Conversation

jglick
Copy link
Member

@jglick jglick commented Sep 11, 2017

Amends #2315. The CLI client was already asking for a crumb. But Jenkins was not properly serving X-Jenkins alongside it, so it did not pass it back; but then Jenkins forgave it anyway! Simpler and clearer to just serve the expected header.

Proposed changelog entries

None should be needed.

@reviewbybees

…ctually serve it, from CrumbIssuer.RestrictedApi.
@jglick jglick requested a review from daniel-beck September 11, 2017 20:47
@ghost
Copy link

ghost commented Sep 11, 2017

This pull request originates from a CloudBees employee. At CloudBees, we require that all pull requests be reviewed by other CloudBees employees before we seek to have the change accepted. If you want to learn more about our process please see this explanation.

@daniel-beck
Copy link
Member

Test failures seem related.

…tuff better checked by authentication(), and was failing since this fake client was not passing a crumb.
@jglick
Copy link
Member Author

jglick commented Sep 13, 2017

CLIActionTest.serveCliActionToAnonymousUserWithoutPermissions was meaningless. But CLIActionTest.authentication was real: the proposed change actually breaks the (admittedly dubious) use case of running CLI commands as anonymous when anonymous has no Overall/Read.

Perhaps we need to return to the crumb exclusion, and just drop the client code to send the crumb, which adds to the round-trip time; is not needed when there is an exclusion; and in master does not even work anyway.

@jglick
Copy link
Member Author

jglick commented Sep 13, 2017

(Note that FullDuplexHttpStream.tryToResolveRedirects does not work for an anonymous user without read access either, but this is just a convenience in case you have a noncanonical Jenkins URL.)

@daniel-beck
Copy link
Member

admittedly dubious

This may be a symptom of a larger possible problem: Unless we want all UnprotectedRootActions to be CrumbExclusions, there probably should be a way for unauthorized users to get a crumb. Searching I now only found JENKINS-31515, but it's still something we should think about.

@jglick
Copy link
Member Author

jglick commented Sep 13, 2017

I do not think we can (safely) create a crumb for anonymous users. There is JENKINS-22474 which could allow us to delete most CrumbExclusions for RootActions. Arguably UnprotectedRootActions should also be excluded automatically.

…ccess, and just let the client stop asking for a crumb.
…ned demonstration of the HTTP Duplex transport.
@@ -549,7 +549,7 @@ public boolean verify(String s, SSLSession sslSession) {
for (Handler h : Logger.getLogger("").getHandlers()) {
h.setLevel(level);
}
for (Logger logger : new Logger[] {LOGGER, PlainCLIProtocol.LOGGER, Logger.getLogger("org.apache.sshd")}) { // perhaps also Channel
for (Logger logger : new Logger[] {LOGGER, FullDuplexHttpStream.LOGGER, PlainCLIProtocol.LOGGER, Logger.getLogger("org.apache.sshd")}) { // perhaps also Channel
Copy link
Member Author

Choose a reason for hiding this comment

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

Generally useful.

@@ -79,11 +85,10 @@ public FullDuplexHttpStream(URL base, String relativeTarget, String authorizatio

URL target = new URL(this.base, relativeTarget);

CrumbData crumbData = new CrumbData();
Copy link
Member Author

Choose a reason for hiding this comment

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

As described in PR comments, this did not previously work, and given the existence of an exclusion, was not necessary anyway.

@@ -193,6 +193,7 @@ public void validateCrumb(StaplerRequest request, String submittedCrumb) {
}

@Override public void doXml(StaplerRequest req, StaplerResponse rsp, @QueryParameter String xpath, @QueryParameter String wrapper, @QueryParameter String tree, @QueryParameter int depth) throws IOException, ServletException {
setHeaders(rsp);
Copy link
Member Author

Choose a reason for hiding this comment

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

Makes the crumb code work. No longer necessary for this PR, which deletes the code that called this endpoint from the context of the CLI (would make that code in old clients start working, which is fine but unnecessary); but generally seems wise to keep the behavior of RestrictedApi consistent with Api.

@@ -122,16 +117,6 @@ public void serveCliActionToAnonymousUserWithoutPermissions() throws Exception {
JenkinsRule.WebClient wc = j.createWebClient();
// The behavior changed due to SECURITY-192. index page is no longer accessible to anonymous
wc.assertFails("cli", HttpURLConnection.HTTP_FORBIDDEN);
// so we check the access by emulating the CLI connection post request
Copy link
Member Author

Choose a reason for hiding this comment

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

Actually would pass again given the restored crumb exclusion, but is anyway redundant given more comprehensive, and realistic, tests later added to the CLI system.

public LoggerRule logging = new LoggerRule().record(FullDuplexHttpService.class, Level.FINE).record(FullDuplexHttpStream.class, Level.FINE);

@Test
public void smokes() throws Exception {
Copy link
Member Author

Choose a reason for hiding this comment

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

Just for fun!


@Test
public void smokes() throws Exception {
logging.record("org.eclipse.jetty", Level.ALL);
Copy link
Member Author

Choose a reason for hiding this comment

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

I have been investigating failures of HTTP Duplex to work in test cases using Jetty 9.4.x. Symptoms are typically a failure to connect the upload side, as in JENKINS-43666.

Copy link
Member Author

Choose a reason for hiding this comment

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

(Starting from #2959 which picks up jenkinsci/jenkins-test-harness#63. Seems unrelated to #3011.)

Copy link
Member

Choose a reason for hiding this comment

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

How verbose is this? Intended to stay on ALL?

Copy link
Member Author

Choose a reason for hiding this comment

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

In practice Jetty logs everything at FINE.

@jglick jglick added the needs-more-reviews Complex change, which would benefit from more eyes label Sep 13, 2017
@jglick
Copy link
Member Author

jglick commented Sep 13, 2017

@reviewbybees done

@ghost
Copy link

ghost commented Sep 15, 2017

This pull request originates from a CloudBees employee. At CloudBees, we require that all pull requests be reviewed by other CloudBees employees before we seek to have the change accepted. If you want to learn more about our process please see this explanation.

Copy link
Member

@oleg-nenashev oleg-nenashev left a comment

Choose a reason for hiding this comment

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

🐝 IIUC

@oleg-nenashev oleg-nenashev added ready-for-merge The PR is ready to go, and it will be merged soon if there is no negative feedback and removed needs-more-reviews Complex change, which would benefit from more eyes labels Sep 15, 2017
@oleg-nenashev oleg-nenashev merged commit 5e84c54 into jenkinsci:master Sep 22, 2017
@jglick jglick deleted the CLI-crumb-JENKINS-18114 branch September 25, 2017 13:35
LinuxSuRen pushed a commit to suren-jenkins/jenkins that referenced this pull request Sep 29, 2017
* [JENKINS-18114] The CLI client already asks for a crumb; we just to actually serve it, from CrumbIssuer.RestrictedApi.

* serveCliActionToAnonymousUserWithoutPermissions() was checking some stuff better checked by authentication(), and was failing since this fake client was not passing a crumb.

* Bring back CliCrumbExclusion, needed for anonymous use with no read access, and just let the client stop asking for a crumb.

* Added FullDuplexHttpServiceTest; useful to have a simple, self-contained demonstration of the HTTP Duplex transport.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-for-merge The PR is ready to go, and it will be merged soon if there is no negative feedback
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants