Git Product home page Git Product logo

shellfirm's Introduction

Buy Me a Coffee at ko-fi.com

shellfirm

Opppppsss you did it again? ๐Ÿ˜ฑ ๐Ÿ˜ฑ ๐Ÿ˜ฐ

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!

Do you want to learn from other people's mistakes?

shellfirm will intercept any risky patterns and immediately prompt a small challenge that will double verify your action, think of it as a captcha for your terminal.

rm -rf /
#######################
# RISKY COMMAND FOUND #
#######################
* You are going to delete everything in the path.

Solve the challenge: 8 + 0 = ? (^C to cancel)

How does it work?

shellfirm will evaluate all the shell commands behind the scenes. If a risky pattern is detected, you will immediately get a prompt with the relevant warning to verify your command.

Example

Setup your shell

Install via brew

brew tap kaplanelad/tap && brew install shellfirm

Or download the binary file from releases page, unzip the file and move to /usr/local/bin folder.

Validate shellfirm installation

shellfirm --version

Verify installation

mkdir /tmp/shellfirm
cd /tmp/shellfirm
git reset --hard

Select your shell

Oh My Zsh Download zsh plugin:
curl https://raw.githubusercontent.com/kaplanelad/shellfirm/main/shell-plugins/shellfirm.plugin.oh-my-zsh.zsh --create-dirs -o ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/shellfirm/shellfirm.plugin.zsh

Add shellfirm to the list of Oh My Zsh plugins when Zsh is loaded(inside ~/.zshrc):

plugins=(... shellfirm)
Bash Bash implementation is based on https://github.com/rcaloras/bash-preexec project, which adds a pre-exec hook to catch the command before executing.
# Download bash-preexec hook functions. 
curl https://raw.githubusercontent.com/rcaloras/bash-preexec/master/bash-preexec.sh -o ~/.bash-preexec.sh

# Source our file at the end of our bash profile (e.g. ~/.bashrc, ~/.profile, or ~/.bash_profile)
echo '[[ -f ~/.bash-preexec.sh ]] && source ~/.bash-preexec.sh' >> ~/.bashrc

# Download shellfirm pre-exec function
curl https://raw.githubusercontent.com/kaplanelad/shellfirm/main/shell-plugins/shellfirm.plugin.sh -o ~/.shellfirm-plugin.sh

# Load pre-exec command on shell initialized
echo 'source ~/.shellfirm-plugin.sh' >> ~/.bashrc
fish
curl https://raw.githubusercontent.com/kaplanelad/shellfirm/main/shell-plugins/shellfirm.plugin.fish -o ~/.config/fish/conf.d/shellfirm.plugin.fish
Zsh
# Add shellfirm to conf.d fishshell folder
curl https://raw.githubusercontent.com/kaplanelad/shellfirm/main/shell-plugins/shellfirm.plugin.zsh -o ~/.shellfirm-plugin.sh
echo 'source ~/.shellfirm-plugin.sh' >> ~/.zshrc
Docker

โ„น๏ธ Open a new shell session

๐Ÿ‘€ ๐Ÿ‘€ Verify installation ๐Ÿ‘€ ๐Ÿ‘€

You should get a shellfirm prompt challenge.

If you didn't get the prompt challenge:

  1. Make sure the shellfirm --version returns a valid response.
  2. Make sure that you downloaded the Zsh plugin and added it to the Oh My Zsh plugins in .zshrc.

Risky commands

We have predefined a baseline of risky groups command that will be enabled by default, these are risky commands that might be destructive.

Group Enabled By Default
base true
git true
fs true
fs-strict false
kubernetes false
kubernetes-strict false
heroku false
terraform false

Add/Remove new group checks

shellfirm config update-groups

Change challenge:

Currently we support 3 different challenges when a risky command is intercepted:

  • Math - Default challenge which requires you to solve a math question.
  • Enter - Required only to press Enter to continue.
  • Yes - Required typing yes to continue.

You can change the default challenge by running the command:

shellfirm config challenge

At any time you can cancel a risky command by hitting ^C

Ignore pattern:

You can disable one or more patterns in a selected group by running the command:

shellfirm config ignore

Deny pattern command:

Restrict user run command by select pattern id's that you not allow to run in the shell:

shellfirm config deny

To Upgrade shellfirm

brew upgrade shellfirm

Contributing

Thank you for your interest in contributing! Please refer to contribution guidelines for guidance.

Copyright

Copyright (c) 2022 @kaplanelad. See LICENSE for further details.

shellfirm's People

Contributors

albertonoys avatar dependabot[bot] avatar gdoron avatar geoff12889 avatar hrmnjt avatar isan-rivkin avatar kaplanelad avatar paulosv avatar vmule avatar warrenski avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

shellfirm's Issues

fishshell visualisation issue

Missing new line:

 git reset --hard#######################
# RISKY COMMAND FOUND #
#######################
* This command going to reset all your local changes.

Solve the challenge:: 4 + 7 = ? ^C to cancel
^C

AWS

AWS destroy commands

List of command:
TTBD

Heroku

List of command:
example:
heroku ps:restart
heroku ps:stop
heroku ps:kill
heroku ps:stop
heroku maintenance:on
heroku members:remove
heroku features:disable
heroku container:rm
heroku config:unset
heroku clients:destroy
heroku clients:rotate
heroku clients:update
heroku apps:destroy
heroku apps:leave
heroku apps:rename
heroku addons:destroy
heroku addons:detach
heroku access:remove
heroku access:update

