|
| 1 | +name: Python Security Auditing |
| 2 | +description: Run bandit and pip-audit security scans on Python code and report findings |
| 3 | +author: Development Seed |
| 4 | + |
| 5 | +inputs: |
| 6 | + tools: |
| 7 | + description: Comma-separated tools to run (bandit, pip-audit) |
| 8 | + default: bandit,pip-audit |
| 9 | + bandit_scan_dirs: |
| 10 | + description: Comma-separated directories for bandit to scan |
| 11 | + default: . |
| 12 | + bandit_severity_threshold: |
| 13 | + description: Minimum bandit severity that blocks the job (HIGH, MEDIUM, LOW) |
| 14 | + default: HIGH |
| 15 | + pip_audit_block_on: |
| 16 | + description: When to block on pip-audit findings — fixable, all, or none |
| 17 | + default: fixable |
| 18 | + package_manager: |
| 19 | + description: How to resolve dependencies for pip-audit (uv, pip, poetry, pipenv, requirements) |
| 20 | + default: requirements |
| 21 | + requirements_file: |
| 22 | + description: Path to requirements file when package_manager=requirements |
| 23 | + default: requirements.txt |
| 24 | + post_pr_comment: |
| 25 | + description: Post or update a PR comment with the scan results |
| 26 | + default: 'true' |
| 27 | + github_token: |
| 28 | + description: GitHub token used for posting PR comments |
| 29 | + default: ${{ github.token }} |
| 30 | + working_directory: |
| 31 | + description: Directory to run the audit from (useful when the project is in a subdirectory) |
| 32 | + default: '.' |
| 33 | + |
| 34 | +runs: |
| 35 | + using: composite |
| 36 | + steps: |
| 37 | + - name: Set up Python |
| 38 | + uses: actions/setup-python@8d9ed9ac5c53483de85588cdf95a591a75ab9f55 # v5.5.0 |
| 39 | + with: |
| 40 | + python-version: '3.13' |
| 41 | + |
| 42 | + - name: Install python-security-auditing |
| 43 | + shell: bash |
| 44 | + run: pip install "${{ github.action_path }}" |
| 45 | + |
| 46 | + - name: Run security audit |
| 47 | + id: audit |
| 48 | + shell: bash |
| 49 | + continue-on-error: true |
| 50 | + working-directory: ${{ inputs.working_directory }} |
| 51 | + env: |
| 52 | + TOOLS: ${{ inputs.tools }} |
| 53 | + BANDIT_SCAN_DIRS: ${{ inputs.bandit_scan_dirs }} |
| 54 | + BANDIT_SEVERITY_THRESHOLD: ${{ inputs.bandit_severity_threshold }} |
| 55 | + PIP_AUDIT_BLOCK_ON: ${{ inputs.pip_audit_block_on }} |
| 56 | + PACKAGE_MANAGER: ${{ inputs.package_manager }} |
| 57 | + REQUIREMENTS_FILE: ${{ inputs.requirements_file }} |
| 58 | + POST_PR_COMMENT: ${{ inputs.post_pr_comment }} |
| 59 | + GITHUB_TOKEN: ${{ inputs.github_token }} |
| 60 | + PR_NUMBER: ${{ github.event.pull_request.number }} |
| 61 | + run: python -m python_security_auditing |
| 62 | + |
| 63 | + - name: Upload audit reports |
| 64 | + if: always() |
| 65 | + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 |
| 66 | + with: |
| 67 | + name: security-audit-reports |
| 68 | + path: | |
| 69 | + ${{ inputs.working_directory }}/bandit-report.json |
| 70 | + ${{ inputs.working_directory }}/pip-audit-report.json |
| 71 | + if-no-files-found: ignore |
| 72 | + |
| 73 | + - name: Fail if blocking issues found |
| 74 | + if: steps.audit.outcome == 'failure' |
| 75 | + shell: bash |
| 76 | + run: exit 1 |
0 commit comments