Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
0f6dd0b
feat: add Trivy security scan workflow for vulnerability detection
aavinash-nr Aug 14, 2025
126f9b6
chore: Update security-scan.yml
aavinash-nr Aug 14, 2025
ccce8a5
feat: Update security-scan.yml
aavinash-nr Aug 14, 2025
9000659
feat: Update security-scan.yml
aavinash-nr Aug 14, 2025
849cc44
Update security-scan.yml
aavinash-nr Aug 14, 2025
dc02d58
chore: testing workflow
aavinash-nr Aug 14, 2025
c9265ce
chore: update docker and security scan to use this docker
aavinash-nr Aug 14, 2025
7597a57
chore: updated docker file
aavinash-nr Aug 14, 2025
6134d0b
chore: updated code
aavinash-nr Aug 14, 2025
cb9823c
chore : updated dependency-tree check
aavinash-nr Aug 14, 2025
6a0720b
chore : updating mod
aavinash-nr Aug 14, 2025
61fa164
Merge branch 'dev' into NR-429672-trivy-workflow
aavinash-nr Aug 14, 2025
452eeb5
chore: updated docker
aavinash-nr Aug 14, 2025
01b5284
chore: updated docker
aavinash-nr Aug 14, 2025
869b4f6
chore: updated yml
aavinash-nr Aug 14, 2025
b099240
chore: updated workflow
aavinash-nr Aug 14, 2025
99cf99d
chore: updated workflow
aavinash-nr Aug 14, 2025
290a5be
chore: updating workflow
aavinash-nr Aug 14, 2025
48b3286
Update security-scan.yml
aavinash-nr Aug 18, 2025
debbc43
Update security-scan.yml
aavinash-nr Aug 18, 2025
7c2d1ff
Update security-scan.yml
aavinash-nr Aug 18, 2025
ed8790b
chore: Update security-scan.yml
aavinash-nr Aug 18, 2025
84a922e
chore: Update security-scan.yml
aavinash-nr Aug 18, 2025
0c2392d
chore: update security-scan.yml
aavinash-nr Aug 18, 2025
5a9b722
Update security-scan.yml
aavinash-nr Aug 18, 2025
9fe3e83
Update security-scan.yml
aavinash-nr Aug 18, 2025
467287f
Update security-scan.yml
aavinash-nr Aug 18, 2025
cb0dbc5
Update security-scan.yml
aavinash-nr Aug 18, 2025
f2a950f
Update security-scan.yml
aavinash-nr Aug 18, 2025
d24b615
Update security-scan.yml
aavinash-nr Aug 18, 2025
060e4ed
Update security-scan.yml
aavinash-nr Aug 18, 2025
22331f5
Update security-scan.yml
aavinash-nr Aug 25, 2025
3037fda
Update security-scan.yml
aavinash-nr Aug 25, 2025
3e648e9
Update security-scan.yml
aavinash-nr Aug 25, 2025
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
156 changes: 156 additions & 0 deletions .github/workflows/security-scan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
name: Security Scan with Trivy CLI

on:
push:
branches:
- main
- dev
pull_request:
branches:
- main
- dev

permissions:
contents: write
security-events: write
pull-requests: write

jobs:
scan-fs:
name: Scan Go Dependencies (FS)
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: "1.23.7"
cache-dependency-path: go.sum

- name: Download Go modules
run: go mod download

- name: Install Trivy
run: |
# This script installs the latest version of Trivy.
# See https://aquasecurity.github.io/trivy/v0.53/getting-started/installation/
sudo apt-get install wget apt-transport-https gnupg lsb-release -y
wget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key | gpg --dearmor | sudo tee /usr/share/keyrings/trivy.gpg > /dev/null
echo "deb [signed-by=/usr/share/keyrings/trivy.gpg] https://aquasecurity.github.io/trivy-repo/deb $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/trivy.list
sudo apt-get update
sudo apt-get install trivy -y

- name: 🛑 Scan filesystem for vulnerabilities (Blocker)
id: fs_scan_blocker
continue-on-error: true
run: |
trivy fs \
--scanners vuln \
--dependency-tree \
--exit-code 1 \
--severity "CRITICAL,HIGH,MEDIUM,LOW,UNKNOWN" \
--ignore-unfixed \
--skip-dirs "examples" \
.

- name: Generate report for PR comment
if: steps.fs_scan_blocker.outcome == 'failure'
run: |
# Run the same scan, but with exit-code 0 so it doesn't fail.
# Redirect the table output to a file for the PR comment.
trivy fs \
--scanners vuln \
--dependency-tree \
--exit-code 0 \
--severity "CRITICAL,HIGH,MEDIUM,LOW,UNKNOWN" \
--ignore-unfixed \
--format table \
--skip-dirs "examples" \
. > trivy-fs-comment-report.txt

