This document outlines security best practices for using the DevSecOps Policy Scanner (DSP Scanner) effectively and securely.
- Overview
- Installation Security
- Configuration Security
- Policy Security
- Runtime Security
- Data Security
- Network Security
- Compliance Security
- Incident Response
The DSP Scanner is designed with security as a core principle. This guide helps you implement security best practices when using the scanner in your environment.
- Defense in Depth: Multiple layers of security controls
- Least Privilege: Minimal permissions required for operation
- Zero Trust: Verify everything, trust nothing
- Secure by Default: Secure configurations out of the box
- Continuous Monitoring: Ongoing security assessment
# Use virtual environments
python -m venv dsp-scanner-env
source dsp-scanner-env/bin/activate
# Install from trusted source
pip install --index-url https://pypi.org/simple/ devsecops-policy-scanner
# Verify installation
dsp-scanner --version# Check for vulnerabilities
safety check
# Update dependencies regularly
pip install --upgrade devsecops-policy-scanner
# Use requirements.txt with pinned versions
pip install -r requirements.txt# Use official images
docker pull devsecops-policy-scanner:latest
# Run with minimal privileges
docker run --rm --user 1000:1000 devsecops-policy-scanner:latest
# Scan images before use
trivy image devsecops-policy-scanner:latest# config.yaml
security:
# Enable secure mode
secure_mode: true
# Set resource limits
resource_limits:
cpu: "1.0"
memory: "512Mi"
timeout: 300
# Enable sandboxing
sandbox:
enabled: true
isolation_level: "strict"
# Logging configuration
logging:
level: "INFO"
secure_logging: true
audit_log: true# Use environment variables for sensitive data
export DSP_API_KEY="your-secure-api-key"
export DSP_SECRET_KEY="your-secret-key"
# Use .env files (keep out of version control)
echo "DSP_API_KEY=your-secure-api-key" > .env
echo "DSP_SECRET_KEY=your-secret-key" >> .env# Access control configuration
access_control:
# Role-based access
roles:
admin:
permissions: ["read", "write", "execute", "delete"]
user:
permissions: ["read", "execute"]
viewer:
permissions: ["read"]
# IP restrictions
allowed_ips:
- "192.168.1.0/24"
- "10.0.0.0/8"
# Time-based access
allowed_hours:
start: "09:00"
end: "17:00"# Validate policies before deployment
dsp-scanner validate policies/security.yaml
# Check policy syntax
dsp-scanner lint policies/
# Test policies in sandbox
dsp-scanner test policies/ --sandbox# Example secure policy
package dsp_scanner.kubernetes
# Use explicit deny rules
deny[msg] {
# Check for privileged containers
input.spec.containers[_].securityContext.privileged == true
msg = {
"title": "Privileged Container Detected",
"description": "Containers should not run with privileged access",
"severity": "HIGH",
"platform": "kubernetes",
"recommendation": "Remove privileged flag or use security contexts"
}
}
# Validate input data
deny[msg] {
# Check for required fields
not input.metadata.namespace
msg = {
"title": "Missing Namespace",
"description": "All resources must have a namespace",
"severity": "MEDIUM",
"platform": "kubernetes",
"recommendation": "Add namespace to resource definition"
}
}# Sign policies with GPG
gpg --sign policies/security.yaml
# Verify policy signatures
gpg --verify policies/security.yaml.gpg
# Use signed policies only
dsp-scanner scan --require-signatures# Run with minimal privileges
dsp-scanner scan --user 1000:1000
# Use resource limits
dsp-scanner scan --cpu-limit 1.0 --memory-limit 512Mi
# Enable timeout protection
dsp-scanner scan --timeout 300
# Use secure output
dsp-scanner scan --output-format json --no-sensitive-data# Sandbox configuration
sandbox:
enabled: true
isolation:
network: "restricted"
filesystem: "readonly"
process: "isolated"
resource_limits:
cpu: "1.0"
memory: "512Mi"
disk: "100Mi"
allowed_operations:
- "read"
- "scan"
- "validate"
blocked_operations:
- "write"
- "network"
- "execute"# Security monitoring
monitoring:
# Enable security events
security_events: true
# Log all operations
audit_logging: true
# Monitor resource usage
resource_monitoring: true
# Alert on violations
alerts:
high_severity: true
policy_violations: true
resource_exceeded: true# Data security configuration
data_security:
# Encrypt sensitive data
encryption:
enabled: true
algorithm: "AES-256-GCM"
key_rotation: "30d"
# Data retention
retention:
scan_results: "90d"
logs: "30d"
temp_files: "1d"
# Data classification
classification:
public: ["scan_results"]
internal: ["logs", "configs"]
confidential: ["api_keys", "secrets"]
restricted: ["user_data"]# Use encrypted storage
dsp-scanner config --storage-encryption true
# Secure file permissions
chmod 600 config.yaml
chmod 700 .dsp/
# Use secure mounts
docker run -v /secure/config:/app/config:ro devsecops-policy-scanner# Example data sanitization
import re
def sanitize_output(data):
"""Remove sensitive information from output"""
patterns = [
r'password["\']?\s*[:=]\s*["\']?[^"\s]+["\']?',
r'api_key["\']?\s*[:=]\s*["\']?[^"\s]+["\']?',
r'secret["\']?\s*[:=]\s*["\']?[^"\s]+["\']?'
]
for pattern in patterns:
data = re.sub(pattern, '***REDACTED***', data, flags=re.IGNORECASE)
return data# Network security settings
network_security:
# Use HTTPS for all connections
require_https: true
# Certificate validation
verify_ssl: true
# Allowed endpoints
allowed_endpoints:
- "https://api.github.com"
- "https://registry.npmjs.org"
# Network isolation
network_isolation:
enabled: true
allowed_ports: [443, 80]
blocked_ports: [22, 23, 3389]# Use API keys securely
dsp-scanner config --api-key $DSP_API_KEY
# Rotate API keys regularly
dsp-scanner rotate-keys --force
# Use rate limiting
dsp-scanner scan --rate-limit 100/hour# Configure firewall rules
iptables -A INPUT -p tcp --dport 8080 -s 192.168.1.0/24 -j ACCEPT
iptables -A INPUT -p tcp --dport 8080 -j DROP
# Use network namespaces
ip netns add dsp-scanner
ip netns exec dsp-scanner dsp-scanner scan# Compliance configuration
compliance:
# SOC 2 Type II
soc2:
enabled: true
controls: ["CC6.1", "CC6.2", "CC6.3"]
# ISO 27001
iso27001:
enabled: true
controls: ["A.12.2.1", "A.12.6.1"]
# NIST Cybersecurity Framework
nist:
enabled: true
functions: ["Identify", "Protect", "Detect"]
# GDPR
gdpr:
enabled: true
data_protection: true
right_to_be_forgotten: true# Audit configuration
audit:
# Enable comprehensive auditing
enabled: true
# Audit events
events:
- "policy_execution"
- "configuration_change"
- "access_attempt"
- "data_access"
# Audit storage
storage:
type: "secure_database"
retention: "7y"
encryption: true
# Audit reporting
reporting:
frequency: "monthly"
format: "pdf"
recipients: ["security@company.com"]# Incident response plan
incident_response:
# Incident classification
severity_levels:
critical:
response_time: "1h"
notification: "immediate"
high:
response_time: "4h"
notification: "urgent"
medium:
response_time: "24h"
notification: "normal"
low:
response_time: "72h"
notification: "low"
# Response procedures
procedures:
detection:
- "Automated monitoring"
- "Manual review"
- "User reports"
containment:
- "Isolate affected systems"
- "Disable compromised accounts"
- "Block malicious IPs"
eradication:
- "Remove malware"
- "Patch vulnerabilities"
- "Update configurations"
recovery:
- "Restore from backups"
- "Verify system integrity"
- "Monitor for recurrence"# Monitor for security events
dsp-scanner monitor --security-events
# Set up alerts
dsp-scanner alert --severity high --email security@company.com
# Generate security reports
dsp-scanner report --security --format pdf# Collect evidence
dsp-scanner forensics --collect-all
# Analyze logs
dsp-scanner forensics --analyze-logs
# Generate timeline
dsp-scanner forensics --timeline --output timeline.json- ✅ Use virtual environments for isolation
- ✅ Keep dependencies updated
- ✅ Use signed and validated policies
- ✅ Enable comprehensive logging
- ✅ Implement access controls
- ✅ Use encryption for sensitive data
- ✅ Monitor for security events
- ✅ Regular security assessments
- ✅ Follow least privilege principle
- ✅ Implement defense in depth
- ❌ Run with root privileges
- ❌ Use default configurations
- ❌ Store secrets in plain text
- ❌ Ignore security warnings
- ❌ Skip policy validation
- ❌ Disable logging
- ❌ Use weak authentication
- ❌ Share sensitive data
- ❌ Ignore compliance requirements
- ❌ Skip regular updates
- Use secure installation methods
- Verify package integrity
- Use virtual environments
- Update dependencies regularly
- Use secure configuration files
- Implement access controls
- Enable encryption
- Configure logging properly
- Use minimal privileges
- Enable sandboxing
- Set resource limits
- Monitor execution
- Encrypt sensitive data
- Implement data retention
- Sanitize outputs
- Secure storage
- Use HTTPS connections
- Configure firewalls
- Implement rate limiting
- Monitor network traffic
- Follow compliance frameworks
- Maintain audit trails
- Regular assessments
- Document procedures