News for hackers. Stuff that matters.
Re:Shellfirm: Intercept risky patterns at the command line by makeitdouble on Sunday July 31, 2022 @03:14AM (#32293871)
This kind of tool needs context awareness to be useful.

After the first 30~40 times you’re asked if you want to delete these pods, solving the question coming next becomes automatic. If you’re in a “I’m on my dev env, nothing bad can happen” mindset, that prompt won’t get you out of it, it will just be a tedious step, we’ve seen that time and time again.

It becomes a lot more interesting if it can ask “you’re going to delete from the cluster prod, do you really want to ?” and only do so for production.

Same for “rm -f” really, if it can confirm before you’re deleting a tree of thousands of file, and not when it’s 3 empty directories you created 3 min ago.

Re:Shellfirm: Intercept risky patterns at the command line by lamontcg on Sunday July 31, 2022 @09:33AM (#32295370)
This is the same logic as "sudo forces people to think about what they're typing", which it doesn't, it just makes you type sudo and your password really quickly and equally mindlessly.
Re:Shellfirm: Intercept risky patterns at the command line by iso1631 on Sunday July 31, 2022 @10:45AM (#32295848)
sudo sticks what you're doing in your auth.log file which is fired off to your syslog server, so you've got a chance of knowing how you messed up, or who else messed up
Re:Shellfirm: Intercept risky patterns at the command line by lamontcg on Sunday July 31, 2022 @07:51PM (#32300063)
we solved that at amazon by patching bash and tcsh to send logs to syslog (honeypot patches).
Re:Shellfirm: Intercept risky patterns at the command line by Kaze404 on Sunday July 31, 2022 @02:18PM (#32297441)
It does once you get past using sudo as second attempt at running a command that failed for a reason you don't understand.
Re:Shellfirm: Intercept risky patterns at the command line by lamontcg on Sunday July 31, 2022 @07:52PM (#32300071)
No it really doesn't, you just get quick at typing "sudo shutdown -r now" and typing your password quick and when do that it on prod it is just as mindless as "shutdown -r now". You can't make people think via extra steps.
Re:Shellfirm: Intercept risky patterns at the command line by Kaze404 on Sunday July 31, 2022 @09:24PM (#32300756)
Surely that's just your view on it? I've been using Linux since I was a kid and it's definitely not how I or the people I know use sudo. Lol
Re:Shellfirm: Intercept risky patterns at the command line by davedx on Sunday July 31, 2022 @04:27AM (#32294198)
When I used to admin Windows servers we had production’s desktop background set to red, that worked well, especially when you had multiple remote desktop sessions open. Wonder if that’s doable for non-GUI enabled Linux servers
Re:Shellfirm: Intercept risky patterns at the command line by t-3 on Sunday July 31, 2022 @05:11AM (#32294367)
The standard way is to set PS1 (the commandline prompt text) to indicate the environment. With escape codes, you can pretty trivially get some flashing red text telling you to be careful.
Re:Shellfirm: Intercept risky patterns at the command line by hobs on Sunday July 31, 2022 @07:55AM (#32294947)
If used properly the -Confirm parameter in powershell can also have you change the impact level in your environment and ask for confirmation on things that in dev would not be cared about.

Also its underused but the just in time access stuff where you can grant users subsets of permissions (again, per environment) is also pretty impressive.

Re:Shellfirm: Intercept risky patterns at the command line by formerly_proven on Sunday July 31, 2022 @05:45PM (#32299162)
A not-so standard way is to output a banner via shrc (instead of putting it in the motd, which the ssh daemon will only output for interactive sessions) - which incidentally will also break pretty much all tools using SSH as a transport (scp, rsync, among others).
Re:Shellfirm: Intercept risky patterns at the command line by qalmakka on Sunday July 31, 2022 @05:52AM (#32294482)
That was also the case in very old Linux distros when you logged on X as root. I clearly remember something like Fedora or Mandriva doing exactly that - note that graphically logging in as root on a Unix system is not a great idea though, most GUI software isn't designed for it.
Re:Shellfirm: Intercept risky patterns at the command line by NathanielK on Sunday July 31, 2022 @07:48AM (#32294924)
Other applications can do it too. I recall the Gnome file browser having a big red warning banner if you decided to launch it with gksudo.
Re:Shellfirm: Intercept risky patterns at the command line by 867-5309 on Sunday July 31, 2022 @05:57AM (#32294492)
the terminal background could be changed from black to red
Re:Shellfirm: Intercept risky patterns at the command line by detaro on Sunday July 31, 2022 @06:51AM (#32294714)
SuSE had bright red background with exclamation mark signs and bomb icons
Re:Shellfirm: Intercept risky patterns at the command line by orev on Sunday July 31, 2022 @09:58AM (#32295508)
It’s pretty easy to insert colors into to prompt using conditional logic in things like bashrc. You can also add them to other system tools like ‘screen’ and (I assume) ‘tmux’. People can override them if they want, but it’s a good starting default (and people rarely override defaults on a fleet of servers).
Re:Shellfirm: Intercept risky patterns at the command line by yencabulator on Sunday July 31, 2022 @01:22PM (#32297049)
My prompt only includes username if it's not the usual one, and it's on an orange-red background if it's root.

Similarly, my prompt doesn't include the host when I'm logged in normally, adds it when I'm in a shell via sudo/doas, and colors it when I'm logged in via SSH.

Re:Shellfirm: Intercept risky patterns at the command line by iso1631 on Sunday July 31, 2022 @10:48AM (#32295871)
20 years ago our live/test/dev solaris + linux environments had different coloured prompts (green/yellow/red)

Hasn't really been best practice in many workflows to connect to servers at all for a decade

Re:Shellfirm: Intercept risky patterns at the command line by linschn on Sunday July 31, 2022 @05:11AM (#32294369)
I use the color of tmux's bar to the same effect.
Re:Shellfirm: Intercept risky patterns at the command line by eladkaplan on Sunday July 31, 2022 @03:50AM (#32294011)
I agree that the context will be better and I'm planning to add it in the next releases.
Re:Shellfirm: Intercept risky patterns at the command line by a-dub on Sunday July 31, 2022 @11:39AM (#32296284)
i think a better approach might be to wrap destructive actions with preview functionality that is carefully tuned to summarize succinctly what is unique about resources that are going to be deleted along with the cardinality of the operation.
Re:Shellfirm: Intercept risky patterns at the command line by rootw0rm on Sunday July 31, 2022 @03:29AM (#32293919)
my main response to this HN submission was lolwtf. but your more measured response is valuable. this tool with context could actually be pretty cool.
Re:Shellfirm: Intercept risky patterns at the command line by arijun on Sunday July 31, 2022 @04:00AM (#32294077)
Only because the creator is on here: oops has two O's. Unless you were making a pun with ops in which case maybe remove the elongation so it doesn't seem like a typo.
Re:Shellfirm: Intercept risky patterns at the command line by wruza on Sunday July 31, 2022 @04:35AM (#32294231)
I don’t think it may help in a long run, except in cases when you mistyped a command. Mistakes are done because some assumptions are wrong, e.g. wrong cwd, hostname, account, and a captcha-like barrier cannot point that out or make you think about it more. The correct way to prevent mistakes is easy reversibility. Except for very big files/changes we now have an essentially unlimited disk space. Programs should learn to use it to manage undo.
Re:Shellfirm: Intercept risky patterns at the command line by pca006132 on Sunday July 31, 2022 @03:37AM (#32293944)
I frequently do `git reset --hard`, knowing what I am doing, until I found that I probably need the code a few days later.

Perhaps I just need a tool to intercept this and backup the affected files somewhere. The files can be deleted after some time (a week? or never?). And when I regret doing resetting the files, I can just dig through the backup and try to find it.

Re:Shellfirm: Intercept risky patterns at the command line by ekimekim on Sunday July 31, 2022 @10:37AM (#32295784)
My solution for this is a script that commits all my changes then tags the resulting commit with a basic descriptive name. Something like this:

    git discard bad-idea-didnt-work
Which creates a tag discarded-bad-idea-didnt-work, then resets back to the previous commit.

I can still find and rescue the changes later by looking at my tags.

Others have suggested using the stash for this but I prefer to keep my stash stack free for shorter-term contexts, eg. if I'm halfway through something but need to go checkout another branch briefly.

Re:Shellfirm: Intercept risky patterns at the command line by skykooler on Sunday July 31, 2022 @12:43PM (#32296755)
Would you mind sharing that script? It sounds useful.
Re:Shellfirm: Intercept risky patterns at the command line by matsemann on Sunday July 31, 2022 @05:49AM (#32294471)
You've already gotten tips based on git. But if you use a JetBrains IDE, you also have the local history there. Or can use the shelve functionality, which is like git's stash but a bit smoother.
Re:Shellfirm: Intercept risky patterns at the command line by staindk on Sunday July 31, 2022 @08:50AM (#32295177)
I don't know how JetBrains IDEs do 'local histories' but FWIW VSCode recently also implemented "local file history"[1]. I have not had to use it to salvage anything yet, but I'm sure that day will come.

[1] https://twitter.com/code/status/1511463379210317824

Re:Shellfirm: Intercept risky patterns at the command line by schoen on Sunday July 31, 2022 @03:57AM (#32294056)
I was surprised to learn a few months ago from https://news.ycombinator.com/item?id=28958613 that the "git reset --hard" does not actually delete the files and you can still recover references to them using "git reflog".

I'm pretty sure most git users (who know what "git reset" is) don't realize this!

Re:Shellfirm: Intercept risky patterns at the command line by pca006132 on Sunday July 31, 2022 @04:00AM (#32294081)
You need to commit them first. If you did not commit them, it doesn't work. But yeah, maybe I can just define an alias to add+commit+reset, which should solve this problem.
Re:Shellfirm: Intercept risky patterns at the command line by wruza on Sunday July 31, 2022 @04:44AM (#32294265)
I just stopped worrying and commit everything into my own repos, even half baked or temporary, making sure that a commit message or a file name signals it clearly. It’s a versioning system for this exact purpose, not a ceremonial sanctuary.
Re:Shellfirm: Intercept risky patterns at the command line by npteljes on Sunday July 31, 2022 @08:44AM (#32295141)
Exactly. To me, some branches are quality, some are quantity.
Re:Shellfirm: Intercept risky patterns at the command line by ithkuil on Sunday July 31, 2022 @08:55AM (#32295196)
You can also stash them which is effectively a commit into a special stash stack
Re:Shellfirm: Intercept risky patterns at the command line by neilparikh on Sunday July 31, 2022 @03:51AM (#32294016)
You could just call `git stash` instead of `git reset --hard`. It'll have the same effect on your working directory, while also "backing up" the changes.

Stashes could be cleared using a cron job.

Re:Shellfirm: Intercept risky patterns at the command line by pca006132 on Sunday July 31, 2022 @03:56AM (#32294048)
iirc stash works more in a stack like manner? Say if you do git stash, and then do git rebase -i to clean up the history, proceed to write some other features, git stash again to clean it up, etc. Can you recover the files for the first stash?
Re:Shellfirm: Intercept risky patterns at the command line by Delk on Sunday July 31, 2022 @07:43AM (#32294901)
Yes, you can. If you save, apply or pop with git stash with no arguments, it works like a stack by default, but you can also access the other entries. For example `git stash pop stash@{n}`, where n is the index of the entry in the stash "stack", applies the nth stash entry on top of the working tree and then removes it from the stored stashes. The latest entry is at index zero, so stash@{0} would be the last saved/pushed one.

You can see a list of saved stashes and their indices with `git stash list`.

Re:Shellfirm: Intercept risky patterns at the command line by staindk on Sunday July 31, 2022 @08:56AM (#32295200)
Ah you can use pop with other stashes too, thanks for the tip... though that feels a bit like a semantic misnomer (? unsure what term would be best to describe what I'm thinking - but 'pop' kind of feels like it should always be applicable only to the top element in a stack. I'd be scared that popping stash@{5} would apply all of stashes 1 to 5 at once lol).

I've been using `git stash apply stash@{n}`, which works just fine, but the stash is then not removed from your list and results in clutter.

Re:Shellfirm: Intercept risky patterns at the command line by Delk on Sunday July 31, 2022 @12:22PM (#32296596)
> though that feels a bit like a semantic misnomer

It does, but then, this is the git command-line interface. :)

My understanding is that the stash pop command is simply an apply plus the removal of the successfully applied stash. The man page reflects this. It does not pop everything above element in the list.

Re:Shellfirm: Intercept risky patterns at the command line by amichal on Sunday July 31, 2022 @03:59AM (#32294071)
git stash list?
Re:Shellfirm: Intercept risky patterns at the command line by timfi on Sunday July 31, 2022 @03:49AM (#32294008)
In situations like this you could use `git stash` instead of completely deleting it.
Re:Shellfirm: Intercept risky patterns at the command line by IshKebab on Sunday July 31, 2022 @04:22AM (#32294178)
Yeah git reflog will show you the previous commit (in a pretty confusing way tbh but it does the job). The original files will get GC'd by git at some point.
Re:Shellfirm: Intercept risky patterns at the command line by sureglymop on Sunday July 31, 2022 @04:28AM (#32294204)
I think there is another use case for a tool like this: predictable auto completion instead of input validation.

For example, if you type this: `mkdir test && cd test` the tool could realize that the `test` folder was created and offer tab completion for it in the second part. I have long wanted a shell with better auto completion, more prediction etc.

Re:Shellfirm: Intercept risky patterns at the command line by cassepipe on Sunday July 31, 2022 @09:41AM (#32295408)
It only cover rm mistakes but is so KISSly great : trash-d will alias rm so that all that you rm goes to the bin instead of disappearing for ever :

https://github.com/rushsteve1/trash-d

Re:Shellfirm: Intercept risky patterns at the command line by huksley on Sunday July 31, 2022 @09:13AM (#32295279)
One way to do it is to use your shell functions (or aliases) for example for bash:

  function rm() {
    if [[ "$@" =~ "-rf" && "${RISKY}" != "1" ]]; then
      echo "Confirm by running RISKY=1 rm $@"
    else
      command rm "$@"
    fi
  }
This goes into ~/.bashrc and I have a lot of commands customized to save time (for example git [1] or docker)

[1]: https://gist.github.com/huksley/ef70da85f8dc0c9ca6f8ec4f37c3...

Re:Shellfirm: Intercept risky patterns at the command line by synu on Sunday July 31, 2022 @02:53AM (#32293791)
Usually when I make these mistakes I’m running the command on purpose, but my context is somehow confused. So I would probably happily solve the challenge and break everything.
Re:Shellfirm: Intercept risky patterns at the command line by playingalong on Sunday July 31, 2022 @02:58AM (#32293808)
Do people really issue these risky commands (and regret)? Or is it rather variable substitution which comes to play? E.g. referenced to undeclared variable which renders to empty string.
Re:Shellfirm: Intercept risky patterns at the command line by xanathar on Sunday July 31, 2022 @04:39AM (#32294246)
Yes, but probably not in the way that makes the program any useful.

Example: I recently executed `git checkout .` (that incidentally would not be caught by this project) on the wrong repo. Oh the pain. But I would have probably confirmed the "captcha" blindly as I really wanted to execute that... just not on that repo.

Re:Shellfirm: Intercept risky patterns at the command line by travisd on Sunday July 31, 2022 @02:52AM (#32293786)
Other than rm -rf / (which can happen if you manage to hit enter rather than another key) this feels not terribly useful. Who has accidentally kubectl delete ns prod? Anecdotally, the accidental enter seems like a much more likely scenario (I once ruined a server by chmod -r a+r / ing — that feels like a better use case for accident protection).
Re:Shellfirm: Intercept risky patterns at the command line by IshKebab on Sunday July 31, 2022 @04:24AM (#32294188)
I've accidentally deleted all Docker containers on a shared system (who knew - Docker has no user-level security at all). Though this command wouldn't help in that case since I didn't know the command I was running was dangerous.
Re:Shellfirm: Intercept risky patterns at the command line by EdwardDiego on Sunday July 31, 2022 @03:03AM (#32293827)
If you are able to `kubectl delete ns prod-stuff` then you have somewhat earned the lesson you're about to learn.
Re:Shellfirm: Intercept risky patterns at the command line by eladkaplan on Sunday July 31, 2022 @02:09AM (#32293593)
How do I save myself from myself?

rm -rf * git reset --hard Before hitting the enter key? kubectl delete ns Stop! you are going to delete a lot of resources And many more!

visit here: https://github.com/kaplanelad/shellfirm

Re:Shellfirm: Intercept risky patterns at the command line by userbinator on Sunday July 31, 2022 @04:15AM (#32294139)
Enter - Required only to press Enter to continue.

That sounds like it would be a bit too easy to accidentally go through, especially since Enter was used to initiate the command. Hold down the key just a little too long and it'll be as if you weren't even challenged.

Re:Shellfirm: Intercept risky patterns at the command line by herpderperator on Sunday July 31, 2022 @04:16AM (#32294146)
If you look at the example gif[0] they ask a simple math challenge. It's probably configurable.

[0] https://github.com/kaplanelad/shellfirm/blob/main/docs/media...

Re:Shellfirm: Intercept risky patterns at the command line by eladkaplan on Sunday July 31, 2022 @04:21AM (#32294176)
absolutely, it configurable.

run shellfirm config --help and you can changed the challenge

Re:Shellfirm: Intercept risky patterns at the command line by eladkaplan on Sunday July 31, 2022 @04:24AM (#32294186)
this is configurable, depend what you want. the `enter` challenge is not the default. you can configure the challenge
Re:Shellfirm: Intercept risky patterns at the command line by 3np on Sunday July 31, 2022 @03:29AM (#32293920)
One thing not clear from readme: Will it detect if it's in a TTY or might it also trigger from commands triggered inside shell scripts?
Re:Shellfirm: Intercept risky patterns at the command line by alexwasserman on Sunday July 31, 2022 @03:52AM (#32294023)
It’s loaded in via .zshrc or .bashrc (didn’t read the fish docs, but I assume it’s similar), so catches commands you enter in an interactive shell.

Commands within a shell script won’t be handled by it.

Similarly cron jobs don’t typically run with a full user environment, unless you’ve gone out of your way to make them, so would be safe.

Re:Shellfirm: Intercept risky patterns at the command line by eladkaplan on Sunday July 31, 2022 @03:56AM (#32294050)
shellfirm not execute the command. it's just get interrupt when you run the command, check the pattern and prompt your a verification. your shell is the executer
Re:Shellfirm: Intercept risky patterns at the command line by TekMol on Sunday July 31, 2022 @03:24AM (#32293901)
This should be a small, easy to read bash script.

Not a plethora of rust files that compile to a binary.

I would never trust this thing to not cause more issues, unless it is so small and elegant, that I can audit it very easily and be very very sure it is safe.

Re:Shellfirm: Intercept risky patterns at the command line by NavinF on Sunday July 31, 2022 @03:49AM (#32294007)
Funny you say that when the sketchiest part of this submission is the shell script dependency it uses to intercept every command you run: https://github.com/rcaloras/bash-preexec/blob/master/bash-pr...

I don’t know rust, but the rust files in the submission look very straightforward. (Why wouldn’t it? It’s just matching a few hardcoded commands. It’d be easy in any language)

Re:Shellfirm: Intercept risky patterns at the command line by eladkaplan on Sunday July 31, 2022 @03:54AM (#32294038)
In base you need a hook that get the command before your shell execute the command. when the shell get the command interrupt this project execute shellfirm before summation in your shell
Re:Shellfirm: Intercept risky patterns at the command line by NavinF on Sunday July 31, 2022 @04:12AM (#32294125)
Yeah I get it. Your code is fine.

I just find it hilarious how that guy wanted you to implement this as a shell script so he could “audit it very easily”. I mean, bash-preexec.sh isn’t the worst shell script I’ve seen (It even has a Bats test!), but anyone that thinks shell scripts are easy to audit is full of shit.

Re:Shellfirm: Intercept risky patterns at the command line by eladkaplan on Sunday July 31, 2022 @04:15AM (#32294137)
In zshrc is much more easier based on the hooks that you get
Re:Shellfirm: Intercept risky patterns at the command line by creatonez on Sunday July 31, 2022 @03:30AM (#32293924)
Why nitpick the programming language of a project clearly intended to be used by the author?
Re:Shellfirm: Intercept risky patterns at the command line by TekMol on Sunday July 31, 2022 @03:36AM (#32293941)
Because of the indirection and complexity it causes.

The user is in a shell. The simplest way to add something to their system is a shellscript. No moving parts. You get what you see in the script.

The way the project is set up, there are multiple moving parts. The interaction between the shell, some compiler and a bunch of rust files.

Imagine during the moon landing, Neil Armstrong could not have communicated directly with Buzz Aldrin. But they would had to go through a translator who translates English to German. Who passes the message on to a translator who translates it from German to French. Who then passes it on to Buzz. BOOM!

                      +   /\
         +              .'  '.   *
                *      /======\      +
                      ;:.  _   ;
                      |:. (_)  |
                      |:.  _   |
            +         |:. (_)  |          *
                      ;:.      ;
                    .' \:.    / `.
                   / .-'':._.'`-. \
                   |/    /||\    \|
Re:Shellfirm: Intercept risky patterns at the command line by Thiez on Sunday July 31, 2022 @04:20AM (#32294171)
By that reasoning all command line tools must be shell scripts.
Re:Shellfirm: Intercept risky patterns at the command line by pca006132 on Sunday July 31, 2022 @03:45AM (#32293992)
I don't think this tool changes the shell command for you? Your analogy doesn't fit here.

But I do agree that it is probably easier to implement as a shell script.

Re:Shellfirm: Intercept risky patterns at the command line by eladkaplan on Sunday July 31, 2022 @04:37AM (#32294240)
shellfirm not changes the shell command, only get the the command and check the pattern. the shell is execute the command.

You really think shell script will be easier? can you elaborate?

Re:Shellfirm: Intercept risky patterns at the command line by IshKebab on Sunday July 31, 2022 @04:20AM (#32294169)
The idea that this would be easier to read and more reliable in Bash is downright hilarious.
Re:Shellfirm: Intercept risky patterns at the command line by eladkaplan on Sunday July 31, 2022 @04:23AM (#32294181)
what is your point? do implement the risky command in bash script?
Re:Shellfirm: Intercept risky patterns at the command line by glitchcrab on Sunday July 31, 2022 @04:34AM (#32294225)
They're saying that writing the whole thing in bash (no rust) would be even harder to read. Programming in bash is hideous.
Re:Shellfirm: Intercept risky patterns at the command line by eladkaplan on Sunday July 31, 2022 @04:49AM (#32294282)
agree, this is the reason that i wrote it in rust faster easy to maintain unitesting and small binary
Re:Shellfirm: Intercept risky patterns at the command line by eladkaplan on Sunday July 31, 2022 @03:51AM (#32294017)
Hey this project is very small, and not execution command! only prompt you a verification when detect a risky pattern from a yaml pre-define (default or by you)

You can see the yaml files.

it wrote in rust to make is faster