Skip to content

Conversation

AmberJBlue
Copy link
Member

@AmberJBlue AmberJBlue commented Aug 7, 2025

  • Update security.yaml workflow
    • Update Trivy scan
    • Adds Bandit scan

Summary by Sourcery

Revamp the security scan workflow to improve vulnerability detection and add Python static analysis

New Features:

  • Introduce a dedicated Bandit job to perform Python security linting and upload SARIF results

Enhancements:

  • Rename and restructure the security workflow to “Security Scan” with unified triggers
  • Switch Trivy job to ubuntu-latest, add Python setup and dependency installation
  • Extend Trivy scan to enforce failure on critical/high vulnerabilities and upload SARIF output

@AmberJBlue AmberJBlue self-assigned this Aug 7, 2025
Copy link

sourcery-ai bot commented Aug 7, 2025

Reviewer's Guide

Overhauls the security GitHub Actions workflow by renaming and restructuring triggers, enriching the Trivy scan with Python setup and severity checks, and introducing a standalone Bandit scanning job.

Flow diagram for Bandit scan job in security workflow

flowchart TD
  A[Checkout code]
  B[Set up Python]
  C[Create virtual environment]
  D[Install dependencies]
  E[Install Bandit]
  F[Run Bandit Security Scan]
  G[Upload SARIF results to Security tab]
  H[Upload SARIF as artifact]

  A --> B --> C --> D --> E --> F --> G --> H
Loading

File-Level Changes

Change Details Files
Revamp workflow triggers and job structure
  • Renamed workflow to “Security Scan” and unified branch syntax
  • Added workflow_dispatch event for manual runs
  • Split original build job into separate Trivy and Bandit jobs
.github/workflows/security.yaml
Enhance Trivy scan job
  • Switched runner to ubuntu-latest and added Python setup with dependency installation
  • Adjusted severity ordering and added a separate critical/high vulnerability check step
  • Updated SARIF upload step with explicit category and always-run condition
.github/workflows/security.yaml
Add Bandit scanning job
  • Introduced a new Bandit job with Python venv creation and dependency installation
  • Configured the Bandit action to produce SARIF and upload to Security tab
  • Persisted SARIF results as a GitHub artifact with a 30-day retention
.github/workflows/security.yaml
Clean up pyproject.toml formatting
  • Normalized indentation of the setuptools_scm block
pyproject.toml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @AmberJBlue - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `.github/workflows/security.yaml:89` </location>
<code_context>
+          source .venv/bin/activate
+          pip install -e ".[dev]"
+
+      - name: Install Bandit
+        run: |
+          source .venv/bin/activate
+          pip install bandit[sarif]
+
+      - name: Run Bandit Security Scan
</code_context>

<issue_to_address>
Bandit is installed separately despite being used via a GitHub Action.

Check if installing Bandit separately is required, as the GitHub Action may already handle this. Remove the step if it's unnecessary.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
      - name: Install Bandit
        run: |
          source .venv/bin/activate
          pip install bandit[sarif]

      - name: Run Bandit Security Scan
        uses: PyCQA/bandit-action@v1
        with:
          targets: "."
          exclude: "tests"
=======
      - name: Run Bandit Security Scan
        uses: PyCQA/bandit-action@v1
        with:
          targets: "."
          exclude: "tests"
>>>>>>> REPLACE

</suggested_fix>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +89 to +98
- name: Install Bandit
run: |
source .venv/bin/activate
pip install bandit[sarif]

- name: Run Bandit Security Scan
uses: PyCQA/bandit-action@v1
with:
targets: "."
exclude: "tests"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Bandit is installed separately despite being used via a GitHub Action.

Check if installing Bandit separately is required, as the GitHub Action may already handle this. Remove the step if it's unnecessary.

Suggested change
- name: Install Bandit
run: |
source .venv/bin/activate
pip install bandit[sarif]
- name: Run Bandit Security Scan
uses: PyCQA/bandit-action@v1
with:
targets: "."
exclude: "tests"
- name: Run Bandit Security Scan
uses: PyCQA/bandit-action@v1
with:
targets: "."
exclude: "tests"

@github-advanced-security
Copy link

This pull request sets up GitHub code scanning for this repository. Once the scans have completed and the checks have passed, the analysis results for this pull request branch will appear on this overview. Once you merge this pull request, the 'Security' tab will show more code scanning analysis results (for example, for the default branch). Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results. For more information about GitHub code scanning, check out the documentation.

@ruivieira ruivieira added the kind/enhancement New feature or request label Aug 7, 2025
Copy link
Member

@ruivieira ruivieira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @AmberJBlue!

@ruivieira ruivieira moved this to In Review in TrustyAI planning Aug 7, 2025
@ruivieira ruivieira changed the title Update security scan chore: Update security scan Aug 7, 2025
@ruivieira ruivieira merged commit 83f30b2 into trustyai-explainability:main Aug 7, 2025
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement New feature or request
Projects
Status: In Review
Development

Successfully merging this pull request may close these issues.

2 participants