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

feat(plugin): add exec_cmd helper for executing command in host #666

Merged
merged 1 commit into from
Sep 9, 2021

Conversation

tw4452852
Copy link
Contributor

Signed-off-by: Tw wei.tan@intel.com

@imsnif
Copy link
Member

imsnif commented Aug 27, 2021

Hey, just to chime in here. While I think this is a really cool feature to have (I think it can also be pretty great to allow plugins to spawn new panes with arbitrary commands or terminals in them), I'm a little worried about security concerns.

We discussed things such as this in the past and agreed that before implementing this we need some sort of permission system. In the least something that when you load the plugin alerts you that this plugin has permissions to run arbitrary commands on your machine, giving you the chance to back down.

@tw4452852 tw4452852 force-pushed the exec_cmd branch 2 times, most recently from c713bbc to b7b52ed Compare August 31, 2021 05:45
@tw4452852
Copy link
Contributor Author

tw4452852 commented Aug 31, 2021

Hi @imsnif ,

I've added a flag to allow the plugin to run host command (forbidden by default). Can you give it another look?

@tw4452852 tw4452852 force-pushed the exec_cmd branch 2 times, most recently from 5afa69f to 0152498 Compare August 31, 2021 06:03
@imsnif
Copy link
Member

imsnif commented Sep 1, 2021

Hey @tw4452852 - sorry for the misunderstanding. I didn't mean to add a flag that would allow all plugins to execute commands. That might be quite dangerous I find. I was thinking right now to do something like add this to the layout where we load the plugin. Maybe under "run"?

@tw4452852
Copy link
Contributor Author

tw4452852 commented Sep 2, 2021

Hi @imsnif ,

Sorry, I misunderstood, thanks for your advice anyway. How about adding the flag under "plugin"? Because it only applies to plugins I think. Like this:

run:
  plugin:
    path: path_or_name
    allow_exec_host_cmd: true/false

@imsnif
Copy link
Member

imsnif commented Sep 2, 2021

@tw4452852 - sounds great!

@tw4452852
Copy link
Contributor Author

@imsnif
Already done.

Copy link
Member

@TheLostLambda TheLostLambda left a comment

Choose a reason for hiding this comment

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

Hey @tw4452852 ! Thank you for all of your excellent work here! I left a couple of small comments, but there is really just one thing we need to address before finally merging this!

Right now there is actually a pretty major security hole: everything in shim.rs is just convenience code for the plugins and isn't actually needed to write a plugin (it wouldn't be used at all in non-Rust plugins, for example). That means that any plugin can just directly call the host_exec_cmd without checking permissions.

I'll leave some comments with more details, but we essentially need to move the permissions check to the host side of things.

zellij-server/src/wasm_vm.rs Show resolved Hide resolved
zellij-utils/src/input/unit/layout_test.rs Outdated Show resolved Hide resolved
zellij-server/src/wasm_vm.rs Show resolved Hide resolved
zellij-server/src/wasm_vm.rs Outdated Show resolved Hide resolved
@@ -37,6 +45,14 @@ pub fn open_file(path: &Path) {
pub fn set_timeout(secs: f64) {
unsafe { host_set_timeout(secs) };
}
pub fn exec_cmd(cmd: &[String]) -> Result<(), PermissionDenied> {
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 need the Result here and I'd be fine with things failing silently (we don't currently have a way to see if the command was run successfully, even if we did have permissions).

I'd personally just return nothing here, but if you disagree, just let me know!

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'd personally prefer to return something if we wait for the command exit, users may know if it's successful or not.
But right now, we don't wait for the command to finish, so I agree with your opinion for simplicity.

Copy link
Member

Choose a reason for hiding this comment

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

@tw4452852 I totally agree :) I'd like to monitor the running of the command eventually, but I'm not sure how we'll do that just yet, so maybe it's best for a second PR :)

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 originally wanted to return the exit code which indicates the success or not. But I'm not sure if this is enough or general. Let's hold on to this for this moment now.

zellij-tile/src/shim.rs Outdated Show resolved Hide resolved
zellij-tile/src/shim.rs Outdated Show resolved Hide resolved
zellij-utils/src/input/layout.rs Outdated Show resolved Hide resolved
@tw4452852
Copy link
Contributor Author

Hi @TheLostLambda , Thanks a lot for your review, they're really good advice, I adopt them all.

zellij-server/src/wasm_vm.rs Outdated Show resolved Hide resolved
@tw4452852
Copy link
Contributor Author

tw4452852 commented Sep 8, 2021

Hi @TheLostLambda

Thanks for your review comments. In the latest version, I also add more context to the log (the plugin's name and the command to run) for better debugging.

Signed-off-by: Tw <wei.tan@intel.com>
Signed-off-by: Tw <tw19881113@gmail.com>
Copy link
Member

@TheLostLambda TheLostLambda left a comment

Choose a reason for hiding this comment

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

This looks great! Thank you for all of your hard work on this and feel free to merge things whenever you're ready!

@TheLostLambda
Copy link
Member

Additionally, @tw4452852 if you can't actually press the merge button, even after approval, just let me know and I'll merge for you!

@tw4452852
Copy link
Contributor Author

Hi @TheLostLambda
It seems I don't have the permission, feel free to merge, I'm done.

@TheLostLambda TheLostLambda merged commit 19b3f83 into zellij-org:main Sep 9, 2021
@TheLostLambda
Copy link
Member

No worries, all merged!

@tw4452852 tw4452852 deleted the exec_cmd branch September 9, 2021 23:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants