Quick Start
The
scan-secrets command exits with code 2 when secrets are detected, making it easy to use in CI/CD pipelines to prevent accidental credential commits.What Secrets Are Detected
Vectra Guard detects secrets using two complementary approaches:Known Pattern Detection
These patterns are always reported when found:| Pattern ID | Description | Severity | Example |
|---|---|---|---|
AWS_ACCESS_KEY_ID | AWS access key identifier | Critical | AKIA0123456789ABCDEF |
AWS_SECRET_ACCESS_KEY | AWS secret access key | Critical | aws_secret_access_key = "abcd..." |
GENERIC_API_KEY | Generic API keys and tokens | Critical | api_key = "sk_live_1234..." |
PRIVATE_KEY_BLOCK | SSH/RSA/DSA private keys | Critical | -----BEGIN PRIVATE KEY----- |
Entropy-Based Detection
High-entropy strings (20+ characters, Shannon entropy ≥ 3.5) are flagged asENTROPY_CANDIDATE only when:
- Context is present: The line contains secret-related keywords like
token,api_key,secret,password,credential, orauth - Assignment pattern: The line includes
=or:suggesting configuration or assignment
False Positive Filters
False Positive Filters
To reduce noise, the scanner automatically skips:
- UUIDs: Standard UUID format (e.g.,
550e8400-e29b-41d4-a716-446655440000) - Path-like strings: Contains
/(e.g.,github.com/org/repo) - Documentation slugs: Numbered slugs (e.g.,
1-getting-started) - URL fragments: Contains
com/,org/,http,github. - Code identifiers: CamelCase or snake_case with no digits
- Lockfiles:
package-lock.json,yarn.lock,poetry.lock,go.sum, etc.
Command Reference
Basic Usage
Options
| Flag | Description | Default |
|---|---|---|
--path | Directory or file to scan | . (current directory) |
--allowlist | Path to allowlist file | None |
Exit Codes
- 0: No secrets detected
- 2: Secrets detected (use in CI to fail builds)
Allowlist Configuration
Create a.secrets-allowlist.txt file to exclude known test keys or false positives:
Allowlist entries are matched exactly (after trimming whitespace). Lines starting with
# are treated as comments.Output Format
When secrets are detected, findings are logged with full context:| Field | Description |
|---|---|
file | File path:line_number where secret was found |
line | Line number |
pattern | Detection pattern ID |
match | Matched secret value (truncated in logs) |
entropy | Shannon entropy score |
severity | critical, high, or medium |
CI/CD Integration
GitHub Actions
GitLab CI
Pre-commit Hook
Add to.git/hooks/pre-commit:
Best Practices
1. Scan Before Commit
Run secret scanning as part of your development workflow:2. Use Environment Variables
Never hardcode secrets. Use environment variables instead:3. Rotate Exposed Credentials
If secrets are committed:- Rotate immediately: Treat exposed credentials as compromised
- Don’t just delete: Secrets remain in Git history
- Use tools like BFG or git-filter-repo: To remove from history
- Force push carefully: Coordinate with team
4. Maintain Allowlists
Keep allowlists minimal and documented:5. Skip Generated Files
The scanner automatically skips common generated files and directories:.git/,node_modules/,vendor/,.venv/,dist/,build/- Lockfiles:
package-lock.json,yarn.lock,poetry.lock,go.sum - Binary files:
.png,.jpg,.pdf,.zip,.exe
Examples
Example 1: Clean Repository
Example 2: Detected Secrets
Example 3: With Allowlist
Troubleshooting
False Positives
Problem: Legitimate code is flagged as a secret. Solution: Add to allowlist or verify it’s not actually a secret:Missed Secrets
Problem: Known secret not detected. Possible causes:- Secret is in a skipped directory (
.git/,node_modules/, etc.) - Secret is in a binary or lockfile
- Entropy is below threshold (< 3.5) and no known pattern matches
Performance on Large Repos
Problem: Scanning takes too long. Solution: The scanner automatically skips vendor directories and binary files. For very large repos:Related Commands
vg scan-security: Scan for risky code patterns (command injection, unsafe functions, etc.)vg audit repo: Comprehensive repository audit (secrets + security + package vulnerabilities)vg cve scan: Scan dependencies for known vulnerabilities
Implementation Details
Scanner Architecture
Scanner Architecture
The secret scanner (
Core logic:
internal/secrets/scanner.go) uses:- Regex-based pattern matching: Known secret formats (AWS keys, private keys, etc.)
- Shannon entropy calculation: Measures randomness of strings
- Context detection: Looks for assignment patterns and secret-related keywords
- False positive filtering: Removes UUIDs, paths, slugs, and code identifiers
- Binary file detection: Skips non-UTF-8 files with NUL bytes
- Smart file skipping: Ignores vendor dirs, lockfiles, and common build artifacts
/home/daytona/workspace/source/cmd/scan_secrets.go:14Core logic:
/home/daytona/workspace/source/internal/secrets/scanner.go:80Security Considerations
Defense in Depth:- Use secret scanning as one layer of security
- Combine with secret management tools (Vault, AWS Secrets Manager, etc.)
- Implement least-privilege access controls
- Rotate credentials regularly
- Monitor for unauthorized API usage