Skip to content

Commit

Permalink
JENKINS-73941 - ForceSandbox - Unify logic in Script-Security for red…
Browse files Browse the repository at this point in the history
…ucing techDeb (#952)

* JENKINS-73941 - HideSandbox - Unify all the logic in Script-Security plugin

* JENKINS-73941 - HideSandbox - Unify all the logic in Script-Security plugin - Incremental Script-Security version

* JENKINS-73941 - HideSandbox - Unify all the logic in Script-Security plugin - Incremental Script-Security version

* Update to release

---------

Co-authored-by: Jesse Glick <[email protected]>
  • Loading branch information
jgarciacloudbees and jglick authored Nov 13, 2024
1 parent 3e20a37 commit 5eebd32
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 10 deletions.
2 changes: 1 addition & 1 deletion plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>script-security</artifactId>
<version>1367.vdf2fc45f229c</version>
<version>1369.v9b_98a_4e95b_2d</version>
</dependency>
</dependencies>
</dependencyManagement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,7 @@ public CpsFlowDefinition(String script) throws Descriptor.FormException {

@DataBoundConstructor
public CpsFlowDefinition(String script, boolean sandbox) throws Descriptor.FormException {
if (!sandbox && ScriptApproval.get().isForceSandboxForCurrentUser()) {
// this will end up in the /oops page until https://github.com/jenkinsci/jenkins/pull/9495 is picked up
throw new Descriptor.FormException("Sandbox cannot be disabled. This Jenkins instance has been configured to not " +
"allow regular users to disable the sandbox in pipelines", "sandbox");
}
ScriptApproval.validateSandbox(sandbox);
StaplerRequest req = Stapler.getCurrentRequest();
this.script = sandbox ? script : ScriptApproval.get().configuring(script, GroovyLanguage.get(),
ApprovalContext.create().withCurrentUser().withItemAsKey(req != null ? req.findAncestorObject(Item.class) : null), req == null);
Expand Down Expand Up @@ -192,10 +188,7 @@ public JSON doCheckScriptCompile(@AncestorInPath Item job, @QueryParameter Strin

@Restricted(NoExternalUse.class) // stapler
public boolean shouldHideSandbox(@CheckForNull CpsFlowDefinition instance) {
// sandbox checkbox is shown to admins even if the global configuration says otherwise
// it's also shown when sandbox == false, so regular users can enable it
return ScriptApproval.get().isForceSandboxForCurrentUser()
&& (instance == null || instance.sandbox);
return ScriptApproval.shouldHideSandbox(instance, CpsFlowDefinition::isSandbox);
}

}
Expand Down

0 comments on commit 5eebd32

Please sign in to comment.