Skip to content

Commit

Permalink
Merge pull request #3254 from jglick/heavyweight-JENKINS-46652
Browse files Browse the repository at this point in the history
[JENKINS-46652] Check Computer.BUILD permission only on heayweight tasks
  • Loading branch information
jglick committed Mar 9, 2018
2 parents c84cbf3 + 50878a3 commit 1f4f76f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion core/src/main/java/hudson/model/Node.java
Expand Up @@ -62,6 +62,7 @@
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import jenkins.model.Jenkins;
import jenkins.util.SystemProperties;
import jenkins.util.io.OnMaster;
import net.sf.json.JSONObject;
import org.acegisecurity.Authentication;
Expand Down Expand Up @@ -97,6 +98,9 @@ public abstract class Node extends AbstractModelObject implements Reconfigurable

private static final Logger LOGGER = Logger.getLogger(Node.class.getName());

/** @see <a href="https://issues.jenkins-ci.org/browse/JENKINS-46652">JENKINS-46652</a> */
public static /* not final */ boolean SKIP_BUILD_CHECK_ON_FLYWEIGHTS = SystemProperties.getBoolean(Node.class.getName() + ".SKIP_BUILD_CHECK_ON_FLYWEIGHTS", true);

/**
* Newly copied agents get this flag set, so that Jenkins doesn't try to start/remove this node until its configuration
* is saved once.
Expand Down Expand Up @@ -395,7 +399,7 @@ public CauseOfBlockage canTake(Queue.BuildableItem item) {
}

Authentication identity = item.authenticate();
if (!hasPermission(identity,Computer.BUILD)) {
if (!(SKIP_BUILD_CHECK_ON_FLYWEIGHTS && item.task instanceof Queue.FlyweightTask) && !hasPermission(identity, Computer.BUILD)) {
// doesn't have a permission
return CauseOfBlockage.fromMessage(Messages._Node_LackingBuildPermission(identity.getName(), getDisplayName()));
}
Expand Down
Expand Up @@ -134,7 +134,7 @@ public boolean canAccept(WorkChunk c) {
if (c.assignedLabel!=null && !c.assignedLabel.contains(node))
return false; // label mismatch

if (!nodeAcl.hasPermission(item.authenticate(), Computer.BUILD))
if (!(Node.SKIP_BUILD_CHECK_ON_FLYWEIGHTS && item.task instanceof Queue.FlyweightTask) && !nodeAcl.hasPermission(item.authenticate(), Computer.BUILD))
return false; // tasks don't have a permission to run on this node

return true;
Expand Down

0 comments on commit 1f4f76f

Please sign in to comment.