-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Re-enable automatic approval of launch command if configured by admin #47
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,8 @@ | |
*/ | ||
package hudson.slaves; | ||
|
||
import edu.umd.cs.findbugs.annotations.NonNull; | ||
import edu.umd.cs.findbugs.annotations.Nullable; | ||
import hudson.AbortException; | ||
import hudson.EnvVars; | ||
import hudson.Extension; | ||
|
@@ -40,6 +42,7 @@ | |
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
import jenkins.model.Jenkins; | ||
import net.sf.json.JSONObject; | ||
import org.apache.commons.lang.StringUtils; | ||
import org.jenkinsci.Symbol; | ||
import org.jenkinsci.plugins.scriptsecurity.scripts.ApprovalContext; | ||
|
@@ -48,6 +51,8 @@ | |
import org.jenkinsci.plugins.scriptsecurity.scripts.languages.SystemCommandLanguage; | ||
import org.kohsuke.stapler.DataBoundConstructor; | ||
import org.kohsuke.stapler.QueryParameter; | ||
import org.kohsuke.stapler.Stapler; | ||
import org.kohsuke.stapler.StaplerRequest; | ||
|
||
/** | ||
* {@link ComputerLauncher} through a remote login mechanism like ssh/rsh. | ||
|
@@ -79,7 +84,7 @@ public CommandLauncher(String command) { | |
agentCommand = command; | ||
env = null; | ||
// TODO add withKey if we can determine the Slave.nodeName being configured | ||
ScriptApproval.get().configuring(command, SystemCommandLanguage.get(), ApprovalContext.create().withCurrentUser()); | ||
ScriptApproval.get().configuring(command, SystemCommandLanguage.get(), ApprovalContext.create().withCurrentUser(), Stapler.getCurrentRequest() == null); | ||
} | ||
|
||
/** Constructor for programmatic use. Always approves the script. | ||
|
@@ -102,7 +107,7 @@ public CommandLauncher(String command, EnvVars env) { | |
} | ||
|
||
private Object readResolve() { | ||
ScriptApproval.get().configuring(agentCommand, SystemCommandLanguage.get(), ApprovalContext.create()); | ||
ScriptApproval.get().configuring(agentCommand, SystemCommandLanguage.get(), ApprovalContext.create(), true); | ||
return this; | ||
} | ||
|
||
|
@@ -220,15 +225,29 @@ private static void reportProcessTerminated(Process proc, TaskListener listener) | |
|
||
@Extension @Symbol("command") | ||
public static class DescriptorImpl extends Descriptor<ComputerLauncher> { | ||
|
||
@Override | ||
public ComputerLauncher newInstance(@Nullable StaplerRequest req, @NonNull JSONObject formData) throws FormException { | ||
CommandLauncher instance = (CommandLauncher) super.newInstance(req, formData); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you check that both of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Checked There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not entirely sure, but I think Here it's There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that cloud plugins may use it, for example ec2-fleet, delta-cloud, spotinst, and I think one proprietary plugin I have access to. Some other clouds appear to only use a cloud-specific subclass of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Works with ec2-fleet, |
||
if (formData.get("oldCommand") != null) { | ||
String oldCommand = formData.getString("oldCommand"); | ||
boolean approveIfAdmin = !StringUtils.equals(oldCommand, instance.agentCommand); | ||
if (approveIfAdmin) { | ||
ScriptApproval.get().configuring(instance.agentCommand, SystemCommandLanguage.get(), | ||
ApprovalContext.create().withCurrentUser(), true); | ||
} | ||
} | ||
return instance; | ||
} | ||
public String getDisplayName() { | ||
return org.jenkinsci.plugins.command_launcher.Messages.CommandLauncher_displayName(); | ||
} | ||
|
||
public FormValidation doCheckCommand(@QueryParameter String value) { | ||
public FormValidation doCheckCommand(@QueryParameter String value, @QueryParameter String oldCommand) { | ||
if(Util.fixEmptyAndTrim(value)==null) | ||
return FormValidation.error(org.jenkinsci.plugins.command_launcher.Messages.CommandLauncher_NoLaunchCommand()); | ||
else | ||
return ScriptApproval.get().checking(value, SystemCommandLanguage.get()); | ||
return ScriptApproval.get().checking(value, SystemCommandLanguage.get(), !StringUtils.equals(value, oldCommand)); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we would ever have an active user in this context, so maybe
false
makes more sense? Not sure.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I thought about this too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems this one has to stay as
true
because of submission via REST and CLIThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, and it looks like both of those mechanisms of updating the configuration fully replace the existing content, so it seems ok to assume that admins always approve scripts in those cases.