Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .github/workflows/bandit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: "Bandit Security Scan"

on:
push:
branches: [ "main", "develop" ]
pull_request:
branches: [ "main", "develop" ]

permissions:
contents: read
security-events: write

jobs:
bandit:
name: Bandit Scan
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'

# bandit-sarif-formatter is required to successfully output the .sarif format
- name: Install Bandit and Dependencies
run: |
pip install bandit bandit-sarif-formatter

# Added an explicit check to make sure the file exists before running the upload step
- name: Run Bandit Scan
run: |
bandit -r . -f sarif -o bandit-results.sarif || true
if [ ! -f bandit-results.sarif ]; then
echo "Bandit failed to generate SARIF output. Creating an empty fallback report."
echo '{"$schema":"https://schemastore.azurewebsites.net/schemas/json/sarif-2.1.0-rtm.5.json","version":"2.1.0","runs":[]}' > bandit-results.sarif
fi

# Upgraded action from v3 to v4 to fix the runner deprecation warning shown in your logs
- name: Upload Bandit Scan Results to GitHub Security
uses: github/codeql-action/upload-sarif@v4
with:
sarif_file: bandit-results.sarif
category: bandit
50 changes: 50 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: "CodeQL SAST Analysis"

on:
push:
branches: [ "main", "develop" ]
pull_request:
branches: [ "main", "develop" ]
schedule:
- cron: '30 4 * * 6' # Runs every Saturday at 04:30 UTC

permissions:
actions: read
contents: read
security-events: write

jobs:
analyze:
name: CodeQL Scan
runs-on: ubuntu-latest
timeout-minutes: 360

strategy:
fail-fast: false
matrix:
# CodeQL supports: 'cpp', 'csharp', 'go', 'java-bytecode', 'javascript-typescript', 'python', 'ruby', 'swift'
# Adjust languages based on your repository stack (e.g., python, javascript-typescript)
language: [ 'python', 'javascript-typescript' ]

steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
queries: security-extended,security-and-quality

# Autobuild attempts to build any compiled languages if present
- name: Autobuild
uses: github/codeql-action/autobuild@v3

# If Autobuild fails, uncomment and adjust manual build steps for compiled languages:
# - run: |
# make build

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{matrix.language}}"
74 changes: 74 additions & 0 deletions .github/workflows/trivy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: Trivy Container Scan & SBOM Reporter

on:
workflow_run:
workflows: ["CD Pipeline"] # Replace with the exact name of your CD workflow
types:
- completed

permissions:
contents: read
pull-requests: write

jobs:
scan-and-report:
name: Container Security & SBOM Diff
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}

steps:
- name: Checkout Code
uses: actions/checkout@v4

# Download build artifacts or image tarballs from the triggering CD workflow if necessary
# For standard registry setups, pull the image built by the CD pipeline
- name: Authenticate to Container Registry
run: |
echo "Logging into container registry..."
# Add registry auth here if pulling from a private registry (e.g., GHCR, AWS ECR)

- name: Generate SBOM and Scan Container
uses: aquasecurity/trivy-action@master
with:
image-ref: 'quantara-service:latest' # Replace with your target image name/tag
format: 'github'
output: 'dependency-snapshot.json'
scan-type: 'image'

- name: Generate Readable SBOM Markdown Summary
uses: aquasecurity/trivy-action@master
with:
image-ref: 'quantara-service:latest'
format: 'table'
output: 'trivy-report.txt'
severity: 'HIGH,CRITICAL'

- name: Post SBOM & Vulnerability Report to PR
uses: actions/github-script@v7
if: ${{ github.event.workflow_run.pull_requests[0] != null }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs');
const report = fs.readFileSync('trivy-report.txt', 'utf8');
const prNumber = context.payload.workflow_run.pull_requests[0].number;

const commentBody = `
### 🛡️ Trivy Container Security & SBOM Report

The container scan completed successfully following the CD pipeline deployment.

#### High & Critical Vulnerabilities Summary
\`\`\`text
${report || 'No high or critical vulnerabilities detected.'}
\`\`\`

*Report generated automatically for verification.*
`;

await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: commentBody
});
Loading