Security Guidelines for Sentinel CI¶
Overview¶
Sentinel CI handles sensitive CI/CD data including build logs, test results, and potentially credentials. This document outlines security best practices for deploying and using Sentinel CI safely.
๐ Never Commit These Items¶
Credentials & Tokens: - CI/CD API tokens (Jenkins, GitHub, GitLab) - SSH keys - AWS access keys / secret keys - Database passwords - Service account credentials - OAuth tokens - Personal access tokens (PATs)
Configuration Files:
- .env files
- secrets.json
- credentials.yaml
- Any file ending in _token, _key, _secret
Internal Information: - Internal URLs and hostnames - IP addresses - Internal network configurations - Organization-specific data
โ Safe Practices¶
1. Environment Variables¶
Always use environment variables for sensitive data:
# .env file (NEVER commit this)
JENKINS_URL=https://jenkins.example.com
JENKINS_TOKEN=user:api_token_here
GITHUB_TOKEN=ghp_xxxxxxxxxxxx
GITLAB_TOKEN=glpat-xxxxxxxxxxxx
Load in Python:
import os
from dotenv import load_dotenv
load_dotenv()
jenkins_url = os.getenv('JENKINS_URL')
jenkins_token = os.getenv('JENKINS_TOKEN')
2. Configuration Files¶
Use a template approach:
# config.example.yaml (committed)
jenkins:
url: "https://jenkins.example.com"
token: "${JENKINS_TOKEN}" # Reference environment variable
# config.yaml (in .gitignore)
jenkins:
url: "https://jenkins.mycompany.com"
token: "user:actual_token_here"
3. Secret Redaction¶
Sentinel CI includes automatic secret redaction. Verify it's working:
from shared.redaction.redactor import SecretRedactor
redactor = SecretRedactor()
log = "password=secret123 token=abc-def-ghi"
redacted = redactor.redact(log)
print(redacted) # Should show [REDACTED]
Patterns automatically redacted:
- API keys (api_key=..., apikey:...)
- Passwords (password=..., pwd=...)
- Tokens (token=..., bearer ...)
- AWS credentials (AKIA..., aws_secret_access_key)
- Private keys (-----BEGIN PRIVATE KEY-----)
- Email addresses
- Credit card numbers
- SSH keys
- Database URLs with credentials
- Generic secrets (secret=...)
4. Read-Only Operations¶
Sentinel CI is designed for read-only access: - Does not trigger builds - Does not modify configurations - Does not delete data - Only fetches and analyzes existing data
Use read-only tokens when possible:
Jenkins:
GitHub:
GitLab:
๐ Token Management¶
Creating Tokens¶
Jenkins:
1. Go to User โ Configure โ API Token
2. Click "Add new Token"
3. Give it a descriptive name: "sentinel-ci-readonly"
4. Copy token immediately (shown only once)
5. Format: username:token
GitHub:
1. Settings โ Developer settings โ Personal access tokens โ Fine-grained tokens
2. Select repository access
3. Permissions: Actions (read), Contents (read), Metadata (read)
4. Generate token
5. Format: ghp_xxxxxxxxxxxx
GitLab:
1. User Settings โ Access Tokens
2. Name: "sentinel-ci"
3. Scopes: read_api
4. Create token
5. Format: glpat-xxxxxxxxxxxx
Token Rotation¶
Rotate tokens regularly (every 90 days):
# 1. Generate new token in CI platform
# 2. Update environment variable
export JENKINS_TOKEN="user:new_token_here"
# 3. Restart Sentinel CI
# 4. Verify functionality
# 5. Revoke old token
Token Storage¶
Local Development:
Production: - Use secret management: AWS Secrets Manager, HashiCorp Vault, Azure Key Vault - Use environment variables in container orchestration (Kubernetes secrets) - Never hardcode in Dockerfiles or config files
๐ก๏ธ Deployment Security¶
Network Security¶
Restrict access:
Use VPN or private network: - Deploy within corporate VPN - Use private subnets in cloud - Enable firewall rules
Authentication¶
Add authentication layer:
# Example: Add API key authentication
from functools import wraps
from flask import request
def require_api_key(f):
@wraps(f)
def decorated(*args, **kwargs):
api_key = request.headers.get('X-API-Key')
if api_key != os.getenv('SENTINEL_API_KEY'):
return {'error': 'Unauthorized'}, 401
return f(*args, **kwargs)
return decorated
Audit Logging¶
Enable audit logging:
import logging
# Configure audit logger
audit_logger = logging.getLogger('sentinel_ci.audit')
audit_logger.setLevel(logging.INFO)
handler = logging.FileHandler('audit.log')
handler.setFormatter(logging.Formatter(
'%(asctime)s - %(name)s - %(levelname)s - %(message)s'
))
audit_logger.addHandler(handler)
# Log all API calls
def log_api_call(user, action, resource):
audit_logger.info(f"User={user} Action={action} Resource={resource}")
๐จ Incident Response¶
If Credentials Are Exposed¶
Immediate actions:
- Revoke compromised credentials in CI platform
- Generate new credentials
- Update environment variables
- Rotate related secrets (if they share passwords)
- Review audit logs for unauthorized access
- Check git history for exposure:
- Use BFG Repo-Cleaner to remove from history:
If Public Repository Exposed¶
Actions:
- Make repository private immediately
- Rotate all credentials mentioned in commits
- Review all forks (they may have copies)
- Contact GitHub to remove cached versions
- Enable GitHub secret scanning alerts
- Add pre-commit hooks to prevent future exposure
๐ Security Checklist¶
Before deploying to production:
- [ ] All credentials in environment variables
- [ ]
.envfile in.gitignore - [ ] No hardcoded URLs or tokens in code
- [ ] Read-only tokens configured
- [ ] Secret redaction tested and working
- [ ] Audit logging enabled
- [ ] Network access restricted
- [ ] Authentication layer added
- [ ] Token rotation schedule defined
- [ ] Incident response plan documented
- [ ] Security scan completed (
ruff,bandit) - [ ] Dependency vulnerabilities checked (
pip-audit)
๐ ๏ธ Security Tools¶
Scan for secrets:
# GitLeaks
gitleaks detect --source . --verbose
# TruffleHog
trufflehog git file://. --only-verified
Dependency scanning:
Static analysis:
๐ Reporting Security Issues¶
DO NOT open public issues for security vulnerabilities.
Instead: 1. Email security@example.com 2. Include: - Description of vulnerability - Steps to reproduce - Potential impact - Suggested fix (if any) 3. Allow 90 days for response before public disclosure
๐ Additional Resources¶
License¶
This security documentation is provided as-is without warranty. Always consult with your security team before deployment.