News for hackers. Stuff that matters.
Re:Show HN: Ultimate Plumber – a tool for writing Linux pipe... by akavel on Wednesday October 24, 2018 @07:42AM (#18291518)
Right, it's theoretically dangerous, or I'd say practically: "please think when using it"... though I personally couldn't find any other serious problematic example other than typing something clearly dangerous in the first place. And I personally found it immensely useful in the other, non-dangerous cases. So I just took the chance and went with the idea, and then wanted to share it with you, so you might also find it useful, maybe! :) Also... umm... you know, a tool isn't really truly Unixy if you can't hurt yourself with it, right? ;P

That said, I'm starting to think — should I include a note about the potential dangers in the readme?... they seemed glaringly obvious to me (at least in case of rm-like commands), but can there be readers/users, to whom they'd not be obvious?...

edit: Ok, I tried to add a warning in the Readme, that's something I can do easily, and if it helps someone, worth it...

Re:Show HN: Ultimate Plumber – a tool for writing Linux pipe... by etatoby on Wednesday October 24, 2018 @11:48PM (#18298440)
I'm not so versant about the state of permission / capability systems on Linux.

But if there is a way for you to drop the capability to modify the filesystem before running the first pipeline, you should definitely do it by default (and provide a switch to override it if somebody knows what they are doing.)

Re:Show HN: Ultimate Plumber – a tool for writing Linux pipe... by skybrian on Wednesday October 24, 2018 @11:35AM (#18293296)
It seems like a whitelist of safe commands would be a good idea? The user can override with -f if they want to live dangerously.

Even rm has a -f flag to override some safety measures, though the defaults aren't very safe.

Re:Show HN: Ultimate Plumber – a tool for writing Linux pipe... by drb91 on Wednesday October 24, 2018 @02:19PM (#18294954)
Even better, put it into a non-privileged user by default with no write permission.
Re:Show HN: Ultimate Plumber – a tool for writing Linux pipe... by akavel on Wednesday October 24, 2018 @02:55PM (#18295290)
Sounds interesting; but is there any way I could change to a different user if not running as root?... also, even if yes, how do I dynamically create a non-privileged user, or find a pre-existing one?
Re:Show HN: Ultimate Plumber – a tool for writing Linux pipe... by gwn7 on Wednesday October 24, 2018 @06:54PM (#18297173)
I would try creating a non-privileged user "up" during installation and switch to that user under the hood before running the command via `su`.

(Though it would complicate installation which is effectively non-existent since there is a single binary; and tightly couple the application with the environment. It's a trade-off anyway.)

(Edit: Somebody mentioned the user "nobody" which seems to be a better alternative.)

In any case I think that the whitelist approach would work better as it would be nice if the tool knew in advance which commands work properly and which ones don't. That way it could inform its users about the allowed & unallowed commands.

Commands with side effects (or "impure" in the FP terminology) don't make much sense anyway to be used within this. The main value is fast iteration, in order to verify the expected output of the pipeline. For me it doesn't make much sense to use it with commands whose main purpose is to modify the filesystem instead of generating / transforming data and writing it to stdout.

So the criteria for the commands that would make it into the whitelist may be "not having side effects", "writing to stdout", and optionally "reading from stdin".

Fastly iterating side effects is unsafe as well, as has already been pointed out.

This can be a fine data analysis tool actually, unfortunately only for command line geeks. The experience is actually not so far from analyzing data with VIM interactively by piping it to an external UNIX command and getting the result dataset back into the editor. VIM hackers will know :)

Re:Show HN: Ultimate Plumber – a tool for writing Linux pipe... by amalcon on Wednesday October 24, 2018 @11:02PM (#18298302)
One thing to watch out for is that a process running as "nobody" has permission to manipulate (e.g. kill) other processes running as that user. This sometimes includes system processes. Allowing any user to run arbitrary commands as nobody is technically a privilege escalation, and therefore should be avoided.

A single-purpose user with its own group would have this problem only to a lesser degree (you'd be able to mess with other users' "up" invocations, but not any system processes).

Re:Show HN: Ultimate Plumber – a tool for writing Linux pipe... by gwn7 on Thursday October 25, 2018 @05:06PM (#18304593)
I didn't know this (I'm not much of a sysadmin), thank you for the information!
Re:Show HN: Ultimate Plumber – a tool for writing Linux pipe... by infogulch on Wednesday October 24, 2018 @11:39PM (#18298412)
Could you make a `[caller]_up` user for each different user?
Re:Show HN: Ultimate Plumber – a tool for writing Linux pipe... by seiferteric on Wednesday October 24, 2018 @08:25PM (#18297650)
I actually like the user idea better. The problem with a whitelist is that even useful commands can have subtle or little known dangerous modes, like "find . -exec rm {}"
Re:Show HN: Ultimate Plumber – a tool for writing Linux pipe... by gwn7 on Thursday October 25, 2018 @04:58PM (#18304530)
Ah. Good point. Whitelisting commands would have already been a bit painful, and now your comment shows that the parameters need to be whitelisted/blacklisted as well, which would be crazy.

In a world in which shell commands respected the UNIX philosophy, "find" wouldn't have a silly option like "exec", and other commands wouldn't mix read / write / pure data transform operations in a single command.

But it is what it is. So yeah, protection probably needs to be implemented in the user level, for maximum safety.

Maybe an alternative and/or complementary solution would be to profile each inputted command to detect if they are attempting write operations (maybe with "strace" or something like that), and cancel the evaluation of the command in the next iterations and/or show a warning.

Re:Show HN: Ultimate Plumber – a tool for writing Linux pipe... by lloeki on Thursday October 25, 2018 @03:21AM (#18299094)
> The experience is actually not so far from analyzing data with VIM interactively by piping it to an external UNIX command and getting the result dataset back into the editor. VIM hackers will know :)

Do you mean something like this?

   :r! lshw | grep network -A2 | grep : | cut -d: -f2- | paste - -
I'm not versed well enough in vim scripting but I suppose there's a way to loop on that on each <CR> or even keypress (like fzf/ctrlp).
Re:Show HN: Ultimate Plumber – a tool for writing Linux pipe... by gwn7 on Thursday October 25, 2018 @05:50PM (#18304876)
> Do you mean something like this?

    :r! lshw | grep network -A2 | grep : | cut -d: -f2- | paste - -
Not exactly. More like:

- Open vim with the output of `lshw` as content:

    lshw | vim -
- Examine the raw data

- Send the whole content of the buffer as standard input to the given command and rewrite the buffer with the data read from the standard output of it:

    :%! grep network -A2
- Examine the returned dataset. Iterate:

    :%! grep :
- Examine & iterate:

    :%! cut -d: -f2-
- Examine & iterate:

    :%! paste - -

This way, you can examine the output of each step of the pipeline individually, so you can construct your command incrementally. And it is up to you to decide at which point a command will be run instead of it being run automatically following every keypress.

Since the dataset returned by the last command will be visible in the current buffer, you will be able to examine & play with it full screen. You will be able to clean or transform some parts manually (this is frequently needed in data science).

You can always return to the previous/next dataset by pressing u/Ctrl+R (for undo and redo), and examine your command history by pressing ":" and then Ctrl+P/Ctrl+N. (Or you can open the command history quickfix menu by pressing "q:" to view/copy the last several commands at once.)

And since you are in a full blown text editor, you can take advantage of other helpful features such as folding, saving the current dataset to a temporary file, etc.

If you are comfortable with more than a few UNIX filters, VIM can be a very convenient and fun tool to play with data.

Re:Show HN: Ultimate Plumber – a tool for writing Linux pipe... by CGamesPlay on Wednesday October 24, 2018 @04:51PM (#18296262)
Nice tool! Your main use case for destroying files is “xargs rm”, which would be used when receiving a piped argument list.

Could you have this command run as user “nobody” by default, and have a flag to run as a real user? Or as others have mentioned, use capabilities on the spawned processes to prevent anything other than standard input/output?