Skip to content

Commit

Permalink
Merge pull request #401 from netscaler/bandit-github-security-integra…
Browse files Browse the repository at this point in the history
…tion

integrated bandit output to github-codeql
  • Loading branch information
sumanth-lingappa authored Apr 8, 2024
2 parents c412329 + 745579d commit 8f73b9a
Showing 1 changed file with 9 additions and 44 deletions.
53 changes: 9 additions & 44 deletions .github/workflows/bandit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,58 +22,23 @@ jobs:
with:
python-version: '3.x'

- name: Find Pull Request
id: find-pull-request
uses: jwalton/gh-find-current-pr@v1
with:
# Can be "open", "closed", or "all". Defaults to "open".
state: open
# - name: Find Comment
# uses: peter-evans/find-comment@v2
# id: fc
# with:
# issue-number: ${{ steps.find-pull-request.outputs.number }}
# comment-author: 'github-actions[bot]'
# body-includes: Bandit found some security issues in your code.
# - name: Delete previous comment
# if: steps.fc.outputs.comment-id != ''
# uses: actions/github-script@v6
# with:
# script: |
# github.rest.issues.deleteComment({
# owner: context.repo.owner,
# repo: context.repo.repo,
# comment_id: ${{ steps.fc.outputs.comment-id }}
# })
- name: Install Bandit
run: pip install bandit
- name: Install Bandit with Sarif extras
run: pip install "bandit[sarif]"

- name: Run Bandit
id: bandit
continue-on-error: true
run: |
set +e
set +x
bandit -r . -f csv -o bandit-output.csv
bandit -r . -f sarif -o bandit-output.sarif
echo "exit_code=$?" >> $GITHUB_OUTPUT
OUTPUT=$(cat bandit-output.csv)
cat bandit-output.csv
echo "report<<EOF"$'\n'"$OUTPUT"$'\n'EOF >> $GITHUB_OUTPUT
- name: Convert CSV to Markdown
if: steps.bandit.outputs.exit_code != 0
uses: petems/csv-to-md-table-action@master
id: csv-table-output
with:
csvinput: ${{ steps.bandit.outputs.report }}
- name: Create comment
if: steps.bandit.outputs.exit_code != 0
id: create-comment
uses: peter-evans/create-or-update-comment@v4
cat bandit-output.sarif
- name: Upload Bandit scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v3
with:
issue-number: ${{ steps.find-pull-request.outputs.number }}
body: |
Bandit found some security issues in your code. Please fix them to ensure the security of your code.
${{steps.csv-table-output.outputs.markdown-table}}
reactions: rocket
sarif_file: "bandit-output.sarif"

- name: Fail if Bandit run had errors
if: steps.bandit.outputs.exit_code != 0
Expand Down

0 comments on commit 8f73b9a

Please sign in to comment.