Skip to content

Commit 029f5eb

Browse files
authored
Merge pull request #24 from Algodons/copilot/fix-snyk-auth-and-codeql
2 parents 0842751 + 7dc77cf commit 029f5eb

6 files changed

Lines changed: 181 additions & 21 deletions

File tree

.github/CI_CD_DOCUMENTATION.md

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,52 @@ The repository uses GitHub Actions to automate:
8686
- Findings appear in the Security tab under Code scanning alerts
8787
- Failed scans will block PR merging if critical issues are found
8888

89-
### 3. Automated Code Review (`code-review.yml`)
89+
### 3. Snyk Security Scan (`snyk.yml`)
90+
91+
**Triggers:**
92+
- Pull requests to `main` and `develop`
93+
- Pushes to `main` and `develop`
94+
- Scheduled daily scans (2:00 AM UTC)
95+
- Manual workflow dispatch
96+
97+
**Purpose:**
98+
- Scans for vulnerabilities in dependencies (npm packages)
99+
- Checks Docker container images for security issues
100+
- Performs static code analysis for security vulnerabilities
101+
- Monitors production dependencies
102+
103+
**Jobs:**
104+
105+
#### Snyk Dependency Scan
106+
- Scans npm dependencies for known vulnerabilities
107+
- Uploads results to GitHub Security tab
108+
- Fails on high severity issues
109+
110+
#### Snyk Container Scan
111+
- Builds Docker image
112+
- Scans container for vulnerabilities
113+
- Only runs on push events and scheduled scans
114+
115+
#### Snyk Code Analysis
116+
- Performs static code analysis
117+
- Identifies security issues in source code
118+
- Checks for common vulnerabilities (XSS, injection, etc.)
119+
120+
#### Snyk Monitor (Production)
121+
- Monitors production dependencies
122+
- Only runs on pushes to main branch
123+
- Tracks vulnerabilities over time in Snyk dashboard
124+
125+
**Configuration Required:**
126+
- **SNYK_TOKEN** secret must be configured (see Repository Secrets section)
127+
- Get your token from: https://app.snyk.io/account
128+
129+
**Results:**
130+
- Findings appear in the Security tab under Code scanning alerts
131+
- SARIF files uploaded for integration with GitHub Security
132+
- Failed scans will block PR merging if critical issues are found
133+
134+
### 4. Automated Code Review (`code-review.yml`)
90135

91136
**Triggers:**
92137
- Pull requests opened, synchronized, or reopened
@@ -109,7 +154,7 @@ The repository uses GitHub Actions to automate:
109154
- Comments on PRs if bundle size increases significantly
110155
- Helps prevent performance regressions
111156

112-
### 4. Auto-Approve Workflow (`auto-approve.yml`)
157+
### 5. Auto-Approve Workflow (`auto-approve.yml`)
113158

