Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-32571

Preserve original security settings after calling CLICommandInvoker.invoke()

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • core

      Calling CLICommandInvoker.invoke() changes Jenkins authorization as a side effect which means that many operations against Jenkins model failed later.

      It is a quite common to prepare data in Jenkins instance, call CLI command and verify the state of Jenkins model later.

      How-to reproduce:
      JenkinsRule j = new JenkinsRule();
      j.createFreeStyleProject("aProject");
      j.jenkins.getItem("aProject").getDisplayName() // OK -> 'aProject'
      CLICommandInvoker command = new CLICommandInvoker(j, "version");
      CLICommandInvoker.Result result = command.authorizedTo(Jenkins.READ).invoke();
      j.jenkins.getItem("aProject").getDisplayName() // Fail -> NPE
      
      How-to fix:
      • in CLICommandInvoker.setAuth() save current SecurityRealm, AuthorizationStrategy and thread's SecurityContext
      • in CLICommandInvoker.invoke() after result = new Result(returnCode, out, err); call a new method restoreAuth()
      • implement a new method CLICommandInvoker.restoreAuth() where SecurityRealm, AuthorizationStrategy and thread's SecurityContext is set to previously saved values

          [JENKINS-32571] Preserve original security settings after calling CLICommandInvoker.invoke()

          PR sent.

          Pavel Janoušek added a comment - PR sent.

          Code changed in jenkins
          User: Ing. Pavel Janousek
          Path:
          src/main/java/hudson/cli/CLICommandInvoker.java
          http://jenkins-ci.org/commit/jenkins-test-harness/07e5d6ab711786b1cf02d13e03abbc14c4ca6dd9
          Log:
          JENKINS-32571 Preserve original security settings after calling CommandInvoker.invoke()

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Ing. Pavel Janousek Path: src/main/java/hudson/cli/CLICommandInvoker.java http://jenkins-ci.org/commit/jenkins-test-harness/07e5d6ab711786b1cf02d13e03abbc14c4ca6dd9 Log: JENKINS-32571 Preserve original security settings after calling CommandInvoker.invoke()

          Code changed in jenkins
          User: Jesse Glick
          Path:
          src/main/java/hudson/cli/CLICommandInvoker.java
          http://jenkins-ci.org/commit/jenkins-test-harness/e1d92561782987d8a6b51285a81790bd52f378ec
          Log:
          Merge pull request #6 from pjanouse/JENKINS-32571-invoke

          [FIXED JENKINS-32571] Preserve original security settings after calling CommandInvoker.invoke()

          Compare: https://github.com/jenkinsci/jenkins-test-harness/compare/1d32b054ae59...e1d925617829

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Jesse Glick Path: src/main/java/hudson/cli/CLICommandInvoker.java http://jenkins-ci.org/commit/jenkins-test-harness/e1d92561782987d8a6b51285a81790bd52f378ec Log: Merge pull request #6 from pjanouse/ JENKINS-32571 -invoke [FIXED JENKINS-32571] Preserve original security settings after calling CommandInvoker.invoke() Compare: https://github.com/jenkinsci/jenkins-test-harness/compare/1d32b054ae59...e1d925617829

          Code changed in jenkins
          User: Ing. Pavel Janousek
          Path:
          src/main/java/hudson/cli/CLICommandInvoker.java
          http://jenkins-ci.org/commit/jenkins-test-harness/167cd62c915d9d5eff67870208c5e6f7efb0f3a2
          Log:
          JENKINS-32571 Follow-up & clean-up

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Ing. Pavel Janousek Path: src/main/java/hudson/cli/CLICommandInvoker.java http://jenkins-ci.org/commit/jenkins-test-harness/167cd62c915d9d5eff67870208c5e6f7efb0f3a2 Log: JENKINS-32571 Follow-up & clean-up

          Code changed in jenkins
          User: Robert Sandell
          Path:
          src/main/java/hudson/cli/CLICommandInvoker.java
          http://jenkins-ci.org/commit/jenkins-test-harness/cd049fc36de74e99287a9696b6ea9409ffff62c9
          Log:
          Merge pull request #15 from pjanouse/JENKINS-32571-cleanup

          JENKINS-32571 Follow-up & clean-up

          Compare: https://github.com/jenkinsci/jenkins-test-harness/compare/e27cb2ecb145...cd049fc36de7

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Robert Sandell Path: src/main/java/hudson/cli/CLICommandInvoker.java http://jenkins-ci.org/commit/jenkins-test-harness/cd049fc36de74e99287a9696b6ea9409ffff62c9 Log: Merge pull request #15 from pjanouse/ JENKINS-32571 -cleanup JENKINS-32571 Follow-up & clean-up Compare: https://github.com/jenkinsci/jenkins-test-harness/compare/e27cb2ecb145...cd049fc36de7

            pajasoft Pavel Janoušek
            pajasoft Pavel Janoušek
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: