Skip to content

Commit cd5b311

Browse files
JGowsk9Justin Golanowski
andauthored
adding code analysis & dependency review (#2150)
Co-authored-by: Justin Golanowski <justingolanowski@Justins-MacBook-Pro.local>
1 parent 16db6c5 commit cd5b311

2 files changed

Lines changed: 132 additions & 0 deletions

File tree

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: "CodeQL Analysis"
2+
on:
3+
push:
4+
branches:
5+
- master
6+
pull_request:
7+
branches:
8+
- master
9+
schedule:
10+
- cron: '0 0 * * *'
11+
jobs:
12+
analyze-code:
13+
runs-on: ubuntu-latest
14+
permissions:
15+
actions: read
16+
contents: read
17+
security-events: write
18+
pull-requests: write
19+
20+
env:
21+
GOPRIVATE: "github.com/onflow, github.com/axiomzen"
22+
# ORG_READER_PAT: ${{ secrets.ORG_READER_PAT }}
23+
# ORG_READER_USERNAME: ${{ secrets.ORG_READER_USERNAME }}
24+
25+
strategy:
26+
fail-fast: false
27+
matrix:
28+
languages: ['go']
29+
steps:
30+
- name: Checkout repository
31+
uses: actions/checkout@v4
32+
33+
- name: Setup Go
34+
uses: actions/setup-go@v4
35+
with:
36+
go-version-file: ./go.mod
37+
38+
# - name: set credentials for private repos
39+
# run: rm -f ~/.gitconfig && git config --global url.https://$ORG_READER_USERNAME:$ORG_READER_PAT@github.com/.insteadOf https://github.com/ && cat ~/.gitconfig
40+
41+
- name: Tidy Go and mod vendor
42+
run: go mod tidy && go mod vendor
43+
44+
45+
- name: Initialize CodeQL
46+
uses: github/codeql-action/init@v3
47+
with:
48+
languages: ${{ matrix.languages}}
49+
queries: security-extended
50+
51+
- name: Build
52+
run: CGO_ENABLED=0 go build -mod=vendor -tags=no_cgo ./...
53+
54+
- name: CodeQL Analyze
55+
uses: github/codeql-action/analyze@v3
56+
with:
57+
category: "/language:${{ matrix.languages}}"
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Dependency Review Action
2+
3+
# PRs introducing NEW known-vulnerable packages will be blocked from merging.
4+
# This will output a GHAS comment in the PR with the details of the vulnerabilities.
5+
# and will also provide a comment on what to do next.
6+
7+
# Public documentation: https://docs.github.com/en/code-security/supply-chain-security/understanding-your-software-supply-chain/about-dependency-review#dependency-review-enforcement
8+
name: "Dependency review"
9+
on:
10+
pull_request:
11+
branches: ["master"]
12+
13+
permissions:
14+
contents: read
15+
pull-requests: write # Required for PR comments
16+
17+
jobs:
18+
dependency-review:
19+
runs-on: ubuntu-latest
20+
outputs:
21+
vulnerable-changes: ${{ steps.review.outputs.vulnerable-changes }}
22+
steps:
23+
- name: "Checkout repository"
24+
uses: actions/checkout@v4
25+
- name: "Dependency Review"
26+
id: review
27+
uses: actions/dependency-review-action@v4
28+
with:
29+
comment-summary-in-pr: always
30+
fail-on-severity: moderate
31+
#allow-ghsas: GHSA-q34m-jh98-gwm2,GHSA-f9vj-2wh5-fj8j EXAMPLE of how to whitelist!
32+
33+
dependency-review-failure-info:
34+
needs: dependency-review
35+
if: failure()
36+
runs-on: ubuntu-latest
37+
steps:
38+
- name: Add PR Comment
39+
uses: actions/github-script@v7
40+
env:
41+
VULN_OUTPUT: ${{ needs.dependency-review.outputs.vulnerable-changes }}
42+
with:
43+
script: |
44+
try {
45+
const vulnData = JSON.parse(process.env.VULN_OUTPUT || '[]');
46+
let details = '';
47+
48+
for (const pkg of vulnData) {
49+
details += `\n📦 **${pkg.name}@${pkg.version}**\n`;
50+
}
51+
52+
const comment = `⚠️ **Security Dependency Review Failed** ⚠️
53+
54+
This pull request introduces dependencies with security vulnerabilities of moderate severity or higher.
55+
56+
### Vulnerable Dependencies:${details}
57+
58+
### What to do next?
59+
1. Review the vulnerability details in the Dependency Review Comment above, specifically the "Vulnerabilities" section
60+
2. Click on the links in the "Vulnerability" section to see the details of the vulnerability
61+
3. If multiple versions of the same package are vulnerable, please update to the common latest non-vulnerable version
62+
4. If you are unsure about the vulnerability, please contact the security engineer
63+
5. If the vulnerability cannot be avoided (can't upgrade, or need to keep), contact #security on slack to **get it added to the allowlist**
64+
\nSecurity Engineering contact: #security on slack`;
65+
66+
await github.rest.issues.createComment({
67+
issue_number: context.issue.number,
68+
owner: context.repo.owner,
69+
repo: context.repo.repo,
70+
body: comment
71+
});
72+
} catch (error) {
73+
console.error('Error processing vulnerability data:', error);
74+
throw error;
75+
}

0 commit comments

Comments
 (0)