Skip to content

ci: add Bandit SAST security scanning#2466

Merged
louiseschmidtgen merged 2 commits intomainfrom
KU-5601/add-bandit-sast
Mar 31, 2026
Merged

ci: add Bandit SAST security scanning#2466
louiseschmidtgen merged 2 commits intomainfrom
KU-5601/add-bandit-sast

Conversation

@louiseschmidtgen
Copy link
Copy Markdown
Contributor

Summary

Add Bandit as a Python SAST (Static Application Security Testing) tool to CI, as recommended by the security team.

Bandit scans the following directories for security issues:

  • tests/integration/
  • ci/
  • build-scripts/
  • docs/tools/

Behavior

  • CI blocks only on HIGH severity findings (-lll flag). If Bandit finds any HIGH severity issue, the python-lint job will fail.
  • LOW/MEDIUM issues are reported in the output but do not fail the build. Developers can run Bandit locally without -lll to see all severity levels.

Current scan results

Total lines of code: 9392
Total issues (by severity):
    Low: 205
    Medium: 50
    High: 0

No HIGH severity issues exist — CI will pass cleanly.

Changes

  • Add bandit==1.7.10 to tests/integration/requirements-dev.txt and ci/requirements-ci.txt
  • Add bandit tox environments in tests/integration/tox.ini and ci/tox.ini
  • Add Bandit security scan step to python-lint job in .github/workflows/lint_and_integration.yaml
  • Add pyproject.toml with [tool.bandit] configuration (exclude .tox dirs)

Follow-up

  • CodeQL analysis workflow (separate PR)
  • Semgrep scanning workflow (separate PR)

Signed-off-by: louiseschmidtgen <louise.schmidtgen@canonical.com>
Copilot AI review requested due to automatic review settings March 30, 2026 10:18
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds Bandit static security analysis to the repo’s Python CI pipeline, per security-team recommendation, to catch common Python security issues during linting.

Changes:

  • Add Bandit as a pinned dependency in CI/dev requirements and introduce tox environments to run it.
  • Add a Bandit scan step to the python-lint GitHub Actions job.
  • Add a root pyproject.toml with Bandit configuration (excluding .tox).

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
tests/integration/tox.ini Adds a bandit tox env to scan integration test Python code.
tests/integration/requirements-dev.txt Pins bandit==1.7.10 for integration tox environments.
pyproject.toml Adds Bandit configuration (exclude .tox).
ci/tox.ini Adds bandit tox env (and includes it in env_list).
ci/requirements-ci.txt Pins bandit==1.7.10 for CI tox environments.
.github/workflows/lint_and_integration.yaml Runs Bandit in CI as part of the python-lint job.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread ci/tox.ini
Comment thread tests/integration/tox.ini
Comment thread ci/tox.ini
Comment thread .github/workflows/lint_and_integration.yaml
Comment thread .github/workflows/lint_and_integration.yaml
Comment thread .github/workflows/lint_and_integration.yaml Outdated
Comment thread tests/integration/requirements-dev.txt Outdated
Comment thread ci/requirements-ci.txt Outdated
Signed-off-by: louiseschmidtgen <louise.schmidtgen@canonical.com>
Copy link
Copy Markdown
Contributor

@HomayoonAlimohammadi HomayoonAlimohammadi 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 a lot @louiseschmidtgen!

@louiseschmidtgen louiseschmidtgen merged commit 3258c62 into main Mar 31, 2026
147 checks passed
@louiseschmidtgen louiseschmidtgen deleted the KU-5601/add-bandit-sast branch March 31, 2026 09:07
louiseschmidtgen added a commit to canonical/calico-rocks that referenced this pull request Apr 8, 2026
- Add Semgrep SAST workflow with p/python and p/github-actions rulesets
- Add Bandit security scan workflow (HIGH severity blocks, -lll)
- Pin pip dependencies with hash verification (OSSF Scorecard compliance)
- Add pyproject.toml with bandit configuration

All tools run as advisory-only; results uploaded to GitHub Security tab via SARIF.

Ref: canonical/k8s-snap#2468 (semgrep)
Ref: canonical/k8s-snap#2466 (bandit)
Ref: canonical/k8s-snap#2492 (dep-pinning)
louiseschmidtgen added a commit to canonical/cinder-csi-operator that referenced this pull request Apr 8, 2026
- Add Semgrep SAST workflow with p/python and p/github-actions rulesets
- Add Bandit security scan workflow (HIGH severity blocks, -lll)
- Pin pip dependencies with hash verification (OSSF Scorecard compliance)
- Add bandit configuration to pyproject.toml

All tools run as advisory-only; results uploaded to GitHub Security tab via SARIF.

Ref: canonical/k8s-snap#2468 (semgrep)
Ref: canonical/k8s-snap#2466 (bandit)
Ref: canonical/k8s-snap#2492 (dep-pinning)
louiseschmidtgen added a commit to charmed-kubernetes/jenkins that referenced this pull request Apr 8, 2026
- Add Semgrep SAST workflow with p/python and p/github-actions rulesets
- Add Bandit security scan workflow (HIGH severity blocks, -lll) with weekly schedule
- Pin pip dependencies with hash verification (OSSF Scorecard compliance)
- Add pyproject.toml with bandit configuration

Semgrep results uploaded to GitHub Security tab via SARIF.
Bandit runs as pass/fail check in CI logs.

Ref: canonical/k8s-snap#2468 (semgrep)
Ref: canonical/k8s-snap#2466 (bandit)
Ref: canonical/k8s-snap#2492 (dep-pinning)
bschimke95 pushed a commit to canonical/calico-rocks that referenced this pull request Apr 9, 2026
* ci: add SAST workflows (semgrep + bandit) with dep-pinned installs

- Add Semgrep SAST workflow with p/python and p/github-actions rulesets
- Add Bandit security scan workflow (HIGH severity blocks, -lll)
- Pin pip dependencies with hash verification (OSSF Scorecard compliance)
- Add pyproject.toml with bandit configuration

All tools run as advisory-only; results uploaded to GitHub Security tab via SARIF.

Ref: canonical/k8s-snap#2468 (semgrep)
Ref: canonical/k8s-snap#2466 (bandit)
Ref: canonical/k8s-snap#2492 (dep-pinning)

* fix: update codeql-action to v4, fix bandit format

- Update github/codeql-action/upload-sarif from v3 to v4
- Remove unsupported SARIF output from bandit (1.7.10 lacks --format sarif)
- Bandit now runs as pass/fail check (blocks on HIGH severity)

* ci: add weekly schedule trigger to bandit workflow
This was referenced Apr 9, 2026
bschimke95 pushed a commit to charmed-kubernetes/jenkins that referenced this pull request Apr 9, 2026
…1673)

- Add Semgrep SAST workflow with p/python and p/github-actions rulesets
- Add Bandit security scan workflow (HIGH severity blocks, -lll) with weekly schedule
- Pin pip dependencies with hash verification (OSSF Scorecard compliance)
- Add pyproject.toml with bandit configuration

Semgrep results uploaded to GitHub Security tab via SARIF.
Bandit runs as pass/fail check in CI logs.

Ref: canonical/k8s-snap#2468 (semgrep)
Ref: canonical/k8s-snap#2466 (bandit)
Ref: canonical/k8s-snap#2492 (dep-pinning)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants