Skip to content

Commit

Permalink
Merge pull request #3361 from agentgonzo/JENKINS-50296-RemotingAsSystem
Browse files Browse the repository at this point in the history
[JENKINS-50296] Run ThreadPoolForRemoting as SYSTEM
  • Loading branch information
jtnord committed Apr 5, 2018
2 parents 6526181 + 7d13e17 commit 54325b1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
9 changes: 6 additions & 3 deletions core/src/main/java/hudson/model/Computer.java
Expand Up @@ -30,7 +30,6 @@
import hudson.Extension;
import hudson.Launcher.ProcStarter;
import hudson.slaves.Cloud;
import jenkins.util.SystemProperties;
import hudson.Util;
import hudson.cli.declarative.CLIResolver;
import hudson.console.AnnotatedLargeText;
Expand Down Expand Up @@ -65,7 +64,9 @@
import hudson.util.NamingThreadFactory;
import jenkins.model.Jenkins;
import jenkins.util.ContextResettingExecutorService;
import jenkins.util.SystemProperties;
import jenkins.security.MasterToSlaveCallable;
import jenkins.security.ImpersonatingExecutorService;

import org.apache.commons.lang.StringUtils;
import org.jenkins.ui.icon.Icon;
Expand Down Expand Up @@ -1352,9 +1353,11 @@ public String call() throws IOException {
}

public static final ExecutorService threadPoolForRemoting = new ContextResettingExecutorService(
new ImpersonatingExecutorService(
Executors.newCachedThreadPool(
new ExceptionCatchingThreadFactory(
new NamingThreadFactory(new DaemonThreadFactory(), "Computer.threadPoolForRemoting"))));
new ExceptionCatchingThreadFactory(
new NamingThreadFactory(
new DaemonThreadFactory(), "Computer.threadPoolForRemoting"))), ACL.SYSTEM));

//
//
Expand Down
16 changes: 16 additions & 0 deletions core/src/test/java/hudson/model/ComputerTest.java
@@ -1,9 +1,18 @@
package hudson.model;

import hudson.FilePath;
import hudson.security.ACL;
import jenkins.model.Jenkins;
import org.acegisecurity.Authentication;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;

import java.io.File;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;

/**
* @author Kohsuke Kawaguchi
Expand All @@ -28,4 +37,11 @@ public void testRelocate() throws Exception {
dir.deleteRecursive();
}
}

@Issue("JENKINS-50296")
@Test
public void testThreadPoolForRemotingActsAsSystemUser() throws InterruptedException, ExecutionException {
Future<Authentication> job = Computer.threadPoolForRemoting.submit(Jenkins::getAuthentication);
assertThat(job.get(), is(ACL.SYSTEM));
}
}

0 comments on commit 54325b1

Please sign in to comment.