- name: Post vulnerability report on PR
if: steps.fs_scan_blocker.outcome == 'failure' && github.event_name == 'pull_request'
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.pull_request.number }}
body-file: trivy-fs-comment-report.txt
edit-mode: replace

- name: Fail job if vulnerabilities were found
if: steps.fs_scan_blocker.outcome == 'failure'
run: |
echo "Failing the job due to filesystem vulnerabilities."
exit 1

scan-image:
name: Scan Docker Images
runs-on: ubuntu-latest
needs: scan-fs
strategy:
fail-fast: false
matrix:
arch: [amd64, arm64]
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up QEMU and Docker Buildx
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build Docker image
run: |
docker build --build-arg TARGETARCH=${{ matrix.arch }} \
--platform linux/${{ matrix.arch }} \
-t newrelic-lambda-extension:${{ github.sha }}-${{ matrix.arch }} .

- name: Install Trivy
run: |
sudo apt-get install wget apt-transport-https gnupg lsb-release -y
wget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key | gpg --dearmor | sudo tee /usr/share/keyrings/trivy.gpg > /dev/null
echo "deb [signed-by=/usr/share/keyrings/trivy.gpg] https://aquasecurity.github.io/trivy-repo/deb $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/trivy.list
sudo apt-get update
sudo apt-get install trivy -y

- name: 🛑 Scan image for vulnerabilities (Blocker)
id: image_scan_blocker
continue-on-error: true
run: |
trivy image \
--scanners vuln \
--dependency-tree \
--exit-code 1 \
--severity "CRITICAL,HIGH,MEDIUM,LOW,UNKNOWN" \
--ignore-unfixed \
--format table \
newrelic-lambda-extension:${{ github.sha }}-${{ matrix.arch }}

- name: Generate report for PR comment
if: steps.image_scan_blocker.outcome == 'failure'
run: |
# Run the same scan, but with exit-code 0 and redirect output to a file.
trivy image \
--scanners vuln \
--dependency-tree \
--exit-code 0 \
--severity "CRITICAL,HIGH,MEDIUM,LOW,UNKNOWN" \
--ignore-unfixed \
--format table \
newrelic-lambda-extension:${{ github.sha }}-${{ matrix.arch }} > trivy-image-comment-report.txt

- name: Post vulnerability report on PR
if: steps.image_scan_blocker.outcome == 'failure' && github.event_name == 'pull_request'
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.pull_request.number }}
body-file: 'trivy-image-comment-report.txt'
edit-mode: replace

- name: Fail job if vulnerabilities were found
if: steps.image_scan_blocker.outcome == 'failure'
run: |
echo "Failing the job due to image vulnerabilities in ${{ matrix.arch }} build."
exit 1
30 changes: 30 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
FROM golang:1.23-alpine AS builder

ARG TARGETARCH

RUN apk add --no-cache make git

WORKDIR /app

COPY go.mod go.sum ./

RUN go mod download

COPY . .

RUN if [ "${TARGETARCH}" = "amd64" ]; then \
make build-for-scan-x86_64; \
elif [ "${TARGETARCH}" = "arm64" ]; then \
make build-for-scan-arm64; \
else \
echo "Unsupported architecture: ${TARGETARCH}" && exit 1; \
fi

FROM alpine:3.20

# It's good practice to add ca-certificates for any potential HTTPS communication.
RUN apk add --no-cache ca-certificates

WORKDIR /opt

COPY --from=builder /app/extensions .
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ clean:
rm -f /tmp/newrelic-lambda-extension.x86_64.zip
rm -f /tmp/newrelic-lambda-extension.arm64.zip

# New target for building x86_64 without stripping for security scans
build-for-scan-x86_64: clean
env GOARCH=amd64 GOOS=linux CGO_ENABLED=0 go build -o ./extensions/newrelic-lambda-extension

# New target for building arm64 without stripping for security scans
build-for-scan-arm64: clean
env GOARCH=arm64 GOOS=linux CGO_ENABLED=0 go build -o ./extensions/newrelic-lambda-extension

dist-x86_64: clean
env GOARCH=amd64 GOOS=linux CGO_ENABLED=0 go build -ldflags="-s -w" -o ./extensions/newrelic-lambda-extension
touch preview-extensions-ggqizro707
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module github.com/newrelic/newrelic-lambda-extension

go 1.23.8
go 1.23.7


// Go experimental release X25519Kyber768Draft00 is causing issue with AWS Network Firewall
godebug tlskyber=0
Expand Down
Loading