Skip to content
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

Merged
merged 2 commits into from
May 25, 2022

Conversation

yaroslavafenkin
Copy link
Contributor

@yaroslavafenkin yaroslavafenkin commented May 17, 2022

Re-enable automatic approval of launch command if configured by administrator user. Related to the script-security hardening (jenkinsci/script-security-plugin@f4c0bb9)

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests - that demonstrates feature works or fixes the issue

}

private Object readResolve() {
ScriptApproval.get().configuring(command, SystemCommandLanguage.get(), ApprovalContext.create());
ScriptApproval.get().configuring(command, SystemCommandLanguage.get(), ApprovalContext.create(), true);
Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Contributor Author

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 CLI

Copy link
Member

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.

@@ -49,11 +50,11 @@ public class CommandConnector extends ComputerConnector {
public CommandConnector(String command) {
this.command = command;
// TODO add withKey if we can determine the Cloud.name being configured
ScriptApproval.get().configuring(command, SystemCommandLanguage.get(), ApprovalContext.create().withCurrentUser());
ScriptApproval.get().configuring(command, SystemCommandLanguage.get(), ApprovalContext.create().withCurrentUser(), true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this safe? I was thinking we would need to have oldCommand get passed through the UI like with CpsFlowDefinition, but I am not familiar with this plugin.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if anyone other than admins can configure that, need to check.
If it's only admins who have permissions then I assume we're safe with true.

Copy link
Member

@dwnusbaum dwnusbaum May 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think the relevant config page might only require Computer/Configure permission, but I'm not entirely sure. I guess if it always required administer permission then there would be no need for the plugin to integrate with script-security at all.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC the discussion: Computer/Configure is enough to access the page, that's why this plugin and the security fix preceding it were needed in the first place.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in c158b7b.

* command now gets implicitly approved only if manually edited by admin
@Wadeck Wadeck requested a review from daniel-beck May 19, 2022 13:21
yaroslavafenkin referenced this pull request in jenkinsci/script-security-plugin May 23, 2022

@Override
public ComputerLauncher newInstance(@Nullable StaplerRequest req, @NonNull JSONObject formData) throws FormException {
CommandLauncher instance = (CommandLauncher) super.newInstance(req, formData);
Copy link
Member

@dwnusbaum dwnusbaum May 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you check that both of the newInstance overrides actually get invoked when the objects are constructed? Just in case something else needs to be changed like with workflow-cps and workflow-job.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked CommandLauncher, it gets called. Haven't verified if CommandConnector override gets called though, but the two are very similar.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely sure, but I think CommandConnector is never used. I've looked at ssh-slaves-plugin, there's SSHLauncher/config.jelly which in turn includes the corresponding connector template SSHConnector/config.jelly. And that one specifies the details for ssh connection.

Here it's CommandLauncher's config.xml that provides us an input field to specify a launch command.

Copy link
Member

@dwnusbaum dwnusbaum May 25, 2022

Choose a reason for hiding this comment

The 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 ComputerConnector, in which case this class is not used. So either way, this definitely does not seem to be a commonly used class, but it might be possible to test it with one of those plugins.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works with ec2-fleet, newInstance was called ✔️

Copy link
Member

@dwnusbaum dwnusbaum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

private Object readResolve() {
ScriptApproval.get().configuring(command, SystemCommandLanguage.get(), ApprovalContext.create());
ScriptApproval.get().configuring(command, SystemCommandLanguage.get(), ApprovalContext.create(), true);
Copy link
Member

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.

@jglick jglick added the bug label May 25, 2022
@jglick jglick merged commit 4a97f20 into jenkinsci:master May 25, 2022
@basil
Copy link
Member

basil commented Jul 23, 2022

Could this please be released to facilitate BOM/PCT testing?

@yaroslavafenkin
Copy link
Contributor Author

Could this please be released to facilitate BOM/PCT testing?

It is released :)
https://github.com/jenkinsci/command-launcher-plugin/releases/tag/84.v4a_97f2027398

@basil
Copy link
Member

basil commented Jul 25, 2022

Sorry for not noticing, and thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants