Skip to content

Commit 831c027

Browse files
tazarovHammadB
andauthored
[SEC]: Bandit Scan (chroma-core#1113)
## Description of changes *Summarize the changes made by this PR.* - Improvements & Bug fixes - Added bandit scanning for all pushes to repo ## Test plan *How are these changes tested?* Manual testing of the workflow ## Documentation Changes N/A - unless we want to start a separate security section in the main docs repo. --------- Co-authored-by: Hammad Bashir <[email protected]>
1 parent 7d412ae commit 831c027

File tree

5 files changed

+78
-0
lines changed

5 files changed

+78
-0
lines changed
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM python:3.10-alpine AS base-action
2+
3+
RUN pip3 install -U setuptools pip bandit
4+
5+
COPY entrypoint.sh /entrypoint.sh
6+
RUN chmod +x /entrypoint.sh
7+
ENTRYPOINT ["sh","/entrypoint.sh"]
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: 'Bandit Scan'
2+
description: 'This action performs a security vulnerability scan of python code using bandit library.'
3+
inputs:
4+
bandit-config:
5+
description: 'Bandit configuration file'
6+
required: false
7+
input-dir:
8+
description: 'Directory to scan'
9+
required: false
10+
default: '.'
11+
format:
12+
description: 'Output format (txt, csv, json, xml, yaml). Default: json'
13+
required: false
14+
default: 'json'
15+
output-file:
16+
description: "The report file to produce. Make sure to align your format with the file extension to avoid confusion."
17+
required: false
18+
default: "bandit-scan.json"
19+
runs:
20+
using: 'docker'
21+
image: 'Dockerfile'
22+
args:
23+
- ${{ inputs.format }}
24+
- ${{ inputs.bandit-config }}
25+
- ${{ inputs.input-dir }}
26+
- ${{ inputs.output-file }}
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
CFG="-c $2"
3+
if [ -z "$1" ]; then
4+
echo "No path to scan provided"
5+
exit 1
6+
fi
7+
8+
if [ -z "$2" ]; then
9+
CFG = ""
10+
fi
11+
12+
bandit -f "$1" ${CFG} -r "$3" -o "$4"
13+
exit 0 #we want to ignore the exit code of bandit (for now)

.github/workflows/python-vuln.yaml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Python Vulnerability Scan
2+
on:
3+
push:
4+
branches:
5+
- '*'
6+
- '*/**'
7+
paths:
8+
- chromadb/**
9+
- clients/python/**
10+
workflow_dispatch:
11+
jobs:
12+
bandit-scan:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v3
17+
- uses: ./.github/actions/bandit-scan/
18+
with:
19+
input-dir: '.'
20+
format: 'json'
21+
bandit-config: 'bandit.yaml'
22+
output-file: 'bandit-report.json'
23+
- name: Upload Bandit Report
24+
uses: actions/upload-artifact@v3
25+
with:
26+
name: bandit-artifact
27+
path: |
28+
bandit-report.json

bandit.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# FILE: bandit.yaml
2+
exclude_dirs: [ 'chromadb/test', 'bin', 'build', 'build', '.git', '.venv', 'venv', 'env','.github','examples','clients/js','.vscode' ]
3+
tests: [ ]
4+
skips: [ ]

0 commit comments

Comments
 (0)