Add ../ to rm command

Proposal

When using rm -rf ../ (or multiple ../) it can be dangerous when you do not specify a specific folder to delete.
you may be jump too many folders up :)

Attempted Solutions

Catch ../ or multio ../../../ without spisify spisific folder

Fish shell support

Proposal

Support shellfirm in fish.

Use-cases

I'm using fish as my default shell and failed to make it work so assuming it's not yet supported there?

Customize deny pattern still can be executed

Shellfirm version:

What happened:
Tried to customize the denied command, but it didn't work.

What you expected to happen:
what I think, shellfirm can customize commands that can be denied in addition to the default commands like in the shellfirm/checks directory. But it doesn't work well at my place

How to reproduce it (as minimally and precisely as possible):

  • I declared the command I want to deny in .shellfirm/settings.yaml in the line deny_patterns_ids & includes
  • I did a shellfirm config challenge
  • I've seen my pattern customization already entered there
  • but after I tried the command, it still works in other words it is not restricted by shellfirm. Unlike the default commands that shellfirm give such as git reset etc.

Anything else we need to know?:

  • we all know that this app has big vision and i already feel it
  • I am very happy that you build an application like this, it is very useful in my opinion
  • Thanks @kaplanelad

OS:

  • Ubuntu 20.04LTS Server

Evidence
image

  • git reset command rejected as usual.
  • openstack command not rejected as usual.

Invalid filter .*>(.*)

What happened:
the filter .*>(.*) in fs.yaml file is catch also >> which is also append to file and nut flush the file

What you expected to happen:
the regex should catch only in one >

Ignore patterns

Proposal

Add the option to disable patterns from the selected groups

Use-cases

Some patterns that you don't want to check

Custom checks

Is it still possible to configure custom checks? I remember it used to be possible by setting checks to an array of checks in settings.yaml (at the time config.yaml).

Docker

Support risky patterns in docker cli

Change checks setting on new version

Proposal

We need the option the add/delete/change baseline check when a new version is released.

Use-cases

when we have:

  1. bug in some of the checks
  2. new checks
  3. checks that we want to remove

we need the option to do it automatically when the user updates the new shellfirm version

Attempted Solutions

add Heroku risky commands

Proposal

add Heroku risky commands

Use-cases

List of command:
example:
heroku ps:restart
heroku ps:stop
heroku ps:kill
heroku ps:stop
heroku maintenance:on
heroku members:remove
heroku features:disable
heroku container:rm
heroku config:unset
heroku clients:destroy
heroku clients:rotate
heroku clients:update
heroku apps:destroy
heroku apps:leave
heroku apps:rename
heroku addons:destroy
heroku addons:detach
heroku access:remove
heroku access:update

heroku repo:reset

Restrict command at all

Proposal

Hi Elad, thanks for your good work. Can you add a feature to restrict commands at all? looks like it would be very good if the feature was held.

Very Thanks!

Use-cases

  • Admin set command which is restricted in /.shellfirm/config.yaml
  • The user cannot execute the command in /.shellfirm/config.yaml at all.

Expected Beahviour

  • User can't run command at all if command is on the list of /.shellfirm/config.yaml

Actual Behaviour

  • The user can still run the command if the user succeeds in winning the challenge.

Add check for crontab -r

Please add a check for:

crontab -r

The above command is risky because it'll remove the user's entire crontab of scheduled tasks. Since users typically would want to edit their crontab using the -e option, an accidental keypress of neighbouring -r would be disastrous. Yes, an alias to include the -i (interactive) option could be set to at least first prompt the user before its removal, but users typically only learn about this option once the damage is already done.

Change add_checks_group to work with test yaml file

Proposal

When new test added (for base.yaml for example) that test settings_config.add_checks_group(&["base".into()]) is failed .
need to move the test to take a test yaml file for better maintenance

Use-cases

when new test added to base the test should't brake

Allow to define different challenge per check

Proposal

There are checks that we want to define a different challenge from the default.

Use-cases

By default, I configure Enter as the main challenge, but when I use rm I want a different challenge before continuing the command

Attempted Solutions

Add challenge per check as an optional field

- from: fs
  test: rm.+(-r|-fr|-rf)(\s*)(/|\*|.|./)(\s*)\z
  method: Regex
  enable: true
  description: "You are going to delete everything in the path."
  challenge: Math

Move config reset to interactive

command shellfirm config reset to be interactive:

Rest configuration will reset all checks settings. Select how to continue...
 1. Yes, i want to override the current configuration
 2. Override and backup the existing file
 3. Cancel Or ^C
 4. ```

Move checks into includes list

for better config managment we can move all the list of check to include like:

include: git,fs,base, kubernetes, aws etc

the includes should copy to list of check like :

user_defined:
   list of checks....

rm -R is not getting checked

Shellfirm version:

What happened: Anything

What you expected to happen: Check the command because it is equivalent to "rm -r ."

How to reproduce it (as minimally and precisely as possible): run "rm - R ." or
"RUST_LOG=trace shellfirm pre-command --command "rm -R .""

It gives no more traces

Anything else we need to know?: No, but you are doing a great job

OS: Ubuntu 22.04

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.