Skip to content

Commit b2f63b5

Browse files
committed
Enforced pre-commit and CI rules to avoid .log files
1 parent c441062 commit b2f63b5

4 files changed

Lines changed: 68 additions & 1 deletion

File tree

.github/workflows/security.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Security Enforcement
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: [ feature/pre-commit-test ]
7+
8+
jobs:
9+
security:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@v4
15+
with:
16+
fetch-depth: 0
17+
18+
# Block .log files anywhere in repo
19+
- name: Block .log files
20+
run: |
21+
if git ls-files | grep -E "\.log$"; then
22+
echo "❌ .log files detected. Remove them before merge."
23+
exit 1
24+
fi
25+
26+
# Run Gitleaks (NO LICENSE REQUIRED)
27+
- name: Run Gitleaks
28+
uses: gitleaks/gitleaks-action@v2
29+
with:
30+
config-path: .gitleaks.toml

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,8 @@ Gemfile.lock
2222
# IDE files
2323
.idea/
2424
*.iml
25-
zscaler-root-ca.crt*
25+
zscaler-root-ca.crt*
26+
27+
# Log files
28+
*.log
29+
logs/

.gitleaks.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
title = "Gitleaks Config"
2+
3+
[[rules]]
4+
id = "generic-api-key"
5+
description = "Generic API Key"
6+
regex = '''(?i)(api[_-]?key|apikey|secret|token)\s*[:=]\s*['"]?[A-Za-z0-9_-]{20,}['"]?'''
7+
8+
[[rules]]
9+
id = "hardcoded-password"
10+
description = "Hardcoded password"
11+
regex = '''(?i)(password|passwd|pwd)\s*[:=]\s*['"][^'"\n]{4,}['"]'''

.pre-commit-config.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
repos:
2+
# Basic hygiene
3+
- repo: https://github.com/pre-commit/pre-commit-hooks
4+
rev: v4.6.0
5+
hooks:
6+
- id: check-added-large-files
7+
- id: end-of-file-fixer
8+
9+
# Block .log files
10+
- repo: local
11+
hooks:
12+
- id: block-log-files
13+
name: Block .log files
14+
entry: bash -c 'if git diff --cached --name-only | grep -E "\.log$"; then echo "❌ .log files are not allowed"; exit 1; fi'
15+
language: system
16+
stages: [pre-commit]
17+
18+
# Secret detection
19+
- repo: https://github.com/gitleaks/gitleaks
20+
rev: v8.18.4
21+
hooks:
22+
- id: gitleaks

0 commit comments

Comments
 (0)