Skip to content

Commit 412f2cd

Browse files
authored
feat: overhaul with context-aware protection, policies,Severity, audit, and expanded checks (#144)
* feat: overhaul with context-aware protection, policies,Severity, audit, and expanded checks * fix doc warning * fix doc warning
1 parent 6810779 commit 412f2cd

File tree

243 files changed

+9299
-7384
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

243 files changed

+9299
-7384
lines changed

CHANGELOG.md

Lines changed: 112 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,121 +1,177 @@
11
## Unreleased
22

3+
FEATURES:
4+
5+
- **Context-Aware Protection**: Automatically detects SSH sessions, root user, protected git branches, production Kubernetes contexts, and custom environment variables to escalate challenge difficulty based on risk level (Normal / Elevated / Critical).
6+
- **Safe Alternative Suggestions**: Risky commands now show a safer alternative (e.g., `git push --force` suggests `--force-with-lease`). Alternatives are displayed in green alongside the challenge prompt.
7+
- **Project-Level Policies**: Teams can commit a `.shellfirm.yaml` file to enforce additive-only safety rules (deny lists, challenge escalation overrides, branch-specific rules). Policies are discovered by walking up the directory tree.
8+
- **Audit Trail**: Optional logging of every intercepted command, matched patterns, challenge type, outcome (ALLOWED/BLOCKED/DENIED), and context labels. Commands: `shellfirm audit show` and `shellfirm audit clear`.
9+
- **Zero-Friction Setup**: New `shellfirm init <shell>` command prints the appropriate hook for eval. Auto-detects shell when no argument is given.
10+
- **Custom Checks**: Load user-defined check YAMLs from `~/.shellfirm/checks/` at runtime.
11+
- **Expanded Pattern Coverage**: New built-in checks for Docker, AWS CLI, GCP, Azure CLI, and database commands (DROP, TRUNCATE).
12+
- **Policy CLI**: `shellfirm policy init` scaffolds a template; `shellfirm policy validate` checks syntax.
13+
14+
IMPROVEMENTS:
15+
16+
- **Compound Command Splitting**: Properly splits commands on `&&`, `||`, `|`, `;` operators, replacing the previous character-based splitting that could miss risky subcommands.
17+
- **Dependency Injection Architecture**: All I/O abstracted through `Environment` and `Prompter` traits, enabling fully sandboxed testing with zero real system access.
18+
- **Three-Tier Test Suite**: 102 tests across Pure Logic (Tier 1), Sandboxed Integration (Tier 2), and YAML-driven Decision Matrix (Tier 3).
19+
- **Dependency Upgrades**: clap v3 -> v4, serde_yaml 0.8 -> 0.9, removed `lazy_static` (replaced with `std::sync::OnceLock`), `tempdir` -> `tempfile`, workspace resolver set to v2.
20+
- **Fish Shell Fix**: `commandline -f execute` now only runs when `shellfirm pre-command` exits successfully, preventing commands from executing after cancellation.
21+
- **Zsh Shell Fix**: Added binary existence check before invoking shellfirm.
22+
- **Safer Unwraps**: Replaced unsafe `unwrap()` calls in filter matching with proper `match` + error logging.
23+
24+
BREAKING CHANGES:
25+
26+
- Settings file now includes `context` and `audit_enabled` fields (defaults applied automatically on upgrade).
27+
328
## 0.2.6
29+
430
IMPROVMENT
5-
* Add git-strict file commands. [PR-112](https://github.com/kaplanelad/shellfirm/pull/112)
6-
* Add more git commands. [PR-112](https://github.com/kaplanelad/shellfirm/pull/112)
7-
* Add Terraform commands. [PR-113](https://github.com/kaplanelad/shellfirm/pull/113)
8-
* Improve xtask. [PR-115](https://github.com/kaplanelad/shellfirm/pull/115)
9-
* Improve docs. [PR-116](https://github.com/kaplanelad/shellfirm/pull/116)
10-
* Allow ignoring patterns. [PR-117](https://github.com/kaplanelad/shellfirm/pull/117)
31+
32+
- Add git-strict file commands. [PR-112](https://github.com/kaplanelad/shellfirm/pull/112)
33+
- Add more git commands. [PR-112](https://github.com/kaplanelad/shellfirm/pull/112)
34+
- Add Terraform commands. [PR-113](https://github.com/kaplanelad/shellfirm/pull/113)
35+
- Improve xtask. [PR-115](https://github.com/kaplanelad/shellfirm/pull/115)
36+
- Improve docs. [PR-116](https://github.com/kaplanelad/shellfirm/pull/116)
37+
- Allow ignoring patterns. [PR-117](https://github.com/kaplanelad/shellfirm/pull/117)
1138

1239
## 0.2.5
40+
1341
IMPROVMENT
14-
* create unites for regex checks. [PR-107](https://github.com/kaplanelad/shellfirm/pull/107)
15-
* Remove contains method. [PR-108](https://github.com/kaplanelad/shellfirm/pull/108)
16-
* check is folder or directory exists before prompt a message. [PR-109](https://github.com/kaplanelad/shellfirm/pull/109)
42+
43+
- create unites for regex checks. [PR-107](https://github.com/kaplanelad/shellfirm/pull/107)
44+
- Remove contains method. [PR-108](https://github.com/kaplanelad/shellfirm/pull/108)
45+
- check is folder or directory exists before prompt a message. [PR-109](https://github.com/kaplanelad/shellfirm/pull/109)
1746

1847
BRAKING CHANGES
19-
* Change shellfirm configuration. [PR-103](https://github.com/kaplanelad/shellfirm/pull/103)
48+
49+
- Change shellfirm configuration. [PR-103](https://github.com/kaplanelad/shellfirm/pull/103)
2050

2151
## 0.2.4
52+
2253
IMPROVMENT
23-
* Check test. [PR-98](https://github.com/kaplanelad/shellfirm/pull/98)
24-
* Remove vergen package. [PR-100](https://github.com/kaplanelad/shellfirm/pull/100)
25-
* add .rustfmt.toml file. [PR-](https://github.com/kaplanelad/shellfirm/pull/101)
54+
55+
- Check test. [PR-98](https://github.com/kaplanelad/shellfirm/pull/98)
56+
- Remove vergen package. [PR-100](https://github.com/kaplanelad/shellfirm/pull/100)
57+
- add .rustfmt.toml file. [PR-](https://github.com/kaplanelad/shellfirm/pull/101)
2658

2759
## 0.2.3
60+
2861
IMPROVMENT
29-
* Support $XDG_CONFIG_HOME. [PR-87](https://github.com/kaplanelad/shellfirm/pull/87)
30-
* Add xtask.[PR-95](https://github.com/kaplanelad/shellfirm/pull/95)
31-
* Interactive menu in config reset command. [PR-96](https://github.com/kaplanelad/shellfirm/pull/96)
62+
63+
- Support $XDG_CONFIG_HOME. [PR-87](https://github.com/kaplanelad/shellfirm/pull/87)
64+
- Add xtask.[PR-95](https://github.com/kaplanelad/shellfirm/pull/95)
65+
- Interactive menu in config reset command. [PR-96](https://github.com/kaplanelad/shellfirm/pull/96)
3266

3367
DOCS
34-
* More installation examples. [PR-](https://github.com/kaplanelad/shellfirm/pull/94)
68+
69+
- More installation examples. [PR-](https://github.com/kaplanelad/shellfirm/pull/94)
3570

3671
## 0.2.2
72+
3773
IMPROVMENT
38-
* Adds crontab -r as a risky command. [PR-81](https://github.com/kaplanelad/shellfirm/pull/81)
39-
* Decouple test from base checks. [PR-84](https://github.com/kaplanelad/shellfirm/pull/84)
40-
* Decouple test from app version snapshots. [PR-85](https://github.com/kaplanelad/shellfirm/pull/85)
41-
* Improve config tests. [PR-86](https://github.com/kaplanelad/shellfirm/pull/86)
74+
75+
- Adds crontab -r as a risky command. [PR-81](https://github.com/kaplanelad/shellfirm/pull/81)
76+
- Decouple test from base checks. [PR-84](https://github.com/kaplanelad/shellfirm/pull/84)
77+
- Decouple test from app version snapshots. [PR-85](https://github.com/kaplanelad/shellfirm/pull/85)
78+
- Improve config tests. [PR-86](https://github.com/kaplanelad/shellfirm/pull/86)
4279

4380
BUG FIX
44-
* Change title for fish installation instructions. [PR-82](https://github.com/kaplanelad/shellfirm/pull/82)
81+
82+
- Change title for fish installation instructions. [PR-82](https://github.com/kaplanelad/shellfirm/pull/82)
4583

4684
## 0.2.1
85+
4786
IMPROVMENTS:
48-
* Add heroku risky patterns.[PR-75](https://github.com/kaplanelad/shellfirm/pull/75)
87+
88+
- Add heroku risky patterns.[PR-75](https://github.com/kaplanelad/shellfirm/pull/75)
4989

5090
DOCS
51-
* Spell correction for README typo. [PR-79](https://github.com/kaplanelad/shellfirm/pull/79)
52-
* docs/checks/fs - clarify descriptions. [PR-77](https://github.com/kaplanelad/shellfirm/pull/77)
91+
92+
- Spell correction for README typo. [PR-79](https://github.com/kaplanelad/shellfirm/pull/79)
93+
- docs/checks/fs - clarify descriptions. [PR-77](https://github.com/kaplanelad/shellfirm/pull/77)
5394

5495
## 0.2.0
96+
5597
IMPROVMENTS:
56-
* Replace / with path join.[PR-72](https://github.com/kaplanelad/shellfirm/pull/72)
57-
* Bump crossbeam-utils from 0.8.5 to 0.8.10. [PR-74](https://github.com/kaplanelad/shellfirm/pull/74)
5898

99+
- Replace / with path join.[PR-72](https://github.com/kaplanelad/shellfirm/pull/72)
100+
- Bump crossbeam-utils from 0.8.5 to 0.8.10. [PR-74](https://github.com/kaplanelad/shellfirm/pull/74)
59101

60102
## 0.2.0
103+
61104
IMPROVMENTS:
62-
* Improve test. [PR-71](https://github.com/kaplanelad/shellfirm/pull/71)
63-
* replace / with path join. [PR-72](https://github.com/kaplanelad/shellfirm/pull/72)
64-
* Text cleanuo. [PR-]https://github.com/kaplanelad/shellfirm/pull/66
105+
106+
- Improve test. [PR-71](https://github.com/kaplanelad/shellfirm/pull/71)
107+
- replace / with path join. [PR-72](https://github.com/kaplanelad/shellfirm/pull/72)
108+
- Text cleanuo. [PR-]https://github.com/kaplanelad/shellfirm/pull/66
65109

66110
## 0.1.6
111+
67112
IMPROVMENTS
68-
* change ~ to home dir in IsFileExists FILTER. [PR-63](https://github.com/kaplanelad/shellfirm/pull/63)
69-
* Fish shell support. [PR-61](https://github.com/kaplanelad/shellfirm/pull/61)
70113

71-
## 0.1.5
114+
- change ~ to home dir in IsFileExists FILTER. [PR-63](https://github.com/kaplanelad/shellfirm/pull/63)
115+
- Fish shell support. [PR-61](https://github.com/kaplanelad/shellfirm/pull/61)
116+
117+
## 0.1.5
72118

73119
IMPROVMENTS:
74-
* Ading custom check - for check if file exsits before prompt a delete/flush verification. [PR-46](https://github.com/kaplanelad/shellfirm/pull/60)
75-
* Support multiple commands in one line. [MR](https://github.com/kaplanelad/shellfirm/commit/c2c4d0633dcdac38b6b44d5351179f6e1421096d)
120+
121+
- Ading custom check - for check if file exsits before prompt a delete/flush verification. [PR-46](https://github.com/kaplanelad/shellfirm/pull/60)
122+
- Support multiple commands in one line. [MR](https://github.com/kaplanelad/shellfirm/commit/c2c4d0633dcdac38b6b44d5351179f6e1421096d)
76123

77124
BUG
78-
* Replace `~` char with home directory path. [PR-63](https://github.com/kaplanelad/shellfirm/pull/63)
79-
## 0.1.4
125+
126+
- Replace `~` char with home directory path. [PR-63](https://github.com/kaplanelad/shellfirm/pull/63)
127+
128+
## 0.1.4
80129

81130
IMPROVMENTS:
82-
* Update config file from baseline checks when `shellfirm` binary update. [PR-46](https://github.com/kaplanelad/shellfirm/pull/46)
83-
* Show single prompt verification when multiple pattern is detected. [PR-51](https://github.com/kaplanelad/shellfirm/pull/51)
84-
* Improve `rm` pattern. [PR-53](https://github.com/kaplanelad/shellfirm/pull/53)
85-
* Improve `chmod` pattern. [PR-54](https://github.com/kaplanelad/shellfirm/pull/54)
86-
* Adding reboot and shutdown risky pattern. [PR-56](https://github.com/kaplanelad/shellfirm/pull/56)
131+
132+
- Update config file from baseline checks when `shellfirm` binary update. [PR-46](https://github.com/kaplanelad/shellfirm/pull/46)
133+
- Show single prompt verification when multiple pattern is detected. [PR-51](https://github.com/kaplanelad/shellfirm/pull/51)
134+
- Improve `rm` pattern. [PR-53](https://github.com/kaplanelad/shellfirm/pull/53)
135+
- Improve `chmod` pattern. [PR-54](https://github.com/kaplanelad/shellfirm/pull/54)
136+
- Adding reboot and shutdown risky pattern. [PR-56](https://github.com/kaplanelad/shellfirm/pull/56)
87137

88138
BUG:
89-
* Ignore text between quotes. [PR-57](https://github.com/kaplanelad/shellfirm/pull/57)
90139

91-
## 0.1.3
140+
- Ignore text between quotes. [PR-57](https://github.com/kaplanelad/shellfirm/pull/57)
141+
142+
## 0.1.3
92143

93144
IMPROVEMENTS:
94-
* Improve FS checks. [PR-30](https://github.com/kaplanelad/shellfirm/pull/30)
95-
* Skip github actions on push (without PR) or on *.md file/docs folder. [PR-33](https://github.com/kaplanelad/shellfirm/pull/33)
96-
* Adding strict file sytem command. [PR-36](https://github.com/kaplanelad/shellfirm/pull/36)
97-
* FS checks - adding to `rm`/`chmod` pattern the chars `.` and `./` as risky command. [PR-38](https://github.com/kaplanelad/shellfirm/pull/38)
98-
* Adding a better error message when config file is invalid. [PR-42](https://github.com/kaplanelad/shellfirm/pull/42)
99-
* Adding kubernetes strict risky patters. [PR-41](https://github.com/kaplanelad/shellfirm/pull/41)
100-
* Allow to override deafult per pattern. [PR-43](https://github.com/kaplanelad/shellfirm/pull/43)
145+
146+
- Improve FS checks. [PR-30](https://github.com/kaplanelad/shellfirm/pull/30)
147+
- Skip github actions on push (without PR) or on \*.md file/docs folder. [PR-33](https://github.com/kaplanelad/shellfirm/pull/33)
148+
- Adding strict file sytem command. [PR-36](https://github.com/kaplanelad/shellfirm/pull/36)
149+
- FS checks - adding to `rm`/`chmod` pattern the chars `.` and `./` as risky command. [PR-38](https://github.com/kaplanelad/shellfirm/pull/38)
150+
- Adding a better error message when config file is invalid. [PR-42](https://github.com/kaplanelad/shellfirm/pull/42)
151+
- Adding kubernetes strict risky patters. [PR-41](https://github.com/kaplanelad/shellfirm/pull/41)
152+
- Allow to override deafult per pattern. [PR-43](https://github.com/kaplanelad/shellfirm/pull/43)
101153

102154
FEATURES:
103-
* Promt message while using `config reset` + ading the option to backup file. [PR-31](https://github.com/kaplanelad/shellfirm/pull/31)
155+
156+
- Promt message while using `config reset` + ading the option to backup file. [PR-31](https://github.com/kaplanelad/shellfirm/pull/31)
104157

105158
BREAKING CHANGES:
106-
* Change `is` field in yaml file to `test`. [PR-32](https://github.com/kaplanelad/shellfirm/pull/32)
159+
160+
- Change `is` field in yaml file to `test`. [PR-32](https://github.com/kaplanelad/shellfirm/pull/32)
107161

108162
## 0.1.2 - (Jan 4, 2022)
109163

110164
IMPROVEMENTS:
111-
* Mark history | sh/bash as risky command. [PR-27](https://github.com/kaplanelad/shellfirm/pull/27)
112-
* Add 2 check for `fs` group. detect `chmod 777 /` and `find -delete`. [PR-28](https://github.com/kaplanelad/shellfirm/pull/28)
165+
166+
- Mark history | sh/bash as risky command. [PR-27](https://github.com/kaplanelad/shellfirm/pull/27)
167+
- Add 2 check for `fs` group. detect `chmod 777 /` and `find -delete`. [PR-28](https://github.com/kaplanelad/shellfirm/pull/28)
113168

114169
## 0.1.1 (Jan 3, 2022)
115170

116171
IMPROVEMENTS:
117172

118-
* Add application logger. [PR-24](https://github.com/kaplanelad/shellfirm/pull/24)
173+
- Add application logger. [PR-24](https://github.com/kaplanelad/shellfirm/pull/24)
119174

120175
## 0.1.0 (Jan 2, 2022)
176+
121177
Initial release

0 commit comments

Comments
 (0)