claw-code/.guardrails/.github/workflows/secret-validation.yml

127 lines
3.7 KiB
YAML

name: Secret Validation
on:
push:
branches: [main, develop]
pull_request:
branches: [main, develop]
permissions:
contents: read
jobs:
scan-for-secrets:
name: Scan for Leaked Secrets
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Full history for scanning
- name: Run Gitleaks
uses: gitleaks/gitleaks-action@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITLEAKS_LICENSE: ${{ secrets.GITLEAKS_LICENSE }}
check-env-files:
name: Check for .env Files
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Check for .env files
run: |
echo "Checking for accidentally committed .env files..."
# Find .env files (excluding .env.example)
ENV_FILES=$(find . -name ".env*" ! -name ".env.example" ! -name ".env.template" -type f 2>/dev/null || true)
if [ -n "$ENV_FILES" ]; then
echo "ERROR: Found .env files that should not be committed:"
echo "$ENV_FILES"
echo ""
echo "Please remove these files and add them to .gitignore"
exit 1
else
echo "No .env files found (good!)"
fi
- name: Check for credential files
run: |
echo "Checking for credential files..."
# List of patterns that might contain secrets
PATTERNS=(
"*.pem"
"*.key"
"*credentials*.json"
"*secrets*.json"
"*service-account*.json"
)
FOUND_FILES=""
for pattern in "${PATTERNS[@]}"; do
FILES=$(find . -name "$pattern" -type f 2>/dev/null || true)
if [ -n "$FILES" ]; then
FOUND_FILES="$FOUND_FILES$FILES"$'\n'
fi
done
if [ -n "$FOUND_FILES" ]; then
echo "WARNING: Found potential credential files:"
echo "$FOUND_FILES"
echo ""
echo "Verify these don't contain real credentials"
# Warning only, not failing (might be examples)
else
echo "No credential files found (good!)"
fi
check-hardcoded-secrets:
name: Check for Hardcoded Secrets
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Check for common secret patterns
run: |
echo "Checking for hardcoded secrets..."
# Patterns that might indicate hardcoded secrets
PATTERNS=(
"password\s*=\s*['\"]"
"api_key\s*=\s*['\"]"
"secret\s*=\s*['\"]"
"token\s*=\s*['\"]"
"aws_access_key_id\s*=\s*['\"]"
"private_key\s*=\s*['\"]"
)
ISSUES_FOUND=0
for pattern in "${PATTERNS[@]}"; do
# Search in common code files, excluding test fixtures
MATCHES=$(grep -riE "$pattern" --include="*.py" --include="*.js" --include="*.ts" --include="*.yaml" --include="*.yml" --include="*.json" . 2>/dev/null | grep -v "node_modules" | grep -v ".example" | grep -v "test_fixtures" || true)
if [ -n "$MATCHES" ]; then
echo "WARNING: Potential hardcoded secret pattern found:"
echo "$MATCHES"
echo ""
ISSUES_FOUND=$((ISSUES_FOUND + 1))
fi
done
if [ $ISSUES_FOUND -gt 0 ]; then
echo "Found $ISSUES_FOUND potential issues. Please review."
echo "If these are false positives (e.g., environment variable references), they can be ignored."
else
echo "No obvious hardcoded secrets found (good!)"
fi