Skip to content

Commit 2af73e3

Browse files
committed
auto-sync: [Sun Mar 15 01:47:22 PM -03 2026]
1 parent 3939587 commit 2af73e3

File tree

9 files changed

+126
-64
lines changed

9 files changed

+126
-64
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Secret Scanning
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
scan:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout Code
14+
uses: actions/checkout@v4
15+
with:
16+
fetch-depth: 0
17+
18+
- name: Gitleaks Scan
19+
uses: gitleaks/gitleaks-action@v2
20+
env:
21+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.ignore_stow/git_push_dotfiles.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@
55
# Change to your dotfiles directory
66
cd $HOME/dotfiles || exit
77

8+
# Scan for secrets before doing anything
9+
echo "Running secret scan..."
10+
./scripts/security/scan_secrets.sh
11+
if [ $? -ne 0 ]; then
12+
echo " Sync aborted: Secrets detected!"
13+
exit 1
14+
fi
15+
816
# Add all changes
917
git add -A
1018

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Dotfiles Security
2+
3+
This repository includes automated secret scanning to prevent sensitive information (API keys, passwords, private keys) from being pushed to GitHub.
4+
5+
## Security Measures
6+
7+
- **Secret Scanner Script**: `scripts/security/scan_secrets.sh` - Uses `git grep` with robust regex patterns to find potential secrets.
8+
- **Git Hooks**:
9+
- `pre-commit`: Scans tracked files before every commit.
10+
- `pre-push`: Scans tracked files before every push.
11+
- **GitHub Action**: `.github/workflows/secret-scanning.yml` - Runs Gitleaks on every push to the remote.
12+
- **Enhanced Sync Script**:
13+
- `.ignore_stow/git_push_dotfiles.sh`
14+
This script explicitly runs the secret scanner before proceeding.
15+
16+
## Installation of Git Hooks
17+
18+
Ensure the git hooks are executable to activate the local protection:
19+
```bash
20+
chmod +x .git/hooks/pre-commit .git/hooks/pre-push
21+
```
22+
The hooks are configured to call `scripts/security/scan_secrets.sh` before every commit and push.
23+
24+
## How to handle false positives
25+
26+
If the scanner finds a false positive (a string that looks like a secret but isn't), you can:
27+
1. **Refine the regex** in `scripts/security/scan_secrets.sh`.
28+
2. **Add the file or directory** to the `EXCLUDE` list in `scripts/security/scan_secrets.sh`.

git/.config/git/hooks/pre-push

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env bash
2+
3+
# Global Gitleaks Pre-push Hook
4+
# This will prevent any push that contains potential secrets
5+
6+
if command -v gitleaks >/dev/null 2>&1; then
7+
echo -e "\033[1;33m[Gitleaks] Scanning your commits for secrets...\033[0m"
8+
9+
# --staged: scan what's about to be pushed
10+
# --verbose: show details on match
11+
# --redact: hide the actual secret in the output
12+
gitleaks protect --staged --verbose --redact
13+
14+
EXIT_CODE=$?
15+
16+
if [[ $EXIT_CODE -ne 0 ]]; then
17+
echo -e "\033[0;31m[Gitleaks] PUSH REJECTED: Potential secrets detected.\033[0m"
18+
echo -e "\033[0;33mPlease remove the secrets from your git history before pushing.\033[0m"
19+
exit 1
20+
fi
21+
22+
echo -e "\033[0;32m[Gitleaks] Scan passed. Proceeding with push.\033[0m"
23+
else
24+
# Only show warning if not in a known repo where gitleaks is already ignored
25+
echo -e "\033[0;33m[Gitleaks] Warning: gitleaks is not installed. Skipping local secret scan.\033[0m"
26+
fi
27+
28+
exit 0

opencode/.config/opencode/opencode.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
"edit": false,
2424
}
2525
},
26-
"professor": {
26+
"mentor": {
2727
"mode": "primary",
2828
"instructions": [
29-
"~/.config/opencode/rules/cs-professor.md"
29+
"~/.config/opencode/rules/cs-mentor.md"
3030
],
3131
"tools": {
3232
"write": false,

opencode/.config/opencode/rules/cs-professor.md renamed to opencode/.config/opencode/rules/cs-mentor.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Role: CS Professor
1+
# Role: CS Mentor
22
You are a distinguished Computer Scientist and Professor with decades of experience in academia and industry. Your knowledge spans the entire stack, from low-level systems (VHDL, kernels, compilers) to high-level architecture (microservices, cloud-native design), cybersecurity, and robotics/mechatronics.
33

44
## Objective: Mentorship
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env bash
22
# Quickly add all changes, commit with an auto-message, and push
3+
34
git add -A
45
git commit -m "[auto] Minor change in the codebase."
56
git push

scripts/.local/bin/scripts/git-repo-init

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env bash
22
# Initialize a new Git repository and create it on GitHub
3+
34
git init -b main && \
45
gh repo create --private --source=. --remote=origin && \
56
git add . && \

scripts/security/scan_secrets.sh

Lines changed: 36 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,57 @@
11
#!/usr/bin/env bash
22

33
# Secret Scanning Script for Dotfiles
4-
# This script searches for common patterns that might indicate secrets or sensitive info.
4+
# This script searches for common patterns that might indicate secrets or sensitive info using git grep.
55

66
# Define the colors
77
RED='\033[0;31m'
88
GREEN='\033[0;32m'
99
YELLOW='\033[1;33m'
1010
NC='\033[0m' # No Color
1111

12-
# Define the patterns to search for
12+
# Define the patterns to search for (using extended regex for git grep)
13+
# Note: we use -E for extended regex in git grep
1314
PATTERNS=(
14-
# AWS Access Key ID
15-
'AKIA[0-9A-Z]{16}'
16-
# AWS Secret Access Key
17-
'[^a-zA-Z0-9/+=][a-zA-Z0-9/+=]{40}[^a-zA-Z0-9/+=]'
18-
# GitHub Personal Access Token
19-
'ghp_[a-zA-Z0-9]{36}'
20-
# GitHub OAuth Token
21-
'gho_[a-zA-Z0-9]{36}'
22-
# Slack Token
23-
'xox[bap]-[a-zA-Z0-9-]{10,}'
24-
# Stripe API Key
25-
'sk_live_[0-9a-zA-Z]{24}'
26-
# Google API Key
27-
'AIza[0-9A-Za-z\\-_]{35}'
28-
# Generic Private Key
29-
'-----BEGIN [A-Z ]*PRIVATE KEY-----'
30-
# Potential passwords/secrets in config files
31-
'(password|passphrase|token|secret|key|api|auth|cred|ident|account|user|private|ssh-)[^=]*[=:][^ \n]{8,}'
15+
'AKIA[0-9A-Z]{16}' # AWS Access Key ID
16+
'ghp_[a-zA-Z0-9]{36}' # GitHub Personal Access Token
17+
'gho_[a-zA-Z0-9]{36}' # GitHub OAuth Token
18+
'xox[bap]-[a-zA-Z0-9-]{10,}' # Slack Token
19+
'sk_live_[0-9a-zA-Z]{24}' # Stripe API Key
20+
'AIza[0-9A-Za-z\-_]{35}' # Google API Key
21+
'-----BEGIN [A-Z ]*PRIVATE KEY-----' # Generic Private Key
22+
'(password|passphrase|token|secret|api|auth|cred|ssh-)[^=]*[=:][^ \/\n]{12,}' # Potential secrets (excluding URLs)
3223
)
3324

34-
# Files to exclude (like this script itself)
35-
EXCLUDE_PATTERNS=(
36-
'scripts/security/scan_secrets.sh'
37-
'*.png'
38-
'*.jpg'
39-
'*.jpeg'
40-
'*.gif'
41-
'*.svg'
42-
'*.ico'
43-
'*.woff'
44-
'*.woff2'
45-
'*.ttf'
46-
'*.otf'
47-
'*.lock'
48-
'*.json'
25+
# Files/Directories to exclude (relative to repo root)
26+
EXCLUDE=(
27+
':(exclude).git'
28+
':(exclude)oh-my-zsh'
29+
':(exclude)node_modules'
30+
':(exclude).cache'
31+
':(exclude)scripts/security/scan_secrets.sh'
32+
':(exclude).ignore_stow/default-cursor'
33+
':(exclude).ignore_stow/default-vscode'
34+
':(exclude)*.png'
35+
':(exclude)*.jpg'
36+
':(exclude)*.jpeg'
37+
':(exclude)*.gif'
38+
':(exclude)*.svg'
39+
':(exclude)*.ico'
40+
':(exclude)*.lock'
41+
':(exclude)*.json'
4942
)
5043

51-
# Directories to exclude
52-
EXCLUDE_DIRS=(
53-
'.git'
54-
'oh-my-zsh'
55-
'node_modules'
56-
'.cache'
57-
)
58-
59-
# Build the exclude arguments for grep
60-
EXCLUDE_ARGS=()
61-
for pattern in "${EXCLUDE_PATTERNS[@]}"; do
62-
EXCLUDE_ARGS+=(--exclude="$pattern")
63-
done
64-
65-
for dir in "${EXCLUDE_DIRS[@]}"; do
66-
EXCLUDE_ARGS+=(--exclude-dir="$dir")
67-
done
68-
69-
echo -e "${YELLOW}Scanning for potential secrets...${NC}"
44+
echo -e "${YELLOW}Scanning tracked files for potential secrets...${NC}"
7045

7146
FOUND_SECRETS=0
7247

7348
for pattern in "${PATTERNS[@]}"; do
74-
# Search for the pattern in all files, excluding some
75-
# Use -E for extended regex
76-
# Use -r for recursive
77-
# Use -n for line numbers
78-
# Use -I to skip binary files
79-
MATCHES=$(grep -rEnI "${EXCLUDE_ARGS[@]}" "$pattern" . 2>/dev/null)
49+
# Use git grep to search only tracked files
50+
# -E: extended regex
51+
# -n: line numbers
52+
# -i: ignore case for some patterns if needed (but here we stay case sensitive for tokens)
53+
# -I: don't match in binary files
54+
MATCHES=$(git grep -EnI "$pattern" -- . "${EXCLUDE[@]}" 2>/dev/null)
8055

8156
if [[ -n "$MATCHES" ]]; then
8257
echo -e "${RED}Found potential secret for pattern: $pattern${NC}"
@@ -89,6 +64,6 @@ if [[ $FOUND_SECRETS -eq 1 ]]; then
8964
echo -e "${RED}ERROR: Potential secrets found! Please review before pushing.${NC}"
9065
exit 1
9166
else
92-
echo -e "${GREEN}No potential secrets found.${NC}"
67+
echo -e "${GREEN}No potential secrets found in tracked files.${NC}"
9368
exit 0
9469
fi

0 commit comments

Comments
 (0)