-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
822ece7
commit 18b3121
Showing
8 changed files
with
150 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
.../com/cloudbees/jenkins/plugins/sshcredentials/impl/BasicSSHUserPrivateKeyTest_SEC440.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.cloudbees.jenkins.plugins.sshcredentials.impl; | ||
|
||
import com.cloudbees.hudson.plugins.folder.Folder; | ||
import hudson.FilePath; | ||
import hudson.cli.CLICommandInvoker; | ||
import hudson.cli.UpdateJobCommand; | ||
import hudson.model.Job; | ||
import jenkins.model.Jenkins; | ||
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.recipes.LocalData; | ||
|
||
import static hudson.cli.CLICommandInvoker.Matcher.failedWith; | ||
import static hudson.cli.CLICommandInvoker.Matcher.succeeded; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.containsString; | ||
import static org.hamcrest.Matchers.not; | ||
|
||
//TODO merge it into BasicSSHUserPrivateKeyTest after security patch | ||
public class BasicSSHUserPrivateKeyTest_SEC440 { | ||
|
||
@Rule | ||
public JenkinsRule r = new JenkinsRule(); | ||
|
||
{r.timeout = 0;} | ||
|
||
@Test | ||
@Issue("SECURITY-440") | ||
@LocalData("updateJob") | ||
public void userWithoutRunScripts_cannotMigrateDangerousPrivateKeySource() throws Exception { | ||
Folder folder = r.jenkins.createProject(Folder.class, "folder1"); | ||
|
||
FilePath updateFolder = r.jenkins.getRootPath().child("update_folder.xml"); | ||
|
||
{ // as user with just configure, you cannot migrate | ||
CLICommandInvoker.Result result = new CLICommandInvoker(r, new UpdateJobCommand()) | ||
.authorizedTo(Jenkins.READ, Job.READ, Job.CONFIGURE) | ||
.withStdin(updateFolder.read()) | ||
.invokeWithArgs("folder1"); | ||
|
||
assertThat(result.stderr(), containsString("user is missing the Overall/RunScripts permission")); | ||
assertThat(result, failedWith(-1)); | ||
|
||
// config file not touched | ||
String configFileContent = folder.getConfigFile().asString(); | ||
assertThat(configFileContent, not(containsString("FileOnMasterPrivateKeySource"))); | ||
assertThat(configFileContent, not(containsString("BasicSSHUserPrivateKey"))); | ||
} | ||
{ // but as admin with RUN_SCRIPTS, you can | ||
CLICommandInvoker.Result result = new CLICommandInvoker(r, new UpdateJobCommand()) | ||
.authorizedTo(Jenkins.ADMINISTER) | ||
.withStdin(updateFolder.read()) | ||
.invokeWithArgs("folder1"); | ||
|
||
assertThat(result, succeeded()); | ||
String configFileContent = folder.getConfigFile().asString(); | ||
assertThat(configFileContent, containsString("BasicSSHUserPrivateKey")); | ||
assertThat(configFileContent, not(containsString("FileOnMasterPrivateKeySource"))); | ||
} | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...plugins/sshcredentials/impl/BasicSSHUserPrivateKeyTest_SEC440/updateJob/update_folder.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<com.cloudbees.hudson.plugins.folder.Folder plugin="[email protected]"> | ||
<actions/> | ||
<description></description> | ||
<properties> | ||
<com.cloudbees.hudson.plugins.folder.properties.FolderCredentialsProvider_-FolderCredentialsProperty> | ||
<domainCredentialsMap class="hudson.util.CopyOnWriteMap$Hash"> | ||
<entry> | ||
<com.cloudbees.plugins.credentials.domains.Domain plugin="[email protected]"> | ||
<specifications/> | ||
</com.cloudbees.plugins.credentials.domains.Domain> | ||
<java.util.concurrent.CopyOnWriteArrayList> | ||
<com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey plugin="[email protected]"> | ||
<id>From SSH</id> | ||
<username>from_ssh</username> | ||
<privateKeySource class="com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey$UsersPrivateKeySource"/> | ||
</com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey> | ||
</java.util.concurrent.CopyOnWriteArrayList> | ||
</entry> | ||
</domainCredentialsMap> | ||
</com.cloudbees.hudson.plugins.folder.properties.FolderCredentialsProvider_-FolderCredentialsProperty> | ||
</properties> | ||
<folderViews class="com.cloudbees.hudson.plugins.folder.views.DefaultFolderViewHolder"> | ||
<views> | ||
<hudson.model.AllView> | ||
<owner class="com.cloudbees.hudson.plugins.folder.Folder" reference="../../../.."/> | ||
<name>All</name> | ||
<filterExecutors>false</filterExecutors> | ||
<filterQueue>false</filterQueue> | ||
<properties class="hudson.model.View$PropertyList"/> | ||
</hudson.model.AllView> | ||
</views> | ||
<tabBar class="hudson.views.DefaultViewsTabBar"/> | ||
</folderViews> | ||
<healthMetrics> | ||
<com.cloudbees.hudson.plugins.folder.health.WorstChildHealthMetric> | ||
<nonRecursive>false</nonRecursive> | ||
</com.cloudbees.hudson.plugins.folder.health.WorstChildHealthMetric> | ||
</healthMetrics> | ||
<icon class="com.cloudbees.hudson.plugins.folder.icons.StockFolderIcon"/> | ||
</com.cloudbees.hudson.plugins.folder.Folder> |