Skip to content

Commit 35c841e

Browse files
codegen-sh[bot]Jay Hack
andauthored
Add Trufflehog secret scanning documentation (#1254)
Co-authored-by: codegen-sh[bot] <131295404+codegen-sh[bot]@users.noreply.github.com> Co-authored-by: Jay Hack <[email protected]>
1 parent 09ad131 commit 35c841e

File tree

2 files changed

+170
-1
lines changed

2 files changed

+170
-1
lines changed

docs/docs.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@
4444
"settings/claude-code",
4545
"settings/agent-behavior",
4646
"settings/agent-permissions",
47-
"settings/team-roles"
47+
"settings/team-roles",
48+
"settings/trufflehog-integration"
4849
]
4950
},
5051
{
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
---
2+
title: "Trufflehog Secret Scanning"
3+
sidebarTitle: "Trufflehog Integration"
4+
icon: "shield-check"
5+
---
6+
7+
Codegen integrates [Trufflehog](https://github.com/trufflesecurity/trufflehog), an open-source secret scanning tool, to automatically detect and prevent sensitive information from being committed to your repositories. This security layer protects against accidental exposure of API keys, passwords, tokens, and other secrets.
8+
9+
<Card
10+
title="Configure Repository Settings"
11+
icon="gear"
12+
href="https://codegen.com/repos"
13+
>
14+
Manage Trufflehog scanning and other security settings for your repositories.
15+
</Card>
16+
17+
## How It Works
18+
19+
Trufflehog scanning operates at two key points in the development workflow:
20+
21+
### Pre-Push Hook Scanning
22+
23+
When you push code to a repository, Trufflehog automatically scans all modified and added files for potential secrets before the push completes.
24+
25+
**The scanning process:**
26+
27+
1. **File Detection** - Identifies all files that have been added, modified, or changed in the push
28+
2. **Pattern Filtering** - Applies `.trufflehogignore` patterns to exclude files that shouldn't be scanned
29+
3. **Secret Scanning** - Runs Trufflehog with comprehensive detection rules for verified, unknown, and unverified secrets
30+
4. **Push Control** - Blocks the push if potential secrets are detected, allowing you to review and remediate
31+
32+
### Agent Commit Scanning
33+
34+
When Codegen agents create commits using the signed commit feature, Trufflehog scans all files before the commit is created.
35+
36+
**Agent scanning includes:**
37+
38+
- **Automatic Detection** - Scans all files being committed without manual intervention
39+
- **Configurable Bypass** - Agents can skip scanning for confirmed false positives using the `skip_trufflehog` parameter
40+
- **Error Reporting** - Provides detailed feedback about detected secrets with remediation guidance
41+
42+
## Configuration
43+
44+
### Ignore Patterns
45+
46+
Create a `.trufflehogignore` file in your repository root to exclude files from scanning:
47+
48+
```gitignore
49+
# Documentation and configuration files
50+
*.md
51+
*.txt
52+
docs/
53+
README*
54+
55+
# Test fixtures and mock data
56+
test/fixtures/
57+
**/mocks/
58+
*.test.js
59+
60+
# Build artifacts
61+
dist/
62+
build/
63+
node_modules/
64+
```
65+
66+
The ignore file supports:
67+
68+
- **Glob patterns** for matching file paths
69+
- **Regular expressions** for complex matching rules
70+
- **Comments** using `#` for documentation
71+
- **Directory exclusions** with trailing slashes
72+
73+
### Scanning Scope
74+
75+
Trufflehog scans for multiple types of secrets:
76+
77+
- **API Keys** - AWS, Google Cloud, Azure, and hundreds of other services
78+
- **Database Credentials** - Connection strings, passwords, and authentication tokens
79+
- **Private Keys** - SSH keys, SSL certificates, and cryptographic material
80+
- **Authentication Tokens** - JWT tokens, OAuth secrets, and session identifiers
81+
82+
## Working with Detections
83+
84+
### When Trufflehog Blocks a Push
85+
86+
If Trufflehog detects potential secrets during a push, you'll see output similar to:
87+
88+
```bash
89+
❌ Trufflehog found potential secrets or issues. Aborting push.
90+
```
91+
92+
**To resolve:**
93+
94+
1. **Review the detected secrets** - Examine the flagged content carefully
95+
2. **Remove actual secrets** - Replace real credentials with environment variables or configuration
96+
3. **Update ignore patterns** - Add false positives to `.trufflehogignore` if appropriate
97+
4. **Bypass if necessary** - Use `git push --no-verify` only for confirmed false positives
98+
99+
### Agent Commit Handling
100+
101+
When agents encounter Trufflehog detections, they receive detailed error messages:
102+
103+
```
104+
🔒 TruffleHog security scan failed - potential secrets detected:
105+
[Detection details]
106+
107+
Please review and remove any secrets before committing.
108+
To skip this check (not recommended), set skip_trufflehog=true
109+
```
110+
111+
Agents can bypass scanning using the `skip_trufflehog=true` parameter, but this should only be used for confirmed false positives.
112+
113+
## Best Practices
114+
115+
### Repository Setup
116+
117+
- **Add `.trufflehogignore` early** - Configure ignore patterns when setting up repositories
118+
- **Document exceptions** - Comment ignore patterns to explain why files are excluded
119+
- **Regular reviews** - Periodically audit ignore patterns to ensure they're still appropriate
120+
121+
### Secret Management
122+
123+
- **Use environment variables** - Store secrets in environment variables or secure configuration systems
124+
- **Implement secret rotation** - Regularly rotate API keys and credentials
125+
- **Monitor for exposure** - Set up alerts for any secrets that might be accidentally committed
126+
127+
### Team Workflow
128+
129+
- **Educate developers** - Ensure team members understand how Trufflehog works and why it's important
130+
- **Handle false positives** - Establish clear processes for dealing with false positive detections
131+
- **Emergency procedures** - Have plans for handling actual secret exposures if they occur
132+
133+
<Warning>
134+
Never use `--no-verify` or `skip_trufflehog=true` to bypass real secret
135+
detections. These options should only be used for confirmed false positives
136+
after careful review.
137+
</Warning>
138+
139+
## Troubleshooting
140+
141+
### Common Issues
142+
143+
**High false positive rate:**
144+
- Review and update `.trufflehogignore` patterns
145+
- Consider excluding test files, documentation, or configuration templates
146+
147+
**Scanning performance:**
148+
- Large repositories may experience slower push times
149+
- Consider excluding build artifacts and generated files
150+
151+
**Agent commit failures:**
152+
- Review the specific detection details in error messages
153+
- Update code to use proper secret management practices
154+
- Use `skip_trufflehog=true` only for confirmed false positives
155+
156+
### Getting Help
157+
158+
If you encounter persistent issues with Trufflehog scanning:
159+
160+
1. **Check ignore patterns** - Verify `.trufflehogignore` syntax and coverage
161+
2. **Review detection details** - Examine the specific content flagged by Trufflehog
162+
3. **Contact support** - Reach out to Codegen support for assistance with configuration
163+
164+
<Note>
165+
Trufflehog integration helps maintain security best practices by preventing
166+
accidental secret exposure, but it should be part of a comprehensive security
167+
strategy that includes proper secret management and regular security reviews.
168+
</Note>

0 commit comments

Comments
 (0)