114159
**Triggers:**
115160
- Pull requests opened, synchronized, or reopened
@@ -138,7 +183,7 @@ TRUSTED_USERS=(
138183
)
139184
```
140185

141-
### 5. PR Notifications (`pr-notifications.yml`)
186+
### 6. PR Notifications (`pr-notifications.yml`)
142187

143188
**Triggers:**
144189
- PR opened, reopened, or marked ready for review
@@ -213,10 +258,11 @@ Follow the instructions in [BRANCH_PROTECTION.md](.github/BRANCH_PROTECTION.md)
213258
- Conversation resolution
214259
- Other protection settings
215260

216-
### 3. Repository Secrets (Optional)
261+
### 3. Repository Secrets (Required & Optional)
217262

218263
Configure in Settings → Secrets and variables → Actions:
219-
- `CODECOV_TOKEN` - For code coverage reporting
264+
- `SNYK_TOKEN` - **Required** for Snyk security scanning. Get your token from [Snyk Account Settings](https://app.snyk.io/account)
265+
- `CODECOV_TOKEN` - Optional for code coverage reporting
220266

221267
### 4. Create Required Labels
222268

.github/SNYK_SETUP.md

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# Snyk Security Scanning Setup Guide
2+
3+
## Overview
4+
This repository uses Snyk for comprehensive security scanning of dependencies, container images, and source code. The Snyk workflow has been configured but requires a secret token to function properly.
5+
6+
## Required Configuration
7+
8+
### Step 1: Obtain Your Snyk API Token
9+
1. Go to [Snyk Account Settings](https://app.snyk.io/account)
10+
2. Log in to your Snyk account (create one if you don't have it)
11+
3. Navigate to **Settings****General****API Token**
12+
4. Click **Show** to reveal your API token
13+
5. Copy the token (it should start with a UUID format)
14+
15+
### Step 2: Add SNYK_TOKEN to GitHub Repository Secrets
16+
1. Go to your GitHub repository: https://github.com/Algodons/algo
17+
2. Navigate to **Settings****Secrets and variables****Actions**
18+
3. Click **New repository secret**
19+
4. Set the following:
20+
- **Name**: `SNYK_TOKEN`
21+
- **Secret**: Paste your Snyk API token from Step 1
22+
5. Click **Add secret**
23+
24+
### Step 3: Verify the Configuration
25+
After adding the secret, the Snyk workflow will be able to authenticate properly. You can verify by:
26+
27+
1. Pushing a commit to `main` or `develop` branch, or
28+
2. Manually triggering the workflow from the Actions tab
29+
3. Checking that the workflow runs successfully without authentication errors
30+
31+
## What This Enables
32+
33+
With the SNYK_TOKEN configured, the repository will have:
34+
35+
### 1. **Dependency Scanning**
36+
- Automatically scans `package.json` and `package-lock.json` for vulnerable dependencies
37+
- Runs on every push and pull request
38+
- Results uploaded to GitHub Security tab
39+
40+
### 2. **Container Scanning**
41+
- Scans Docker images for vulnerabilities
42+
- Checks base images and installed packages
43+
- Runs on pushes to main/develop branches
44+
45+
### 3. **Code Analysis**
46+
- Static analysis of source code for security issues
47+
- Identifies common vulnerabilities (XSS, SQL injection, etc.)
48+
- Provides remediation advice
49+
50+
### 4. **Production Monitoring**
51+
- Monitors production dependencies on main branch
52+
- Tracks vulnerabilities over time in Snyk dashboard
53+
- Sends alerts for newly discovered issues
54+
55+
## Workflow Schedule
56+
57+
The Snyk security scan runs:
58+
- On every push to `main` and `develop` branches
59+
- On every pull request to `main` and `develop` branches
60+
- Daily at 2:00 AM UTC (scheduled scan)
61+
- On manual workflow dispatch
62+
63+
## Viewing Results
64+
65+
### In GitHub
66+
1. Go to the **Security** tab in your repository
67+
2. Click **Code scanning alerts**
68+
3. Filter by tool: "Snyk"
69+
70+
### In Snyk Dashboard
71+
1. Log in to [Snyk Dashboard](https://app.snyk.io)
72+
2. Select your organization
73+
3. View "algo-cloud-ide" project
74+
4. See detailed vulnerability reports and remediation advice
75+
76+
## Troubleshooting
77+
78+
### Authentication Errors (SNYK-0005)
79+
**Error**: `Authentication credentials not recognized, or user access is not provisioned`
80+
81+
**Solutions**:
82+
- Verify SNYK_TOKEN secret is correctly set in GitHub
83+
- Ensure the token is valid and not expired
84+
- Regenerate a new token from Snyk if needed
85+
- Check that the token has proper permissions in Snyk
86+
87+
### Missing SARIF File
88+
**Error**: `Path does not exist: snyk.sarif`
89+
90+
**Solutions**:
91+
- This usually occurs when authentication fails
92+
- Fix the SNYK_TOKEN first
93+
- The SARIF file is now automatically generated with `--sarif-file-output=snyk.sarif`
94+
95+
### Incompatible CLI Flags
96+
**Error**: `Invalid flag option (SNYK-CLI-0004)`
97+
98+
**Solutions**:
99+
- This has been fixed in the workflow
100+
- The monitor job now only uses `--all-projects` flag
101+
- No action needed
102+
103+
## Support
104+
105+
For questions or issues:
106+
1. Check the [Snyk Documentation](https://docs.snyk.io/)
107+
2. Review workflow logs in GitHub Actions tab
108+
3. Contact the DevOps team
109+
4. Open an issue in the repository
110+
111+
## Security Note
112+
113+
⚠️ **Never commit the SNYK_TOKEN to version control!**
114+
Always use GitHub Secrets for storing sensitive tokens and credentials.

.github/workflows/codeql.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
uses: actions/checkout@v4
3333

3434
- name: Initialize CodeQL
35-
uses: github/codeql-action/init@v3
35+
uses: github/codeql-action/init@v4
3636
with:
3737
languages: ${{ matrix.language }}
3838
queries: +security-and-quality
@@ -52,7 +52,7 @@ jobs:
5252
npm run build:server
5353
5454
- name: Perform CodeQL Analysis
55-
uses: github/codeql-action/analyze@v3
55+
uses: github/codeql-action/analyze@v4
5656
with:
5757
category: "/language:${{ matrix.language }}"
5858

.github/workflows/security-scan.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ jobs:
9494
continue-on-error: true
9595

9696
- name: Upload Semgrep results
97-
uses: github/codeql-action/upload-sarif@v3
97+
uses: github/codeql-action/upload-sarif@v4
9898
if: always()
9999
with:
100100
sarif_file: semgrep.sarif
@@ -118,7 +118,7 @@ jobs:
118118
continue-on-error: true
119119

120120
- name: Upload OSV results
121-
uses: github/codeql-action/upload-sarif@v3
121+
uses: github/codeql-action/upload-sarif@v4
122122
if: always()
123123
with:
124124
sarif_file: osv-results.sarif
@@ -143,7 +143,7 @@ jobs:
143143
continue-on-error: true
144144

145145
- name: Upload Hadolint results
146-
uses: github/codeql-action/upload-sarif@v3
146+
uses: github/codeql-action/upload-sarif@v4
147147
if: always()
148148
with:
149149
sarif_file: hadolint.sarif

.github/workflows/snyk.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ jobs:
4343
env:
4444
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
4545
with:
46-
args: --severity-threshold=high --all-projects
46+
args: --severity-threshold=high --all-projects --sarif-file-output=snyk.sarif
4747

4848
- name: Upload Snyk results to GitHub Code Scanning
49-
uses: github/codeql-action/upload-sarif@v3
49+
uses: github/codeql-action/upload-sarif@v4
5050
if: always()
5151
with:
5252
sarif_file: snyk.sarif
@@ -70,10 +70,10 @@ jobs:
7070
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
7171
with:
7272
image: algo-cloud-ide:${{ github.sha }}
73-
args: --severity-threshold=high
73+
args: --severity-threshold=high --sarif-file-output=snyk.sarif
7474

7575
- name: Upload Snyk container results
76-
uses: github/codeql-action/upload-sarif@v3
76+
uses: github/codeql-action/upload-sarif@v4
7777
if: always()
7878
with:
7979
sarif_file: snyk.sarif
@@ -93,10 +93,10 @@ jobs:
9393
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
9494
with:
9595
command: code test
96-
args: --severity-threshold=high
96+
args: --severity-threshold=high --sarif-file-output=snyk.sarif
9797

9898
- name: Upload Snyk Code results
99-
uses: github/codeql-action/upload-sarif@v3
99+
uses: github/codeql-action/upload-sarif@v4
100100
if: always()
101101
with:
102102
sarif_file: snyk.sarif
@@ -125,7 +125,7 @@ jobs:
125125
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
126126
with:
127127
command: monitor
128-
args: --all-projects --project-name="algo-cloud-ide"
128+
args: --all-projects
129129

130130
dependency-review:
131131
name: Dependency Review

.github/workflows/trivy.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
ignore-unfixed: true
4040

4141
- name: Upload Trivy repo scan results to GitHub Security
42-
uses: github/codeql-action/upload-sarif@v3
42+
uses: github/codeql-action/upload-sarif@v4
4343
if: always()
4444
with:
4545
sarif_file: 'trivy-repo-results.sarif'
@@ -72,7 +72,7 @@ jobs:
7272
exit-code: '0'
7373

7474
- name: Upload Trivy config scan results
75-
uses: github/codeql-action/upload-sarif@v3
75+
uses: github/codeql-action/upload-sarif@v4
7676
if: always()
7777
with:
7878
sarif_file: 'trivy-config-results.sarif'
@@ -100,7 +100,7 @@ jobs:
100100
vuln-type: 'os,library'
101101

102102
- name: Upload Trivy Docker scan results
103-
uses: github/codeql-action/upload-sarif@v3
103+
uses: github/codeql-action/upload-sarif@v4
104104
if: always()
105105
with:
106106
sarif_file: 'trivy-docker-results.sarif'
@@ -133,7 +133,7 @@ jobs:
133133
severity: 'CRITICAL,HIGH,MEDIUM'
134134

135135
- name: Upload Trivy Kubernetes scan results
136-
uses: github/codeql-action/upload-sarif@v3
136+
uses: github/codeql-action/upload-sarif@v4
137137
if: always()
138138
with:
139139
sarif_file: 'trivy-k8s-results.sarif'

0 commit comments

Comments
 (0)