## Description Run trivy and scout scanner with image name Fixes #`37036` ## Automation /ok-to-test tags="@tag.IDE" ### 🔍 Cypress test results <!-- This is an auto-generated comment: Cypress test results --> > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: <https://github.com/appsmithorg/appsmith/actions/runs/11480586298> > Commit: 5ebbcd37ec177c781d8b0be38a83ce695d211c9d > <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=11480586298&attempt=1" target="_blank">Cypress dashboard</a>. > Tags: `@tag.IDE` > Spec: > <hr>Wed, 23 Oct 2024 13:36:44 UTC <!-- end of auto-generated comment: Cypress test results --> ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [x] No <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced two new scripts for automated vulnerability scanning of Docker images: `scout_vulnerabilities_data.sh` and `trivy_vulnerabilities_data.sh`. - Added a GitHub Actions workflow to automate vulnerability scanning and update pull requests with results. - **Bug Fixes** - Improved error handling for missing environment variables in the new scripts. - **Documentation** - Added details on the new workflow and its steps for user reference. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
143 lines
5.4 KiB
YAML
143 lines
5.4 KiB
YAML
name: Run Vulnerability Data Script with Parameters and Update PR
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
inputs:
|
|
image_name:
|
|
description: 'Docker image name to scan'
|
|
required: true
|
|
default: 'appsmith/appsmith-ce:release'
|
|
|
|
jobs:
|
|
run-and-update-pr:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v3
|
|
|
|
- name: Set up Node.js
|
|
uses: actions/setup-node@v3
|
|
with:
|
|
node-version: '20'
|
|
|
|
- name: Login to DockerHub
|
|
uses: docker/login-action@v3
|
|
with:
|
|
username: ${{ secrets.DOCKER_HUB_USERNAME }}
|
|
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
|
|
|
|
- name: Install pg
|
|
run: npm install pg
|
|
|
|
- name: Fetch vulnerability data
|
|
id: vulnerability_data
|
|
env:
|
|
DB_HOST: ${{ secrets.CYPRESS_DB_HOST }}
|
|
DB_NAME: ${{ secrets.CYPRESS_DB_NAME }}
|
|
DB_USER: ${{ secrets.CYPRESS_DB_USER }}
|
|
DB_PWD: ${{ secrets.CYPRESS_DB_PWD }}
|
|
uses: actions/github-script@v7
|
|
with:
|
|
script: |
|
|
const { Pool } = require("pg");
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const { DB_HOST, DB_NAME, DB_USER, DB_PWD } = process.env;
|
|
|
|
const pool = new Pool({
|
|
user: DB_USER,
|
|
host: DB_HOST,
|
|
database: DB_NAME,
|
|
password: DB_PWD,
|
|
port: 5432,
|
|
connectionTimeoutMillis: 60000,
|
|
});
|
|
|
|
(async () => {
|
|
const client = await pool.connect();
|
|
try {
|
|
// Fetch vurn_id, product, scanner_tool, and priority from the database
|
|
const result = await client.query(`SELECT vurn_id, product, scanner_tool, priority FROM vulnerability_tracking`);
|
|
console.log('Vulnerability Data:', result.rows);
|
|
|
|
// Extract relevant fields from the result
|
|
const extractedData = result.rows.map(({ vurn_id, product, scanner_tool, priority }) => ({
|
|
vurn_id,
|
|
product,
|
|
scanner_tool,
|
|
priority
|
|
}));
|
|
console.log('Extracted Vulnerability Data:', extractedData);
|
|
|
|
// Prepare CSV content
|
|
const csvContent = [
|
|
['vurn_id', 'product', 'scanner_tool', 'priority'], // Add priority column header
|
|
...extractedData.map(row => [row.vurn_id, row.product, row.scanner_tool, row.priority])
|
|
]
|
|
.map(e => e.join(',')) // Join columns
|
|
.join('\n'); // Join rows
|
|
|
|
// Write to CSV file in workspace
|
|
const csvFilePath = path.join(process.env.GITHUB_WORKSPACE, 'vulnerability_base_data.csv');
|
|
fs.writeFileSync(csvFilePath, csvContent);
|
|
console.log(`Data successfully written to ${csvFilePath}`);
|
|
|
|
// Prepare TXT content
|
|
const txtContent = extractedData
|
|
.map(row => `vurn_id: ${row.vurn_id}, product: ${row.product}, scanner_tool: ${row.scanner_tool}, priority: ${row.priority}`)
|
|
.join('\n'); // Join rows
|
|
|
|
// Write to TXT file in workspace
|
|
const txtFilePath = path.join(process.env.GITHUB_WORKSPACE, 'vulnerability_base_data.txt');
|
|
fs.writeFileSync(txtFilePath, txtContent);
|
|
console.log(`Data successfully written to ${txtFilePath}`);
|
|
|
|
client.release();
|
|
return extractedData; // Return the extracted data
|
|
} catch (err) {
|
|
console.error('Error fetching vulnerability data:', err);
|
|
client.release();
|
|
}
|
|
})();
|
|
|
|
- name: Upload Vulnerability Data
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: vulnerability-data
|
|
path: |
|
|
vulnerability_base_data.csv
|
|
vulnerability_base_data.txt
|
|
|
|
# Run Scout vulnerability data script
|
|
- name: Run Scout vulnerability data script
|
|
if: always()
|
|
env:
|
|
DB_HOST: ${{ secrets.CYPRESS_DB_HOST }}
|
|
DB_NAME: ${{ secrets.CYPRESS_DB_NAME }}
|
|
DB_USER: ${{ secrets.CYPRESS_DB_USER }}
|
|
DB_PWD: ${{ secrets.CYPRESS_DB_PWD }}
|
|
run: |
|
|
chmod +x scripts/scout_vulnerabilities_data.sh
|
|
./scripts/scout_vulnerabilities_data.sh \
|
|
"${{ inputs.image_name }}" \
|
|
"${{ github.event.pull_request.number }}" \
|
|
"${{ github.event.pull_request.html_url }}" \
|
|
"${{ github.run_id }}"
|
|
|
|
- name: Run Trivy vulnerability data script
|
|
if: always()
|
|
env:
|
|
DB_HOST: ${{ secrets.CYPRESS_DB_HOST }}
|
|
DB_NAME: ${{ secrets.CYPRESS_DB_NAME }}
|
|
DB_USER: ${{ secrets.CYPRESS_DB_USER }}
|
|
DB_PWD: ${{ secrets.CYPRESS_DB_PWD }}
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
run: |
|
|
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u "${{ github.actor }}" --password-stdin
|
|
chmod +x scripts/trivy_vulnerabilities_data.sh
|
|
./scripts/trivy_vulnerabilities_data.sh \
|
|
"${{ inputs.image_name }}" \
|
|
"${{ github.event.pull_request.number }}" \
|
|
"${{ github.event.pull_request.html_url }}" \
|
|
"${{ github.run_id }}"
|
|
|