Skip to content

Commit e310d2a

Browse files
shahidhkclaudeGavinRay97
authored
fix vulnerabilities (#62)
* fix vulnerabilities * change to ubuntu image for vuln fixes * add scanning * add trivy scan with security agent upload and fail on critical/high vulns Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * use non-root user in dockerfiles Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Allow useradd bin to choose a UID for non-root --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: Gavin Ray <ray.gavin97@gmail.com>
1 parent 99e19e8 commit e310d2a

3 files changed

Lines changed: 67 additions & 6 deletions

File tree

.github/workflows/ndc-nodejs-lambda-connector.yaml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,49 @@ jobs:
119119
tags: ${{ steps.docker-metadata.outputs.tags }}
120120
labels: ${{ steps.docker-metadata.outputs.labels }}
121121

122+
- name: Build docker image for scanning
123+
uses: docker/build-push-action@v6
124+
with:
125+
context: .
126+
build-args: |
127+
CONNECTOR_VERSION=${{ steps.get-npm-package-version.outputs.package_version }}
128+
load: true
129+
tags: ${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_IMAGE_NAME }}:scan
130+
131+
- name: Run Trivy vulnerability scanner (json output)
132+
uses: aquasecurity/trivy-action@0.32.0
133+
with:
134+
image-ref: ${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_IMAGE_NAME }}:scan
135+
format: json
136+
output: trivy-results.json
137+
scanners: vuln
138+
139+
- name: Upload Trivy scan results to Security Agent
140+
if: always()
141+
uses: hasura/security-agent-tools/upload-file@v1
142+
with:
143+
file_path: trivy-results.json
144+
security_agent_api_key: ${{ secrets.SECURITY_AGENT_API_KEY }}
145+
tags: |
146+
service=ndc-nodejs-lambda
147+
source_code_path=.
148+
docker_file_path=Dockerfile
149+
scanner=trivy
150+
image_name=${{ steps.docker-metadata.outputs.tags }}
151+
product_domain=hasura-ddn-data-plane
152+
team=engine
153+
154+
- name: Fail build on High/Critical Vulnerabilities
155+
uses: aquasecurity/trivy-action@0.32.0
156+
with:
157+
skip-setup-trivy: true
158+
image-ref: ${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_IMAGE_NAME }}:scan
159+
format: table
160+
severity: CRITICAL,HIGH
161+
scanners: vuln
162+
ignore-unfixed: true
163+
exit-code: 1
164+
122165
- name: Push docker image
123166
uses: docker/build-push-action@v6
124167
if: ${{ startsWith(github.ref, 'refs/tags/v') }}

Dockerfile

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
1-
FROM node:20-alpine
1+
FROM ubuntu:noble-20260113
22
ARG CONNECTOR_VERSION
33

4-
RUN npm update -g npm
5-
RUN apk add bash jq curl
4+
RUN apt-get update && apt-get install -y \
5+
curl \
6+
bash \
7+
jq \
8+
ca-certificates \
9+
gnupg \
10+
&& mkdir -p /etc/apt/keyrings \
11+
&& curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg \
12+
&& echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list \
13+
&& apt-get update \
14+
&& apt-get install -y nodejs \
15+
&& npm update -g npm \
16+
&& apt-get clean \
17+
&& rm -rf /var/lib/apt/lists/*
618

719
COPY /docker /scripts
820
COPY /connector-definition/scripts/upgrade-connector.sh /scripts/upgrade-connector.sh
@@ -12,6 +24,12 @@ RUN echo ${CONNECTOR_VERSION} > /scripts/CONNECTOR_VERSION
1224
COPY /functions /functions
1325
RUN /scripts/package-restore.sh
1426

27+
# Create non-root user, let useradd pick a unique UID
28+
RUN useradd -m -s /bin/bash hasura \
29+
&& chown -R hasura:hasura /scripts /functions
30+
31+
USER hasura
32+
1533
EXPOSE 8080
1634

1735
HEALTHCHECK --interval=5s --timeout=10s --start-period=1s --retries=3 CMD [ "sh", "-c", "exec curl -f http://localhost:${HASURA_CONNECTOR_PORT:-8080}/health" ]

connector-definition/Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
FROM ghcr.io/hasura/ndc-nodejs-lambda:v{{VERSION}}
22

3-
COPY package-lock.json package.json /functions/
3+
COPY --chown=hasura:hasura package-lock.json package.json /functions/
44

55
WORKDIR /functions
6-
RUN --mount=type=cache,target=/root/.npm \
6+
RUN --mount=type=cache,target=/home/hasura/.npm,uid=1000,gid=1000 \
77
npm ci
88

9-
COPY ./ /functions
9+
COPY --chown=hasura:hasura ./ /functions

0 commit comments

Comments
 (0)