This document explains how to set up pre-commit hooks to prevent credential exposure and maintain security standards in the LRArchiveRetention project.
The pre-commit security system includes:
- General credential scanner - Detects hardcoded passwords, API keys, and secrets
- PowerShell-specific scanner - Identifies PowerShell credential anti-patterns
- Documentation scanner - Prevents credential exposure in markdown files
- detect-secrets integration - Industry-standard secret detection
- Python 3.8 or later
- Git repository
- macOS (for keychain integration)
# Install pre-commit
pip install pre-commit
# Install detect-secrets for advanced secret detection
pip install detect-secrets# Navigate to project root
cd /path/to/LRArchiveRetention
# Install the git hook scripts
pre-commit install
# Install commit-msg hook (optional, for commit message validation)
pre-commit install --hook-type commit-msg# Generate initial secrets baseline (excludes known safe patterns)
detect-secrets scan --baseline .secrets.baseline
# Review and update baseline if needed
detect-secrets audit .secrets.baseline# Run pre-commit on all files to test
pre-commit run --all-files
# Test with a specific file
pre-commit run --files path/to/test-file.ps1- Hardcoded passwords in various formats
- Windows/Active Directory credential patterns
- Connection strings with embedded passwords
- API keys and access tokens
- SSH/RSA private keys
- URLs with embedded credentials
- Environment variables with secrets
New-Object PSCredentialwith hardcoded passwordsConvertTo-SecureString -AsPlainText -Forceusage- Direct
-Passwordparameter usage - Insecure credential storage patterns
- WinRM/PSSession credential embedding
- Registry credential storage
- Credential examples that might be real
- Connection strings in documentation
- API keys in code examples
- SSH keys in markdown
- Command-line examples with passwords
- Forbidden credential strings
- Entropy-based detection
- Keyword-based detection
- Regular expression patterns
- Base64 encoded secrets
- Custom plugin support
The pre-commit configuration excludes:
.git/directoriesnode_modules/directories.venv/virtual environments.secrets.baselinefile itself- Test expected output files
- Lock files
Edit .pre-commit-config.yaml to:
- Add new file patterns
- Exclude additional directories
- Modify security check parameters
- Add new security hooks
If legitimate code triggers false positives:
-
For detect-secrets:
# Add to baseline after verification it's safe detect-secrets scan --baseline .secrets.baseline --update -
For custom scanners:
- Update the acceptable patterns in the respective script
- Add
# noseccomments for specific lines (if implemented)
If you get permission errors:
chmod +x scripts/*.shIf pre-commit fails:
# Reinstall pre-commit environment
pre-commit clean
pre-commit install-
Use macOS Keychain:
security add-internet-password -s "server.domain.com" -a "username" -w
-
Reference keychain in scripts:
PASSWORD=$(security find-internet-password -s "server" -a "user" -w) -
PowerShell credential patterns:
# Good: Use Save-Credential.ps1 with -UseStdin echo "password" | .\Save-Credential.ps1 -Target "NAS" -UseStdin # Bad: Hardcoded credentials $credential = New-Object PSCredential("user", "password")
- Use placeholder values:
YOUR_PASSWORD,<PASSWORD> - Reference keychain retrieval methods
- Include security warnings
- Use example domains:
example.com
- Always run
pre-commit run --all-filesbefore major commits - Update
.secrets.baselinewhen adding legitimate patterns - Review security violations carefully before bypassing
- Rotate any accidentally committed credentials
# Full repository scan
pre-commit run --all-files
# Specific file type scan
find . -name "*.ps1" -exec scripts/check-powershell-secrets.sh {} \;
# Update secrets baseline
detect-secrets scan --baseline .secrets.baseline --update- Review exposed credentials monthly
- Rotate service account passwords quarterly
- Update keychain entries as needed
- Audit baseline file for new patterns
If you encounter issues:
- Check the specific script output for detailed error messages
- Verify file permissions on scripts
- Ensure all dependencies are installed
- Review the
.pre-commit-config.yamlconfiguration
For PowerShell-specific issues, refer to the secure credential patterns documented in the main project README.