-
Controls whether the "Use Groovy Sandbox" is shown in pipeline jobs configuration page to users without Overall/Administer permission.
-
This can be used to get a better UX in highly secured environments where all pipelines are required to run in the sandbox (ie. running arbitrary code is never approved)
-
Note that this does not prevent users to configure and run pipelines with sandbox disabled if they create or update jobs by other means (like CLI or HTTP API).
- This option is only hiding the checkbox from the HTML UI
-
\ No newline at end of file
diff --git a/plugin/src/test/java/org/jenkinsci/plugins/workflow/cps/CpsFlowDefinitionTest.java b/plugin/src/test/java/org/jenkinsci/plugins/workflow/cps/CpsFlowDefinitionTest.java
index 3ec930cc7..cb68e9dbe 100644
--- a/plugin/src/test/java/org/jenkinsci/plugins/workflow/cps/CpsFlowDefinitionTest.java
+++ b/plugin/src/test/java/org/jenkinsci/plugins/workflow/cps/CpsFlowDefinitionTest.java
@@ -24,6 +24,7 @@
package org.jenkinsci.plugins.workflow.cps;
+import hudson.model.Result;
import hudson.util.VersionNumber;
import org.htmlunit.FailingHttpStatusCodeException;
import org.htmlunit.HttpMethod;
@@ -45,12 +46,15 @@
import org.jenkinsci.plugins.scriptsecurity.scripts.languages.GroovyLanguage;
import org.jenkinsci.plugins.workflow.cps.config.CPSConfiguration;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
+import org.jenkinsci.plugins.workflow.job.WorkflowRun;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.MockAuthorizationStrategy;
+import org.jvnet.hudson.test.recipes.LocalData;
+import java.io.File;
import java.nio.charset.StandardCharsets;
import java.util.List;
@@ -59,8 +63,6 @@
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.not;
-import static org.hamcrest.Matchers.notNullValue;
-import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -316,7 +318,7 @@ public void cpsScriptSandboxHide() throws Exception {
}
// non-admins cannot see the sandbox checkbox in jobs if hideSandbox is On globally
- CPSConfiguration.get().setHideSandbox(true);
+ ScriptApproval.get().setForceSandbox(true);
{
HtmlForm config = wcDevel.getPage(p, "configure").getFormByName("config");
assertThat(config.getVisibleText(), not(containsStringIgnoringCase("Use Groovy Sandbox")));
@@ -328,7 +330,7 @@ public void cpsScriptSandboxHide() throws Exception {
}
// admins can always see the sandbox checkbox
- CPSConfiguration.get().setHideSandbox(false);
+ ScriptApproval.get().setForceSandbox(false);
wcDevel.login("admin");
{
HtmlForm config = wcDevel.getPage(p, "configure").getFormByName("config");
@@ -336,7 +338,7 @@ public void cpsScriptSandboxHide() throws Exception {
}
// even when set to hide globally
- CPSConfiguration.get().setHideSandbox(true);
+ ScriptApproval.get().setForceSandbox(true);
{
HtmlForm config = wcDevel.getPage(p, "configure").getFormByName("config");
assertThat(config.getVisibleText(), containsStringIgnoringCase("Use Groovy Sandbox"));
@@ -370,4 +372,67 @@ public void cpsScriptSandboxHide() throws Exception {
}
}
+
+ @Test
+ public void cpsConfigurationSandboxToScriptApprovalSandbox() throws Exception{
+ //Deprecated CPSConfiguration should update ScriptApproval forceSandbox logic to keep casc compatibility
+ ScriptApproval.get().setForceSandbox(false);
+
+ CPSConfiguration.get().setHideSandbox(true);
+ assertTrue(ScriptApproval.get().isForceSandbox());
+
+ ScriptApproval.get().setForceSandbox(false);
+ assertFalse(CPSConfiguration.get().isHideSandbox());
+ }
+
+ @Test
+ public void cpsScriptSignatureException() throws Exception {
+ ScriptApproval.get().setForceSandbox(false);
+ WorkflowJob p = jenkins.createProject(WorkflowJob.class);
+ String script = "jenkins.model.Jenkins.instance";
+ p.setDefinition(new CpsFlowDefinition(script, true));
+ WorkflowRun b = jenkins.assertBuildStatus(Result.FAILURE, p.scheduleBuild2(0).get());
+ jenkins.assertLogContains("Scripts not permitted to use staticMethod jenkins.model.Jenkins getInstance. "
+ + "Administrators can decide whether to approve or reject this signature.", b);
+
+ ScriptApproval.get().setForceSandbox(true);
+ b = jenkins.assertBuildStatus(Result.FAILURE, p.scheduleBuild2(0).get());
+ jenkins.assertLogContains("Scripts not permitted to use staticMethod jenkins.model.Jenkins getInstance. "
+ + "Script signature is not in the default whitelist.", b);
+ }
+
+ @Test
+ @LocalData
+ public void cpsLoadConfiguration() throws Exception {
+ //CPSConfiguration file containing