-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from ncats/SLS
Feat: Implement shift-left strategy to the smartgraph pub repo
- Loading branch information
Showing
2 changed files
with
200 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,62 @@ | ||
# For most projects, this workflow file will not need changing; you simply need | ||
# to commit it to your repository. | ||
# | ||
# You may wish to alter this file to override the set of languages analyzed, | ||
# or to provide custom queries or build logic. | ||
# | ||
# ******** NOTE ******** | ||
# We have attempted to detect the languages in your repository. Please check | ||
# the `language` matrix defined below to confirm you have the correct set of | ||
# supported CodeQL languages. | ||
# | ||
name: "CodeQL" | ||
# Define the name of the workflow | ||
name: "CodeQL-Advanced" | ||
|
||
# Define when the workflow should be triggered (on push to a specific branch and pull requests to the master branch) | ||
on: | ||
push: | ||
branches: [ "main" ] | ||
branches: | ||
- main | ||
pull_request: | ||
branches: [ "main" ] | ||
schedule: | ||
- cron: '18 17 * * 5' | ||
|
||
branches: | ||
- main | ||
# Define the jobs that will be executed as part of the workflow | ||
jobs: | ||
analyze: | ||
name: Analyze | ||
# Runner size impacts CodeQL analysis time. To learn more, please see: | ||
# - https://gh.io/recommended-hardware-resources-for-running-codeql | ||
# - https://gh.io/supported-runners-and-hardware-resources | ||
# - https://gh.io/using-larger-runners | ||
# Consider using larger runners for possible analysis time improvements. | ||
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }} | ||
timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }} | ||
runs-on: | ||
group: ncats-awsci-runners | ||
permissions: | ||
actions: read | ||
contents: read | ||
security-events: write | ||
issues: write | ||
|
||
# Define the matrix strategy for parallel runs with different languages | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
language: [ ] | ||
# CodeQL supports [ 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift' ] | ||
# Use only 'java-kotlin' to analyze code written in Java, Kotlin or both | ||
# Use only 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both | ||
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support | ||
language: ["python"] | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
# Initializes the CodeQL tools for scanning. | ||
- name: Initialize CodeQL | ||
uses: github/codeql-action/init@v3 | ||
with: | ||
languages: ${{ matrix.language }} | ||
# If you wish to specify custom queries, you can do so here or in a config file. | ||
# By default, queries listed here will override any specified in a config file. | ||
# Prefix the list here with "+" to use these queries and those in the config file. | ||
|
||
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs | ||
# queries: security-extended,security-and-quality | ||
|
||
|
||
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift). | ||
# If this step fails, then you should remove it and run the build manually (see below) | ||
- name: Autobuild | ||
uses: github/codeql-action/autobuild@v3 | ||
|
||
# ℹ️ Command-line programs to run using the OS shell. | ||
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun | ||
|
||
# If the Autobuild fails above, remove it and uncomment the following three lines. | ||
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. | ||
|
||
# - run: | | ||
# echo "Run, Build Application using script" | ||
# ./location_of_script_within_repo/buildscript.sh | ||
|
||
- name: Perform CodeQL Analysis | ||
uses: github/codeql-action/analyze@v3 | ||
with: | ||
category: "/language:${{matrix.language}}" | ||
# Step 1: Checkout repository | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
# Step 2: Initialize CodeQL for scanning | ||
- name: Initialize CodeQL | ||
uses: github/codeql-action/init@v3 | ||
with: | ||
languages: ${{ matrix.language }} | ||
|
||
# Step 3: Autobuild the code. | ||
- name: Autobuild | ||
uses: github/codeql-action/autobuild@v3 | ||
|
||
# Step 4: Analyzes the code using CodeQL, with the analysis category based on the matrix language. | ||
- name: Perform CodeQL Analysis | ||
uses: github/codeql-action/analyze@v3 | ||
with: | ||
category: "/language:${{matrix.language}}" | ||
|
||
# Step 5: Generate Security Report | ||
- name: Generate Security Report | ||
uses: rsdmike/[email protected] | ||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
# Step 6: Uploads artifacts (PDF reports) generated during the workflow to download. | ||
- name: Upload Artifacts | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: codeql-reports | ||
path: ./*.pdf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
# Define the name of the workflow | ||
name: snyk-zap | ||
|
||
# Define when the workflow should be triggered (on push to a specific branch and pull requests to the master branch) | ||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
workflow_dispatch: | ||
|
||
# Define the jobs that will be executed as part of the workflow | ||
jobs: | ||
# Job to build and push the ZAP Docker image to Docker Hub | ||
Snyk-Docker-Image: | ||
runs-on: | ||
group: ncats-awsci-runners | ||
permissions: | ||
actions: read | ||
contents: read | ||
security-events: write | ||
issues: write | ||
|
||
outputs: | ||
build_version: ${{ steps.get_build_version.outputs.build_version }} | ||
RUNNER: ${{ runner.name }} | ||
steps: | ||
# Step 1: Checkout repository | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
# Step 2: Generate Build Version Number | ||
- name: Generate Build Version Number | ||
id: GET_BUILD_VERSION | ||
run: | | ||
# Get the last recorded date from the environment variable | ||
LAST_DATE=$(date -d "$LAST_BUILD_DATE" +'%Y-%m-%d' 2>/dev/null || echo "") | ||
# Get the current date | ||
CURRENT_DATE=$(date +'%Y-%m-%d') | ||
echo "Last recorded date: $LAST_DATE" | ||
echo "Current date: $CURRENT_DATE" | ||
|
||
# Check if it's a new day | ||
if [ "$LAST_DATE" != "$CURRENT_DATE" ]; then | ||
# Reset BUILDS_TODAY to 0 for the new day | ||
BUILDS_TODAY=0 | ||
echo "Resetting BUILDS_TODAY to 0 for the new day" | ||
else | ||
# Calculate the number of builds today | ||
BUILDS_TODAY=$(seq -f v$GITHUB_RUN_NUMBER.%g $(($GITHUB_RUN_NUMBER - 1)) | wc -l) | ||
echo "Incrementing BUILDS_TODAY" | ||
fi | ||
|
||
# Store the current date for the next run | ||
echo "LAST_BUILD_DATE=$CURRENT_DATE" >> $GITHUB_ENV | ||
|
||
# Generate the build version with the number of builds today | ||
BUILD_VERSION_GENERATED=$(date +v%Y.%m%d.$BUILDS_TODAY) | ||
echo "Generated Build Version: $BUILD_VERSION_GENERATED" | ||
echo "BUILD_VERSION=$BUILD_VERSION_GENERATED" >> $GITHUB_ENV | ||
echo "BUILD=true" >> $GITHUB_ENV | ||
echo "::set-output name=build_version::$BUILD_VERSION_GENERATED" | ||
|
||
# # Step 3: Login to Dockerhub | ||
# - name: Login to Dockerhub | ||
# run: docker login -u "${{ secrets.DKRHUB_NCATSSVCDVOPS_USERNAME }}" -p "${{ secrets.DKRHUB_NCATSSVCDVOPS_TOKEN_WRITE }}" | ||
|
||
# Step 4: Build a Docker image | ||
- name: Build a Docker image | ||
run: docker build --no-cache -f ./Dockerfile --build-arg NPM_TOKEN=${{ secrets.NPM_INSTALL_TOKEN }} --build-arg BUILD_VERSION=$BUILD_VERSION -t ncats/smartgraph_api:$BUILD_VERSION . | ||
|
||
# Step 5: Run Snyk to check Docker image for vulnerabilities | ||
- name: Run Snyk to check Docker image for vulnerabilities | ||
continue-on-error: true | ||
uses: snyk/actions/docker@master | ||
id: docker-image-scan | ||
env: | ||
SNYK_TOKEN: ${{ secrets.SNYK_CLI }} | ||
with: | ||
image: ncats/smartgraph_api:$BUILD_VERSION | ||
args: --sarif-file-output=snyk.sarif --file=Dockerfile | ||
|
||
- name: Replace security-severity undefined for license-related findings | ||
continue-on-error: true | ||
run: | | ||
sed -i 's/"security-severity": "undefined"/"security-severity": "0"/g' snyk.sarif | ||
sed -i 's/"security-severity": "null"/"security-severity": "0"/g' snyk.sarif | ||
# Step 6: Upload result to GitHub Code Scanning | ||
- name: Upload result to GitHub Code Scanning | ||
# continue-on-error: true | ||
uses: github/codeql-action/upload-sarif@v3 | ||
with: | ||
sarif_file: snyk.sarif | ||
|
||
# Step 7: Generate Security Report | ||
- name: Generate Security Report | ||
uses: rsdmike/[email protected] | ||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
sarifReportDir: . | ||
# Step 8: Uploads artifacts (PDF reports) generated during the workflow to download. | ||
- name: Upload Artifacts | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: reports | ||
path: ./*.pdf | ||
|
||
ZAP-Docker-Scan: | ||
needs: Snyk-Docker-Image | ||
runs-on: ${{needs.Snyk-Docker-Image.outputs.RUNNER}} | ||
permissions: | ||
actions: read | ||
contents: read | ||
security-events: write | ||
issues: write | ||
|
||
steps: | ||
# Step 1: Get BUILD_VERSION from Snyk-Docker-Image job | ||
- name: Get BUILD_VERSION from Snyk-Docker-Image job | ||
id: get_runner_ip | ||
run: | | ||
echo "BUILD_VERSION=${{ needs.Snyk-Docker-Image.outputs.build_version }}" >> $GITHUB_ENV | ||
echo "::set-output name=runner_ip::$(hostname -I | cut -d' ' -f1)" | ||
# Step 2: Add the command to start Docker image on port 5058 | ||
- name: Start Docker image on port 5058 | ||
run: docker run -d -p 5058:5058 -e SMARTGRAPH_UI_URL=https://randomurl.com -e sg_api_int_port=5058 -e SMARTGRAPH_API_SWAGGER_URL=https://randomurl.com/docs -e SMARTGRAPH_API_BASE_PATH=/api -e WRITE_CONFIG=true ncats/smartgraph_api:${{ needs.Snyk-Docker-Image.outputs.build_version }} | ||
continue-on-error: true | ||
# Step 3: ZAP BASELINE SCAN | ||
- name: ZAP base Scan | ||
uses: zaproxy/[email protected] | ||
with: | ||
target: 'http://${{ steps.get_runner_ip.outputs.runner_ip }}:5058' # ip address of the runner | ||
docker_name: 'ghcr.io/zaproxy/zaproxy:stable' | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
fail_action: false | ||
continue-on-error: true | ||
# Step 4: Create SARIF file from ZAP results | ||
- name: Create SARIF file from ZAP results | ||
uses: SvanBoxel/zaproxy-to-ghas@main | ||
continue-on-error: true | ||
# Step 5: Upload SARIF file to GitHub Code Scanning | ||
- name: Upload SARIF file | ||
uses: github/codeql-action/upload-sarif@v3 | ||
with: | ||
sarif_file: results.sarif | ||
wait-for-processing: true | ||
continue-on-error: true | ||
# Step 6: Stop and remove the Docker container | ||
- name: Stop and remove Docker container | ||
run: docker stop $(docker ps -a -q --filter ancestor=ncats/smartgraph_api:$BUILD_VERSION) && docker rm -f $(docker ps -a -q --filter ancestor=ncats/smartgraph_api:$BUILD_VERSION) || true |