Shellfirm: Intercept risky patterns at the command line
github.com
github.com
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.
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.
Hasn't really been best practice in many workflows to connect to servers at all for a decade
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.
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.
Stashes could be cleared using a cron job.
You can see a list of saved stashes and their indices with `git stash list`.
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.
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.
I'm pretty sure most git users (who know what "git reset" is) don't realize 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.
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.
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...
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.
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
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.
[0] https://github.com/kaplanelad/shellfirm/blob/main/docs/media...
run shellfirm config --help and you can changed the challenge
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.
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.
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!
+ /\
+ .' '. *
* /======\ +
;:. _ ;
|:. (_) |
|:. _ |
+ |:. (_) | *
;:. ;
.' \:. / `.
/ .-'':._.'`-. \
|/ /||\ \|But I do agree that it is probably easier to implement as a shell script.
You really think shell script will be easier? can you elaborate?
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)
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.
You can see the yaml files.
it wrote in rust to make is faster