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

Named parameters are not supported in the sandbox

      Using a DSL in a workflow script that has a method with named params e.g.

      Object inside(String link = null, Closure body)
      

      Calling it in the workflow (with sandbox mode turned ON) results in the following exception:

      org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use method groovy.lang.GroovyObject invokeMethod java.lang.String java.lang.Object (DSL inside java.util.LinkedHashMap com.cloudbees.groovy.cps.impl.CpsClosure)
      	at org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.StaticWhitelist.rejectMethod(StaticWhitelist.java:155)
      	at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:77)
      	at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:60)
      

      Quote from Jesse:

      Not sure offhand how to fix; part of the general “Groovy hell” that is SandboxInterceptor: we get a high-level representation of a call point, and have to duplicate an incredibly complex system in Groovy to translate that to an actual Java method call.

          [JENKINS-28170] Named parameters are not supported in the sandbox

          Andrew Bayer added a comment -

          Possibly related to JENKINS-34741?

          Andrew Bayer added a comment - Possibly related to JENKINS-34741 ?

          Jesse Glick added a comment -

          Doubtful.

          Jesse Glick added a comment - Doubtful.

          Andrew Bayer added a comment -

          An update as of workflow-cps 2.39 - the following fails:

          def inside(String name = null, Closure body) {
              echo "name? ${name}"
              body.call()
          }
          
          inside(name: "banana") {
              echo "is body"
          }
          

          But in a different way - instead, it's falling through to java.lang.NoSuchMethodError: No such DSL method 'inside' found among steps ... rather than barfing in sandbox land. That, however, is ok, I think - named parameters for Groovy methods don't work in the normal Groovy context (if you call foo(param: value), that actually calls foo(Map) and it's the method's responsibility to do something with the map). Since there's no inside(Map, Closure) method defined, the dispatch is working properly and looking for a Step (or a metastep-enabled Describable and failing to find one.

          Debating whether to add a test verifying the lack of a RejectedAccessException, though.

          Andrew Bayer added a comment - An update as of workflow-cps 2.39 - the following fails: def inside( String name = null , Closure body) { echo "name? ${name}" body.call() } inside(name: "banana" ) { echo "is body" } But in a different way - instead, it's falling through to java.lang.NoSuchMethodError: No such DSL method 'inside' found among steps ... rather than barfing in sandbox land. That, however, is ok, I think - named parameters for Groovy methods don't work in the normal Groovy context (if you call foo(param: value) , that actually calls foo(Map) and it's the method's responsibility to do something with the map). Since there's no inside(Map, Closure) method defined, the dispatch is working properly and looking for a Step (or a metastep-enabled Describable and failing to find one. Debating whether to add a test verifying the lack of a RejectedAccessException , though.

            Unassigned Unassigned
            tfennelly Tom FENNELLY
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: