Skip to content

Commit 107dd18

Browse files
Fix TypeScript compilation errors (Phase 1) (#79)
Merge critical fixes: SSH validation, data loss prevention, security updates, simplified README This merge includes 7 commits with critical bug fixes and improvements: - SSH key validation enforcement (security fix) - Data persistence by default (UX fix) - Security vulnerability fixes (3 CVEs) - Simplified README documentation - Comprehensive testing infrastructure - TypeScript compilation fixes - First-run success improvements
1 parent d45718c commit 107dd18

29 files changed

Lines changed: 5072 additions & 246 deletions

.gitignore

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -403,13 +403,12 @@ $RECYCLE.BIN/
403403
.nfs*
404404

405405
# ======================================
406-
# TEST AND DOCUMENTATION DIRECTORIES - NEVER COMMIT
406+
# TEST DIRECTORIES - NEVER COMMIT
407407
# ======================================
408408

409-
# Project-specific test and documentation directories
409+
# Project-specific test directories
410410
/test/
411411
/tests/
412-
/docs/
413412
backend/test/
414413
backend/tests/
415414
frontend/test/
@@ -597,7 +596,7 @@ test_comprehensive*.py
597596

598597
# Test report and summary files
599598
*_TEST_REPORT.md
600-
*_SUMMARY.md
599+
*_TEST_SUMMARY.md
601600
COMPREHENSIVE_TEST_REPORT.md
602601
TROUBLESHOOTING_SUMMARY.md
603602
gitignore_recommendations.md
@@ -694,4 +693,22 @@ scripts/*phase*.py
694693

695694
# Demo and phase files
696695
*phase*.py
697-
*demo*.py
696+
*demo*.py
697+
# ======================================
698+
# TEMPORARY AND DEBUG FILES
699+
# ======================================
700+
701+
# Debug logs in docs
702+
docs/log_*.txt
703+
docs/*-output
704+
docs/*-log
705+
docs/*.log
706+
707+
# Temporary CLI fix scripts
708+
backend/app/cli/*_fixed.py
709+
backend/app/cli/*_backup.py
710+
backend/app/cli/*_temp.py
711+
712+
# Installation/migration outputs
713+
*-installation-output
714+
*-migration-output

DATA_LOSS_FIX_SUMMARY.md

Lines changed: 241 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,241 @@
1+
# Data Loss Fix Summary
2+
3+
## Problem
4+
5+
User reported all configuration data disappeared after running:
6+
```bash
7+
./stop-openwatch.sh
8+
./start-openwatch.sh --force-build --runtime docker
9+
```
10+
11+
All hosts, system credentials, and compliance rules were lost, despite Docker volumes being properly configured.
12+
13+
## Root Cause
14+
15+
The `stop-openwatch.sh` script defaulted to **CLEAN_MODE=true**, which executed:
16+
```bash
17+
docker-compose down --volumes --remove-orphans
18+
```
19+
20+
This deleted all Docker volumes, including:
21+
- `openwatch_postgres_data` - User accounts, hosts, scan history
22+
- `openwatch_mongodb_data` - Compliance rules (1,387 SCAP rules)
23+
- `openwatch_app_data` - Uploaded SCAP content and scan results
24+
25+
**Critical code (line 21 of stop-openwatch.sh):**
26+
```bash
27+
CLEAN_MODE=${OPENWATCH_CLEAN_STOP:-true} # Default to clean stop for development
28+
```
29+
30+
The script was designed for rapid development iteration, but users expected "stop" to preserve data.
31+
32+
## Solution
33+
34+
Changed default behavior from **destructive** to **safe**:
35+
36+
### Changes to stop-openwatch.sh
37+
38+
1. **Changed default to safe mode** (line 21):
39+
```bash
40+
# Before:
41+
CLEAN_MODE=${OPENWATCH_CLEAN_STOP:-true} # Default to clean stop for development
42+
43+
# After:
44+
CLEAN_MODE=${OPENWATCH_CLEAN_STOP:-false} # Default to SAFE stop - preserves data
45+
```
46+
47+
2. **Added prominent warnings** when clean mode is active:
48+
```bash
49+
log_warning "⚠️ CLEAN MODE: Will DELETE ALL DATA (volumes will be removed)"
50+
log_warning "⚠️ This includes hosts, credentials, scan results, and SCAP content"
51+
```
52+
53+
3. **Updated help documentation** to clarify safe vs clean behavior
54+
55+
4. **Updated default messaging**:
56+
```bash
57+
log_info "Safe mode: Stopping containers but preserving data volumes"
58+
log_info "Use OPENWATCH_CLEAN_STOP=true for clean development environment"
59+
```
60+
61+
### New Behavior
62+
63+
**Safe stop (default):**
64+
```bash
65+
./stop-openwatch.sh
66+
# Containers stopped, data preserved
67+
```
68+
69+
**Clean stop (explicit):**
70+
```bash
71+
OPENWATCH_CLEAN_STOP=true ./stop-openwatch.sh
72+
# Containers stopped, ALL DATA DELETED
73+
```
74+
75+
**Nuclear option (unchanged):**
76+
```bash
77+
./stop-openwatch.sh --deep-clean
78+
# Removes containers, volumes, networks, orphans
79+
```
80+
81+
## Documentation
82+
83+
Created comprehensive documentation:
84+
85+
1. **docs/DATA_PERSISTENCE.md** - Complete guide covering:
86+
- Volume mappings and data storage
87+
- Safe vs clean mode comparison
88+
- Common scenarios with examples
89+
- Troubleshooting data issues
90+
- Backup procedures
91+
- Best practices
92+
93+
2. **README.md updates**:
94+
- Added warning about data preservation
95+
- Updated container runtime examples
96+
- Added "Data disappeared after restart" troubleshooting section
97+
98+
## Testing
99+
100+
Verified changes:
101+
```bash
102+
# Test help message
103+
./stop-openwatch.sh --help
104+
# ✅ Shows safe mode as default
105+
# ✅ Shows warnings about data deletion
106+
# ✅ Shows correct usage examples
107+
108+
# Test safe mode
109+
./stop-openwatch.sh
110+
# ✅ Shows "Safe mode: Preserving data volumes"
111+
# ✅ Does NOT pass --volumes to docker-compose
112+
113+
# Test clean mode
114+
OPENWATCH_CLEAN_STOP=true ./stop-openwatch.sh
115+
# ✅ Shows "CLEAN MODE: Will DELETE ALL DATA"
116+
# ✅ Shows warning about data types
117+
```
118+
119+
## Impact
120+
121+
**Positive:**
122+
- Users' data will be preserved across restarts
123+
- Principle of least surprise - "stop" no longer deletes data
124+
- Explicit opt-in required for destructive operations
125+
- Clear warnings when data will be deleted
126+
127+
**Neutral:**
128+
- Developers need to use `OPENWATCH_CLEAN_STOP=true` for clean environments
129+
- Adds one extra step for development workflow
130+
- Disk space usage may increase (volumes not automatically cleaned)
131+
132+
**No Breaking Changes:**
133+
- All existing flags still work (`--simple`, `--deep-clean`)
134+
- Environment variable still works (just inverted default)
135+
- Docker volume behavior unchanged
136+
- Container runtime detection unchanged
137+
138+
## User Impact
139+
140+
**For the reporting user:**
141+
- Data already lost (must re-enter hosts, credentials, SCAP content)
142+
- Future restarts will preserve data
143+
- Update to latest `stop-openwatch.sh` via `git pull`
144+
145+
**For all users:**
146+
- Safer default behavior prevents accidental data loss
147+
- Must explicitly request data deletion
148+
- Better matches user expectations
149+
150+
## Migration Notes
151+
152+
**Scripts that relied on automatic cleanup:**
153+
154+
Before:
155+
```bash
156+
./stop-openwatch.sh # Deleted all data
157+
```
158+
159+
After (equivalent behavior):
160+
```bash
161+
OPENWATCH_CLEAN_STOP=true ./stop-openwatch.sh # Deletes all data
162+
```
163+
164+
**Scripts that preserved data:**
165+
166+
Before:
167+
```bash
168+
./stop-openwatch.sh --simple # Preserved data
169+
```
170+
171+
After (unchanged):
172+
```bash
173+
./stop-openwatch.sh # Preserves data (now default)
174+
./stop-openwatch.sh --simple # Also preserves data (unchanged)
175+
```
176+
177+
## Verification Checklist
178+
179+
- [x] Default mode changed from clean to safe
180+
- [x] Warnings added for destructive operations
181+
- [x] Help text updated with correct examples
182+
- [x] Documentation created (DATA_PERSISTENCE.md)
183+
- [x] README updated with troubleshooting
184+
- [x] Tested help message output
185+
- [x] Verified volume preservation behavior
186+
- [x] No breaking changes to existing flags
187+
- [x] Environment variable behavior inverted but working
188+
189+
## Files Changed
190+
191+
1. `stop-openwatch.sh` - 5 edits to default behavior and messaging
192+
2. `docs/DATA_PERSISTENCE.md` - New comprehensive guide (350+ lines)
193+
3. `README.md` - Updated container runtime section and troubleshooting
194+
4. `DATA_LOSS_FIX_SUMMARY.md` - This document
195+
196+
## Commit Message
197+
198+
```
199+
Fix data loss: Change stop-openwatch.sh default to safe mode
200+
201+
BREAKING CHANGE for development workflows:
202+
- Default behavior now PRESERVES data volumes (was: delete)
203+
- Must use OPENWATCH_CLEAN_STOP=true for clean development environment
204+
205+
Problem:
206+
Users reported all data (hosts, credentials, SCAP content) disappeared
207+
after running ./stop-openwatch.sh. Root cause: script defaulted to
208+
CLEAN_MODE=true which runs "docker-compose down --volumes".
209+
210+
Solution:
211+
- Changed CLEAN_MODE default from true to false
212+
- Added prominent warnings when clean mode is active
213+
- Updated help text to clarify safe vs destructive behavior
214+
- Created comprehensive DATA_PERSISTENCE.md documentation
215+
216+
Impact:
217+
- Safe by default: "stop" no longer deletes data
218+
- Explicit opt-in required for destructive operations
219+
- Principle of least surprise: matches user expectations
220+
221+
Migration:
222+
Old: ./stop-openwatch.sh # Deleted data
223+
New: OPENWATCH_CLEAN_STOP=true ./stop-openwatch.sh # Equivalent
224+
225+
Files changed:
226+
- stop-openwatch.sh: Default to safe mode with warnings
227+
- docs/DATA_PERSISTENCE.md: Complete data persistence guide
228+
- README.md: Updated usage examples and troubleshooting
229+
- DATA_LOSS_FIX_SUMMARY.md: Technical documentation
230+
231+
🤖 Generated with Claude Code
232+
Co-Authored-By: Claude <noreply@anthropic.com>
233+
```
234+
235+
## Lessons Learned
236+
237+
1. **Default to safe** - Destructive operations should require explicit opt-in
238+
2. **Warn prominently** - Critical operations need visual warnings
239+
3. **Document behavior** - Users need clear documentation of data handling
240+
4. **Test user assumptions** - "Stop" should not delete data
241+
5. **Fail safe** - Better to waste disk space than lose user data

0 commit comments

Comments
 (0)