Security Gates Configuration
Overview
GhostKit implements a multi-layered security gate system to prevent vulnerabilities and enforce code quality. This document details the configuration and customization of these security gates.
Pre-Commit Hooks
Installation
Pre-commit hooks are installed automatically when running the setup script:
Alternatively, you can install them manually:
Default Configuration
The default pre-commit hook runs the following checks:
- Import Sorting (isort)
- Profile: black-compatible
-
Ensures consistent import organization
-
Code Formatting (black)
- Line length: 88
- Python version: 3.8+
-
Ensures consistent code style
-
Syntax Checking (flake8)
- Critical errors: E9, F63, F7, F82
-
Ensures code is free of basic syntax errors
-
Security Scanning (bandit)
- Severity level: high
- Exclusions: tests, docs
-
Scans for security vulnerabilities
-
Merge Conflict Detection
- Prevents committing files with merge conflict markers
Customizing Security Gates
Modifying the Pre-Commit Hook
Edit .git/hooks/pre-commit to adjust security checks:
Creating a Custom Configuration
For team-wide configuration, create a .pre-commit-config.yaml file:
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- id: check-merge-conflict
- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: black
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
args: ["--profile", "black"]
- repo: https://github.com/pycqa/flake8
rev: 6.0.0
hooks:
- id: flake8
args: ["--select=E9,F63,F7,F82"]
- repo: https://github.com/PyCQA/bandit
rev: 1.7.5
hooks:
- id: bandit
args: ["-r", ".", "-x", "tests,docs", "--severity-level", "high"]
Continuous Integration Security Gates
GitHub Actions Workflow
GhostKit's CI pipeline enforces security gates for all pull requests and commits to protected branches.
Default Configuration
# .github/workflows/ci.yml
name: Security Checks
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]
jobs:
security:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
pip install bandit safety
- name: Run security scans
run: |
bandit -r . -x tests,docs --severity-level medium
pip install safety==1.10.3
safety check --file .safety-ignore || true
Customizing CI Security Gates
Adjusting Severity Levels
Modify the --severity-level parameter in .github/workflows/ci.yml:
Adding Custom Security Checks
Extend the security job with additional steps:
Security Gate Bypass
In exceptional circumstances, security gates can be bypassed:
Temporary Bypass
# Skip pre-commit hooks (USE WITH CAUTION)
git commit --no-verify -m "[SECURITY] Critical emergency fix"
Documented Exceptions
For known issues that cannot be immediately fixed:
-
Add to
.safety-ignorefor dependency vulnerabilities: -
Add
# noseccomment for bandit false positives:
Advanced Security Gate Configuration
Custom Rules
Create custom security rules in scripts/security/custom_rules.py:
def check_custom_security_rule(file_content):
# Example: Check for hardcoded credentials
if "password" in file_content.lower() and "=" in file_content:
return False
return True
Semgrep Rules
Use semgrep for advanced pattern matching:
-
Install semgrep:
-
Create custom rules in
.semgrep/rules/: -
Add to pre-commit hook:
Reporting Security Gate Issues
If you believe a security gate is generating false positives or requires adjustment:
- Open an issue with the label
security-gate - Include detailed information:
- Specific gate failing
- Code snippet causing the issue
- Proposed solution
- Justification for changes
Best Practices
- Never Disable Gates: Modify configurations rather than disabling gates
- Document Exceptions: Always document and justify security gate exceptions
- Regular Updates: Keep security tools updated to latest versions
- Monitor Bypasses: Track and review all security gate bypasses
- Test Changes: Validate security gate changes before deployment