@objctp/opencode-shell-routines 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +114 -0
- package/agents/shell-architect.md +88 -0
- package/agents/shell-expert.md +60 -0
- package/commands/shell-audit.md +47 -0
- package/commands/shell-batch-exec.md +48 -0
- package/commands/shell-new.md +57 -0
- package/commands/shell-routines-setup.md +66 -0
- package/commands/shell-test-run.md +46 -0
- package/opencode.json +19 -0
- package/package.json +34 -0
- package/plugins/shell-hooks.ts +150 -0
- package/scripts/lib-batch.sh +297 -0
- package/scripts/lib-common.sh +332 -0
- package/skills/shell-batch-operations/SKILL.md +97 -0
- package/skills/shell-batch-operations/assets/batch-template.sh +124 -0
- package/skills/shell-batch-operations/examples/data-pipeline.sh +157 -0
- package/skills/shell-batch-operations/examples/file-batch.sh +140 -0
- package/skills/shell-batch-operations/references/decision-tree.md +53 -0
- package/skills/shell-best-practices/SKILL.md +313 -0
- package/skills/shell-best-practices/assets/library.sh +142 -0
- package/skills/shell-best-practices/assets/minimal.sh +54 -0
- package/skills/shell-best-practices/assets/posix.sh +180 -0
- package/skills/shell-best-practices/assets/standard.sh +203 -0
- package/skills/shell-best-practices/references/patterns.md +386 -0
- package/skills/shell-best-practices/references/security.md +195 -0
- package/skills/shell-debugging/SKILL.md +115 -0
- package/skills/shell-debugging/examples/debug-session.md +165 -0
- package/skills/shell-debugging/references/debugging-guide.md +336 -0
- package/skills/shell-profiling/SKILL.md +154 -0
- package/skills/shell-profiling/examples/profile-session.md +225 -0
- package/skills/shell-profiling/references/optimisation-patterns.md +373 -0
- package/skills/shell-profiling/references/profiling-tools.md +318 -0
- package/skills/shell-profiling/scripts/bench.sh +82 -0
- package/skills/shell-profiling/scripts/trace-aggregate.sh +34 -0
- package/skills/shell-review/SKILL.md +61 -0
- package/skills/shell-review/examples/sample-review.md +42 -0
- package/skills/shell-review/references/guidelines.md +48 -0
- package/skills/shell-review/references/review-template.md +56 -0
- package/skills/shell-security/SKILL.md +128 -0
- package/skills/shell-security/examples/dangerous-command-review.md +231 -0
- package/skills/shell-security/examples/secure-script-example.sh +317 -0
- package/skills/shell-security/references/dangerous-commands.md +561 -0
- package/skills/shell-security/references/security-patterns.md +30 -0
- package/skills/shell-security/references/sensitive-files.md +525 -0
- package/skills/shell-security/scripts/security-audit.sh +208 -0
- package/skills/shell-test/SKILL.md +237 -0
- package/skills/shell-test/examples/test-example.md +74 -0
- package/skills/shell-test/references/advanced-patterns.md +52 -0
- package/skills/shell-test/references/assertions.md +184 -0
- package/skills/shell-test/references/test-template.md +60 -0
- package/skills/shell-test/scripts/public-coverage.sh +93 -0
|
@@ -0,0 +1,525 @@
|
|
|
1
|
+
# Sensitive Files Reference
|
|
2
|
+
|
|
3
|
+
Files and directories that require careful handling in shell scripts due to security implications.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
| Category | Risk Level | Examples |
|
|
8
|
+
|----------|------------|----------|
|
|
9
|
+
| **Authentication & Credentials** | ● Severe | SSH keys, API tokens, certificates |
|
|
10
|
+
| **System Configuration** | ◆ Fatal | /etc/passwd, /etc/sudoers, /etc/shadow |
|
|
11
|
+
| **User Configuration** | ▲ Moderate | ~/.bashrc, ~/.ssh/config |
|
|
12
|
+
| **Data & Secrets** | ● Severe | .env files, certificates, vault passwords |
|
|
13
|
+
| **Package & Build** | ▲ Moderate | package.json, requirements.txt |
|
|
14
|
+
| **Temporary & Cache** | ▲ Moderate | /tmp files, cache directories |
|
|
15
|
+
| **Git & Version Control** | ▲ Moderate | .git/config, .git-credentials |
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## Authentication & Credentials
|
|
20
|
+
|
|
21
|
+
### SSH Keys and Config
|
|
22
|
+
|
|
23
|
+
**Files:**
|
|
24
|
+
- `~/.ssh/id_rsa` — Private RSA key
|
|
25
|
+
- `~/.ssh/id_ed25519` — Private Ed25519 key
|
|
26
|
+
- `~/.ssh/config` — SSH client configuration
|
|
27
|
+
- `~/.ssh/known_hosts` — Server fingerprint cache
|
|
28
|
+
- `~/.ssh/authorized_keys` — Public keys for login
|
|
29
|
+
- `/etc/ssh/ssh_host_*_key` — Host private keys
|
|
30
|
+
|
|
31
|
+
**Risks:**
|
|
32
|
+
- Private key leakage allows unauthorised access
|
|
33
|
+
- Modified config can redirect connections
|
|
34
|
+
- Corrupted authorized_keys prevents login
|
|
35
|
+
|
|
36
|
+
**Safe handling:**
|
|
37
|
+
```bash
|
|
38
|
+
# Check file existence before operations
|
|
39
|
+
[[ -f ~/.ssh/id_rsa ]] || { echo "Key not found" >&2; exit 1; }
|
|
40
|
+
|
|
41
|
+
# Set restrictive permissions
|
|
42
|
+
chmod 700 ~/.ssh
|
|
43
|
+
chmod 600 ~/.ssh/id_rsa
|
|
44
|
+
chmod 644 ~/.ssh/id_rsa.pub
|
|
45
|
+
chmod 600 ~/.ssh/config
|
|
46
|
+
chmod 644 ~/.ssh/known_hosts
|
|
47
|
+
|
|
48
|
+
# Backup before modifying
|
|
49
|
+
cp ~/.ssh/config ~/.ssh/config.bak
|
|
50
|
+
# ... modify ...
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
### GPG Keys
|
|
56
|
+
|
|
57
|
+
**Files:**
|
|
58
|
+
- `~/.gnupg/private-keys-v1.d/*.key` — Private key rings
|
|
59
|
+
- `~/.gnupg/pubring.kbx` — Public key ring
|
|
60
|
+
- `~/.gnupg/gpg-agent.conf` — Agent configuration
|
|
61
|
+
|
|
62
|
+
**Risks:**
|
|
63
|
+
- Private key compromise defeats encryption
|
|
64
|
+
- Agent misconfiguration can expose keys
|
|
65
|
+
|
|
66
|
+
**Safe handling:**
|
|
67
|
+
```bash
|
|
68
|
+
# Use gpg CLI instead of direct file manipulation
|
|
69
|
+
gpg --export-secret-keys KEYID > backup.gpg
|
|
70
|
+
# NOT: cp ~/.gnupg/private-keys-v1.d/* /backup/
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
### AWS Credentials
|
|
76
|
+
|
|
77
|
+
**Files:**
|
|
78
|
+
- `~/.aws/credentials` — AWS access keys
|
|
79
|
+
- `~/.aws/config` — AWS configuration
|
|
80
|
+
- `/etc/cloud/templates/credentials*` — Cloud credentials
|
|
81
|
+
|
|
82
|
+
**Risks:**
|
|
83
|
+
- Credential exposure enables AWS account takeover
|
|
84
|
+
- Hard-coded credentials in scripts
|
|
85
|
+
|
|
86
|
+
**Safe handling:**
|
|
87
|
+
```bash
|
|
88
|
+
# Use AWS CLI or SDK credential sources
|
|
89
|
+
aws s3 ls # Uses ~/.aws/credentials or IAM role
|
|
90
|
+
|
|
91
|
+
# Never hard-code
|
|
92
|
+
# DON'T: export AWS_ACCESS_KEY_ID="AKIA..."
|
|
93
|
+
|
|
94
|
+
# Use environment variables only in controlled environments
|
|
95
|
+
export AWS_PROFILE=production
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
### Docker Credentials
|
|
101
|
+
|
|
102
|
+
**Files:**
|
|
103
|
+
- `~/.docker/config.json` — Docker registry auth tokens
|
|
104
|
+
- `/var/lib/docker/containers/*/config.json` — Container configs
|
|
105
|
+
|
|
106
|
+
**Risks:**
|
|
107
|
+
- Registry tokens allow image push/pull
|
|
108
|
+
- Contains base64-encoded passwords
|
|
109
|
+
|
|
110
|
+
**Safe handling:**
|
|
111
|
+
```bash
|
|
112
|
+
# Use docker login command
|
|
113
|
+
docker login registry.example.com
|
|
114
|
+
|
|
115
|
+
# NOT: echo '{"auths":{"..."}' > ~/.docker/config.json
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
### Git Credentials
|
|
121
|
+
|
|
122
|
+
**Files:**
|
|
123
|
+
- `~/.git-credentials` — Stored credentials
|
|
124
|
+
- `~/.netrc` — Generic credentials (FTP, HTTP)
|
|
125
|
+
- `.git/config` — Repository URLs (may contain tokens)
|
|
126
|
+
|
|
127
|
+
**Risks:**
|
|
128
|
+
- Stored passwords can be extracted
|
|
129
|
+
- Tokens in remote URLs
|
|
130
|
+
|
|
131
|
+
**Safe handling:**
|
|
132
|
+
```bash
|
|
133
|
+
# Use credential helpers
|
|
134
|
+
git config --global credential.helper osxkeychain # macOS
|
|
135
|
+
git config --global credential.helper cache # In-memory
|
|
136
|
+
|
|
137
|
+
# Avoid embedding tokens in URLs
|
|
138
|
+
# DON'T: git remote add origin https://token@github.com/repo.git
|
|
139
|
+
# DO: git remote add origin https://github.com/repo.git
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
## System Configuration
|
|
145
|
+
|
|
146
|
+
### User Database
|
|
147
|
+
|
|
148
|
+
**Files:**
|
|
149
|
+
- `/etc/passwd` — User account information
|
|
150
|
+
- `/etc/shadow` — Password hashes
|
|
151
|
+
- `/etc/group` — Group definitions
|
|
152
|
+
- `/etc/gshadow` — Group passwords
|
|
153
|
+
|
|
154
|
+
**Risks:**
|
|
155
|
+
- System breakage if corrupted
|
|
156
|
+
- Security breach if passwords exposed
|
|
157
|
+
- Privilege escalation if modified
|
|
158
|
+
|
|
159
|
+
**Safe handling:**
|
|
160
|
+
```bash
|
|
161
|
+
# Use proper tools
|
|
162
|
+
vipw # Edit /etc/passwd
|
|
163
|
+
vigr # Edit /etc/group
|
|
164
|
+
|
|
165
|
+
# NEVER write directly
|
|
166
|
+
# DON'T: echo "user:x:1000:1000::/home/user:/bin/bash" >> /etc/passwd
|
|
167
|
+
|
|
168
|
+
# For automation, use useradd/usermod
|
|
169
|
+
useradd -m -s /bin/bash newuser
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
---
|
|
173
|
+
|
|
174
|
+
### Sudo Configuration
|
|
175
|
+
|
|
176
|
+
**Files:**
|
|
177
|
+
- `/etc/sudoers` — Sudo access rules
|
|
178
|
+
- `/etc/sudoers.d/*` — Additional rules
|
|
179
|
+
|
|
180
|
+
**Risks:**
|
|
181
|
+
- Syntax error prevents sudo usage
|
|
182
|
+
- Overly permissive rules enable escalation
|
|
183
|
+
- Comments or edits can break sudo
|
|
184
|
+
|
|
185
|
+
**Safe handling:**
|
|
186
|
+
```bash
|
|
187
|
+
# ALWAYS use visudo
|
|
188
|
+
visudo # Edits with validation
|
|
189
|
+
|
|
190
|
+
# For automation
|
|
191
|
+
visudo -c -f /etc/sudoers.d/newfile # Check before deploy
|
|
192
|
+
|
|
193
|
+
# DON'T: echo "user ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
---
|
|
197
|
+
|
|
198
|
+
### System Services
|
|
199
|
+
|
|
200
|
+
**Files:**
|
|
201
|
+
- `/etc/crontab` — System cron jobs
|
|
202
|
+
- `/etc/cron.*/*` — Scheduled tasks
|
|
203
|
+
- `/etc/systemd/system/*` — Service units
|
|
204
|
+
- `/etc/hosts` — Hostname mappings
|
|
205
|
+
|
|
206
|
+
**Risks:**
|
|
207
|
+
- Service disruption if corrupted
|
|
208
|
+
- Unauthorised task execution
|
|
209
|
+
- Privilege escalation
|
|
210
|
+
|
|
211
|
+
**Safe handling:**
|
|
212
|
+
```bash
|
|
213
|
+
# Use systemd tools
|
|
214
|
+
systemctl edit service-name # Creates override
|
|
215
|
+
systemctl daemon-reload # After editing units
|
|
216
|
+
|
|
217
|
+
# For cron
|
|
218
|
+
crontab -e # User crontabs
|
|
219
|
+
# System crontabs: edit and validate syntax
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
---
|
|
223
|
+
|
|
224
|
+
## User Configuration
|
|
225
|
+
|
|
226
|
+
### Shell Configuration
|
|
227
|
+
|
|
228
|
+
**Files:**
|
|
229
|
+
- `~/.bashrc` — Bash interactive shell config
|
|
230
|
+
- `~/.bash_profile` — Bash login shell config
|
|
231
|
+
- `~/.profile` — POSIX shell config
|
|
232
|
+
- `~/.zshrc` — Zsh configuration
|
|
233
|
+
- `/etc/profile` — System-wide profile
|
|
234
|
+
|
|
235
|
+
**Risks:**
|
|
236
|
+
- Malicious code in startup files
|
|
237
|
+
- PATH manipulation leading to trojan horses
|
|
238
|
+
- Environment variable leakage
|
|
239
|
+
|
|
240
|
+
**Safe handling:**
|
|
241
|
+
```bash
|
|
242
|
+
# Validate before sourcing
|
|
243
|
+
validate_shell_rc() {
|
|
244
|
+
local file="$1"
|
|
245
|
+
[[ -f "$file" ]] || return 1
|
|
246
|
+
[[ -r "$file" ]] || return 1
|
|
247
|
+
# Check for suspicious patterns
|
|
248
|
+
grep -qE 'eval\s+\$|exec\s+\$|alias\s+sudo=' "$file" && return 1
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
# Safer sourcing
|
|
252
|
+
validate_shell_rc ~/.bashrc && source ~/.bashrc
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
---
|
|
256
|
+
|
|
257
|
+
### Application Config
|
|
258
|
+
|
|
259
|
+
**Files:**
|
|
260
|
+
- `~/.config/*` — Application configuration (XDG)
|
|
261
|
+
- `~/.local/share/*` — Application data
|
|
262
|
+
- `~/Library/Preferences/*` — macOS preferences
|
|
263
|
+
|
|
264
|
+
**Risks:**
|
|
265
|
+
- Contains API keys, tokens
|
|
266
|
+
- May have executable snippets
|
|
267
|
+
|
|
268
|
+
**Safe handling:**
|
|
269
|
+
```bash
|
|
270
|
+
# Mask sensitive values when viewing
|
|
271
|
+
grep -vE '(password|token|key)\s*=' ~/.config/app.conf
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
---
|
|
275
|
+
|
|
276
|
+
## Data & Secrets
|
|
277
|
+
|
|
278
|
+
### Environment Files
|
|
279
|
+
|
|
280
|
+
**Files:**
|
|
281
|
+
- `.env` — Environment variables
|
|
282
|
+
- `.env.local` — Local overrides
|
|
283
|
+
- `.env.production` — Production secrets
|
|
284
|
+
- `*.key` — Private key files
|
|
285
|
+
- `*.pem` — Certificate files
|
|
286
|
+
- `secrets.*` — Secret storage
|
|
287
|
+
- `credentials.json` — Google Cloud credentials
|
|
288
|
+
- `.vault_pass` — Ansible vault password
|
|
289
|
+
|
|
290
|
+
**Risks:**
|
|
291
|
+
- Credential exposure if committed
|
|
292
|
+
- API key leakage
|
|
293
|
+
- Database connection strings
|
|
294
|
+
|
|
295
|
+
**Safe handling:**
|
|
296
|
+
```bash
|
|
297
|
+
# Add to .gitignore
|
|
298
|
+
cat >> .gitignore << 'EOF'
|
|
299
|
+
.env
|
|
300
|
+
.env.*
|
|
301
|
+
*.key
|
|
302
|
+
*.pem
|
|
303
|
+
secrets.*
|
|
304
|
+
credentials.json
|
|
305
|
+
.vault_pass
|
|
306
|
+
EOF
|
|
307
|
+
|
|
308
|
+
# Load with validation
|
|
309
|
+
load_env() {
|
|
310
|
+
local env_file=".env"
|
|
311
|
+
[[ -f "$env_file" ]] || { echo "No .env file" >&2; return 1; }
|
|
312
|
+
set -a # Auto-export
|
|
313
|
+
source "$env_file"
|
|
314
|
+
set +a
|
|
315
|
+
# Verify required variables
|
|
316
|
+
: "${DATABASE_URL:?DATABASE_URL not set in .env}"
|
|
317
|
+
: "${API_KEY:?API_KEY not set in .env}"
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
# Use sed to mask secrets when logging
|
|
321
|
+
mask_secrets() {
|
|
322
|
+
sed -E 's/(password|token|key)=[^[:space:]]+/\1=[REDACTED]/g'
|
|
323
|
+
}
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
---
|
|
327
|
+
|
|
328
|
+
### Certificates
|
|
329
|
+
|
|
330
|
+
**Files:**
|
|
331
|
+
- `*.crt` — Certificates
|
|
332
|
+
- `*.pem` — PEM-encoded certificates/keys
|
|
333
|
+
- `*.key` — Private keys
|
|
334
|
+
- `*.p12` — PKCS#12 bundles
|
|
335
|
+
- `*.jks` — Java key stores
|
|
336
|
+
|
|
337
|
+
**Risks:**
|
|
338
|
+
- Private key exposure
|
|
339
|
+
- Certificate expiration
|
|
340
|
+
- Man-in-the-middle if wrong cert
|
|
341
|
+
|
|
342
|
+
**Safe handling:**
|
|
343
|
+
```bash
|
|
344
|
+
# Verify certificate expiry
|
|
345
|
+
check_cert_expiry() {
|
|
346
|
+
local cert="$1"
|
|
347
|
+
local days=30
|
|
348
|
+
local expiry
|
|
349
|
+
expiry=$(openssl x509 -enddate -noout -in "$cert" | cut -d= -f2)
|
|
350
|
+
expiry_date=$(date -d "$expiry" +%s)
|
|
351
|
+
current_date=$(date +%s)
|
|
352
|
+
(( (expiry_date - current_date) / 86400 < days )) && echo "Cert expiring soon"
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
# Validate permissions
|
|
356
|
+
chmod 600 *.key
|
|
357
|
+
chmod 644 *.crt
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
---
|
|
361
|
+
|
|
362
|
+
## Package & Build Files
|
|
363
|
+
|
|
364
|
+
### Dependency Files
|
|
365
|
+
|
|
366
|
+
**Files:**
|
|
367
|
+
- `package.json` / `package-lock.json` — Node.js
|
|
368
|
+
- `requirements.txt` / `Pipfile.lock` — Python
|
|
369
|
+
- `Gemfile` / `Gemfile.lock` — Ruby
|
|
370
|
+
- `go.mod` / `go.sum` — Go
|
|
371
|
+
- `Cargo.toml` / `Cargo.lock` — Rust
|
|
372
|
+
- `composer.json` — PHP
|
|
373
|
+
|
|
374
|
+
**Risks:**
|
|
375
|
+
- May contain embedded credentials
|
|
376
|
+
- Supply chain attacks via malicious packages
|
|
377
|
+
- Lock file manipulation
|
|
378
|
+
|
|
379
|
+
**Safe handling:**
|
|
380
|
+
```bash
|
|
381
|
+
# Scan for secrets before committing
|
|
382
|
+
scan_package_files() {
|
|
383
|
+
grep -rE '(api_key|password|secret|token)\s*=\s*["\047]' package.json requirements.txt
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
# Use lock files for reproducibility
|
|
387
|
+
# Commit lock files, verify no unexpected changes
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
---
|
|
391
|
+
|
|
392
|
+
## Temporary & Cache Files
|
|
393
|
+
|
|
394
|
+
### Temporary Directories
|
|
395
|
+
|
|
396
|
+
**Files:**
|
|
397
|
+
- `/tmp/*` — System temporary files
|
|
398
|
+
- `/var/tmp/*` — Persistent temporary files
|
|
399
|
+
- `~/.cache/*` — User cache
|
|
400
|
+
- `*.swp` — Vim swap files
|
|
401
|
+
- `*~` — Backup files
|
|
402
|
+
|
|
403
|
+
**Risks:**
|
|
404
|
+
- May contain sensitive data
|
|
405
|
+
- Permissions issues
|
|
406
|
+
- Race conditions in creation
|
|
407
|
+
|
|
408
|
+
**Safe handling:**
|
|
409
|
+
```bash
|
|
410
|
+
# Use mktemp for secure temp file creation
|
|
411
|
+
tmpfile=$(mktemp) || exit 1
|
|
412
|
+
chmod 600 "$tmpfile"
|
|
413
|
+
# ... use file ...
|
|
414
|
+
rm -f "$tmpfile"
|
|
415
|
+
|
|
416
|
+
# For directories
|
|
417
|
+
tmpdir=$(mktemp -d) || exit 1
|
|
418
|
+
chmod 700 "$tmpdir"
|
|
419
|
+
|
|
420
|
+
# NOT: tmpfile=/tmp/myfile_$$
|
|
421
|
+
```
|
|
422
|
+
|
|
423
|
+
---
|
|
424
|
+
|
|
425
|
+
## Git & Version Control
|
|
426
|
+
|
|
427
|
+
### Git Configuration
|
|
428
|
+
|
|
429
|
+
**Files:**
|
|
430
|
+
- `.git/config` — Repository configuration
|
|
431
|
+
- `.git/hooks/*` — Git hooks
|
|
432
|
+
- `.git/HEAD` — Current branch
|
|
433
|
+
- `.git/refs/*` — Branch references
|
|
434
|
+
|
|
435
|
+
**Risks:**
|
|
436
|
+
- Hooks can execute arbitrary code
|
|
437
|
+
- Config may contain credentials
|
|
438
|
+
- Refs can be manipulated
|
|
439
|
+
|
|
440
|
+
**Safe handling:**
|
|
441
|
+
```bash
|
|
442
|
+
# Verify hooks before running
|
|
443
|
+
for hook in .git/hooks/*; do
|
|
444
|
+
[[ -x "$hook" ]] && echo "Executable hook: $hook"
|
|
445
|
+
# Review hook content
|
|
446
|
+
done
|
|
447
|
+
|
|
448
|
+
# Don't commit hooks
|
|
449
|
+
echo ".git/hooks/" >> .gitignore
|
|
450
|
+
|
|
451
|
+
# Check for credentials in config
|
|
452
|
+
grep -iE '(credential|token|password)' .git/config
|
|
453
|
+
```
|
|
454
|
+
|
|
455
|
+
---
|
|
456
|
+
|
|
457
|
+
## Safe File Handling Checklist
|
|
458
|
+
|
|
459
|
+
```bash
|
|
460
|
+
# Template for safe file operations
|
|
461
|
+
|
|
462
|
+
safe_file_operation() {
|
|
463
|
+
local file="$1"
|
|
464
|
+
local operation="$2" # read, write, delete
|
|
465
|
+
|
|
466
|
+
# Check file type
|
|
467
|
+
case "$file" in
|
|
468
|
+
/etc/passwd|/etc/shadow|/etc/sudoers)
|
|
469
|
+
echo "FATAL: Refusing to operate on critical system file: $file" >&2
|
|
470
|
+
return 1
|
|
471
|
+
;;
|
|
472
|
+
~/.ssh/id_*|*.pem|*.key)
|
|
473
|
+
if [[ "$operation" == "write" ]]; then
|
|
474
|
+
echo "ERROR: Refusing to overwrite sensitive file: $file" >&2
|
|
475
|
+
return 1
|
|
476
|
+
fi
|
|
477
|
+
;;
|
|
478
|
+
.env|*.env|secrets.*)
|
|
479
|
+
echo "WARNING: Operating on secrets file: $file" >&2
|
|
480
|
+
;;
|
|
481
|
+
esac
|
|
482
|
+
|
|
483
|
+
# Check file existence
|
|
484
|
+
if [[ "$operation" == "write" ]] && [[ -f "$file" ]]; then
|
|
485
|
+
echo "ERROR: File exists, refusing to overwrite: $file" >&2
|
|
486
|
+
return 1
|
|
487
|
+
fi
|
|
488
|
+
|
|
489
|
+
# Check permissions
|
|
490
|
+
if [[ -e "$file" ]] && ! [[ -r "$file" ]]; then
|
|
491
|
+
echo "ERROR: File not readable: $file" >&2
|
|
492
|
+
return 1
|
|
493
|
+
fi
|
|
494
|
+
|
|
495
|
+
# Perform operation
|
|
496
|
+
case "$operation" in
|
|
497
|
+
read)
|
|
498
|
+
cat "$file"
|
|
499
|
+
;;
|
|
500
|
+
write)
|
|
501
|
+
echo "$operation" > "$file"
|
|
502
|
+
;;
|
|
503
|
+
delete)
|
|
504
|
+
rm -i "$file" # Confirm before delete
|
|
505
|
+
;;
|
|
506
|
+
esac
|
|
507
|
+
}
|
|
508
|
+
```
|
|
509
|
+
|
|
510
|
+
---
|
|
511
|
+
|
|
512
|
+
## Quick Reference
|
|
513
|
+
|
|
514
|
+
| File Pattern | Permission | Owner | Notes |
|
|
515
|
+
|--------------|------------|-------|-------|
|
|
516
|
+
| `~/.ssh/id_*` | 600 | user | Private keys |
|
|
517
|
+
| `~/.ssh/*.pub` | 644 | user | Public keys |
|
|
518
|
+
| `~/.ssh/config` | 600 | user | SSH config |
|
|
519
|
+
| `~/.gnupg/` | 700 | user | GPG home |
|
|
520
|
+
| `.env` | 600 | user | Secrets |
|
|
521
|
+
| `*.key` | 600 | user | Private keys |
|
|
522
|
+
| `*.pem` | 600 | user | Keys/certs |
|
|
523
|
+
| `*.crt` | 644 | user | Certificates |
|
|
524
|
+
| `/etc/shadow` | 000 | root | Password hashes |
|
|
525
|
+
| `/etc/sudoers` | 440 | root | Sudo config |
|