Your team committed 29 million new hardcoded secrets to public repositories in 2025—a 34% increase from the previous year. AI services contributed to 81% more leaks year over year, and internal repositories were 6x more likely to leak secrets than public ones.
You need a secrets policy that prevents credentials from reaching your repositories. Here's a template you can deploy this week.
What This Template Does
This policy establishes automated pre-commit controls for secrets detection, with specific requirements for AI service credentials, internal repository scanning, and non-code environments like Slack and Confluence. It's designed to catch secrets before they spread.
The template addresses three critical gaps:
- AI service credentials (OpenAI keys, Anthropic tokens, Model Context Protocol configurations)
- Internal repository scanning (where 6x more leaks occur)
- Non-code collaboration tools that traditional scanners miss
Prerequisites
Before implementing this policy, ensure you have:
Technical infrastructure:
- Git hooks capability on developer workstations (Git 2.9 or later)
- CI/CD pipeline with policy enforcement gates
- Secrets scanning tool (options: detect-secrets, Gitleaks, TruffleHog)
- Centralized secrets management system (HashiCorp Vault, AWS Secrets Manager, or equivalent)
Organizational readiness:
- Developer workstation management policy (to deploy hooks)
- Incident response process for detected secrets
- Secrets rotation procedures
- Executive sponsor for enforcement decisions
Compliance mapping:
- PCI DSS v4.0.1 Requirement 8.3.2 (cryptographic key management)
- SOC 2 Type II CC6.1 (logical access controls)
- ISO 27001 Control 8.3 (information access restriction)
The Policy Template
# Secrets Management and Detection Policy
Version: 1.0
Effective Date: [INSERT DATE]
Owner: [CISO/Security Engineering Lead]
## 1. Scope
This policy applies to:
- All source code repositories (public and internal)
- Infrastructure-as-code configurations
- CI/CD pipeline definitions
- Documentation repositories
- AI service integrations and prompt libraries
- Collaboration tool content (Slack, Confluence, Notion)
## 2. Prohibited Credential Storage
The following MUST NOT be committed to any repository:
### 2.1 Traditional Credentials
- API keys and tokens
- Database connection strings with embedded passwords
- Private keys (SSH, TLS, GPG)
- OAuth client secrets
- Service account credentials
- Encryption keys
### 2.2 AI Service Credentials (High Priority)
- OpenAI API keys (sk-*, org-*)
- Anthropic API keys
- Google AI/Vertex credentials
- Azure OpenAI keys
- Model Context Protocol (MCP) server configurations with embedded tokens
- LLM infrastructure credentials (vector DB, embedding services)
### 2.3 Internal System Credentials
- LDAP/Active Directory service accounts
- Internal API authentication tokens
- VPN credentials
- Monitoring system API keys
- Internal tool passwords
## 3. Pre-Commit Controls (REQUIRED)
### 3.1 Developer Workstation Requirements
All developers MUST have pre-commit hooks installed that:
- Scan for secrets patterns before allowing commits
- Block commits containing detected secrets
- Log detection events to central security logging
Installation verification: Security team validates hook installation quarterly.
### 3.2 Scanning Configuration
Pre-commit scanners MUST detect:
- High-entropy strings (entropy > 4.5)
- Pattern matches for known credential formats
- AI service key patterns: `(sk-[a-zA-Z0-9]{48}|api[_-]?key.*['\"][a-zA-Z0-9]{32,})`
- MCP configuration files with inline credentials
- Cloud provider credential patterns (AWS, Azure, GCP)
### 3.3 Bypass Procedures
Developers MAY bypass pre-commit hooks only when:
- Committing test fixtures with fake credentials (marked with `# FAKE_CREDENTIAL`)
- Committing public key material (must be reviewed)
- Emergency production fixes (requires post-commit review within 4 hours)
All bypasses MUST be logged and reviewed weekly by the security team.
## 4. CI/CD Pipeline Gates (REQUIRED)
### 4.1 Build-Time Scanning
Every pipeline MUST include secrets scanning that:
- Runs before deployment to any environment
- Fails the build on detection (no warnings-only mode)
- Scans commit history for the current branch (last 10 commits minimum)
- Checks for secrets in environment variable definitions
### 4.2 Internal Repository Priority
Internal repositories require:
- Daily full-history scans (not just new commits)
- Scanning of non-code files (markdown, YAML, JSON)
- Alert routing to repository owner + security team
Rationale: Internal repos show 6x higher leak rates than public repos.
## 5. Non-Code Environment Controls
### 5.1 Collaboration Tools
Security team MUST implement:
- Automated scanning of Slack channels (public and private) for credential patterns
- Confluence/wiki page scanning for embedded secrets
- Jira ticket scanning for credentials in descriptions/comments
- Automated deletion or masking of detected credentials within 1 hour
### 5.2 AI Coding Assistants
Developers using AI coding assistants (GitHub Copilot, Cursor, etc.) MUST:
- Disable credential sharing in assistant settings
- Review all AI-generated code for embedded secrets before committing
- Use credential placeholders in prompts (e.g., `YOUR_API_KEY_HERE`)
## 6. Detection Response
### 6.1 Immediate Actions (Within 1 Hour)
When secrets are detected:
1. Revoke the exposed credential immediately
2. Generate new credential
3. Update all systems using the credential
4. Remove secret from repository history (BFG Repo-Cleaner or git-filter-repo)
5. Notify security team
### 6.2 Investigation Requirements
For each incident, document:
- How the secret was committed (direct commit, merge, AI-generated)
- Duration of exposure
- Systems accessed by the credential
- Evidence of unauthorized access
- Root cause (training gap, tool misconfiguration, etc.)
### 6.3 Repeat Violations
Developers with 3+ violations in 90 days:
- Mandatory secrets management training
- Manager notification
- Potential workstation access restriction pending training completion
## 7. Approved Alternatives
Instead of committing secrets, use:
### 7.1 Local Development
- Environment variables loaded from `.env` files (add `.env` to `.gitignore`)
- Local secrets management tools (direnv, dotenv)
- Developer-specific configuration files (not committed)
### 7.2 CI/CD Environments
- Pipeline secrets management (GitHub Secrets, GitLab CI/CD variables)
- Cloud provider secrets managers (AWS Secrets Manager, Azure Key Vault)
- HashiCorp Vault with dynamic credentials
### 7.3 Production
- Centralized secrets management system (REQUIRED)
- Secrets rotation every 90 days (minimum)
- Audit logging of all secrets access
## 8. Compliance Mapping
This policy satisfies:
- [PCI DSS](https://www.pcisecuritystandards.org/) v4.0.1 Requirement 8.3.2: Secure cryptographic key management
- [SOC 2](https://www.aicpa-cima.com/topic/audit-assurance/audit-and-assurance-greater-than-soc-2) Type II CC6.1: Logical and physical access controls
- [ISO 27001](https://www.iso.org/standard/27001) Control 8.3: Information access restriction
## 9. Policy Exceptions
Exceptions require:
- Written justification from requesting team
- Compensating controls documentation
- CISO approval
- Annual renewal
## 10. Review Schedule
This policy is reviewed:
- Annually (minimum)
- After any secrets exposure incident affecting production
- When new AI services are adopted
- When compliance requirements change
How to Customize It
For your organization size:
- Under 100 developers: Remove quarterly hook verification; do annual reviews instead
- Over 1000 developers: Add automated hook deployment via MDM/configuration management
- Distributed teams: Add VPN-based repository access requirements
For your tech stack:
- Add your specific cloud provider patterns (Oracle Cloud, IBM Cloud, etc.)
- Include proprietary internal service credential patterns
- Add your CI/CD platform's specific secrets syntax
For your risk tolerance:
- Higher risk tolerance: Allow 5 violations before mandatory training (instead of 3)
- Lower risk tolerance: Require security team approval for ALL pre-commit hook bypasses
- Regulated industries: Add specific compliance section numbers for your frameworks (HIPAA, GDPR, etc.)
For AI adoption stage:
- Early AI adoption: Focus Section 2.2 on your current AI vendors only
- Heavy AI usage: Add scanning for prompt injection attempts and PII in prompts
- MCP implementations: Add specific MCP server configuration scanning rules
Validation Steps
Week 1: Technical validation
- Install pre-commit hooks on 5 test developer workstations
- Attempt to commit a test secret (use a fake API key:
sk-test1234567890abcdefghijklmnopqrstuvwxyz123456) - Verify the commit is blocked
- Check that the detection event appears in your security logging system
- Test the bypass procedure with a fake credential marked
# FAKE_CREDENTIAL
Week 2: Pipeline validation
- Add secrets scanning to one non-production pipeline
- Introduce a test secret in a feature branch
- Verify the build fails
- Confirm security team receives the alert
- Test the incident response workflow (revocation, rotation, history cleanup)
Week 3: Internal repository validation
- Run full-history scan on 3 internal repositories
- Document all findings (expect to find secrets—internal repos leak 6x more)
- Follow the response procedure for each finding
- Measure time-to-revocation (target: under 1 hour)
Week 4: Non-code environment validation
- Post a test credential in a Slack channel
- Verify automated detection and masking
- Test Confluence scanning on 5 high-traffic pages
- Review AI coding assistant settings across your team
Month 2: Policy enforcement
- Deploy pre-commit hooks to all developer workstations
- Enable pipeline gates in production CI/CD
- Begin weekly bypass log reviews
- Start tracking repeat violations
Quarterly review metrics:
- Secrets detected pre-commit vs. in CI/CD (goal: 90%+ caught pre-commit)
- Time-to-revocation (goal: under 1 hour)
- Repeat violation rate (goal: under 5% of developers)
- Internal repository scan coverage (goal: 100%)
- AI service credential leaks (track trend—should decrease)
If your time-to-revocation exceeds 4 hours, your incident response process needs work before you can effectively enforce this policy. Fix that first.



