diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d305594..76028e2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -27,18 +27,18 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Install cosign if: github.event_name != 'pull_request' - uses: sigstore/cosign-installer@main + uses: sigstore/cosign-installer@v3 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 + uses: docker/setup-buildx-action@v3 - name: Login to registry if: github.event_name != 'pull_request' - uses: docker/login-action@v2 + uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} username: ${{ github.repository_owner }} @@ -46,7 +46,7 @@ jobs: - name: Set Docker metadata id: meta - uses: docker/metadata-action@v4 + uses: docker/metadata-action@v5 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} tags: | @@ -67,3 +67,23 @@ jobs: env: COSIGN_EXPERIMENTAL: "true" TAGS: ${{ steps.meta.outputs.tags }} + + scan: + name: Scan current image & report results + needs: build + runs-on: "ubuntu-latest" + steps: + - name: Run Trivy vulnerability scanner + uses: aquasecurity/trivy-action@master + with: + image-ref: 'ghcr.io/tommytran732/matrix.to' + format: 'template' + template: '@/contrib/sarif.tpl' + output: 'trivy-results.sarif' + severity: 'CRITICAL,HIGH' + vuln-type: "os" + + - name: Upload Trivy scan results to GitHub Security tab + uses: github/codeql-action/upload-sarif@v2 + with: + sarif_file: 'trivy-results.sarif' \ No newline at end of file diff --git a/.github/workflows/scan.yml b/.github/workflows/scan.yml new file mode 100644 index 0000000..1e4374c --- /dev/null +++ b/.github/workflows/scan.yml @@ -0,0 +1,27 @@ +name: Scan + +on: + workflow_dispatch: + schedule: + # Scan the image regularly (once a day) + - cron: '0 23 * * *' + +jobs: + scan: + name: Scan current image & report results + runs-on: "ubuntu-latest" + steps: + - name: Run Trivy vulnerability scanner + uses: aquasecurity/trivy-action@master + with: + image-ref: 'ghcr.io/tommytran732/matrix.to' + format: 'template' + template: '@/contrib/sarif.tpl' + output: 'trivy-results.sarif' + severity: 'CRITICAL,HIGH' + vuln-type: "os" + + - name: Upload Trivy scan results to GitHub Security tab + uses: github/codeql-action/upload-sarif@v3 + with: + sarif_file: 'trivy-results.sarif' \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 55deaa5..ef97cbe 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,25 @@ +ARG HARDENED_MALLOC_VERSION=2024052100 + +### Build Hardened Malloc +FROM alpine:latest as hmalloc-builder + +ARG HARDENED_MALLOC_VERSION +ARG CONFIG_NATIVE=false +ARG VARIANT=default + +RUN apk -U upgrade \ + && apk --no-cache add build-base git gnupg openssh-keygen + +RUN cd /tmp \ + && git clone --depth 1 --branch ${HARDENED_MALLOC_VERSION} https://github.com/GrapheneOS/hardened_malloc \ + && cd hardened_malloc \ + && wget -q https://grapheneos.org/allowed_signers -O grapheneos_allowed_signers \ + && git config gpg.ssh.allowedSignersFile grapheneos_allowed_signers \ + && git verify-tag $(git describe --tags) \ + && make CONFIG_NATIVE=${CONFIG_NATIVE} VARIANT=${VARIANT} + +### Build Production + FROM node:alpine LABEL maintainer="Thien Tran contact@tommytran.io" @@ -6,8 +28,8 @@ ARG UID=992 ARG GID=992 RUN apk -U upgrade \ - && apk --no-cache add git \ - && adduser -g ${GID} -u ${UID} --disabled-password --gecos "" matrix-to + && apk --no-cache add git \ + && adduser -g ${GID} -u ${UID} --disabled-password --gecos "" matrix-to USER matrix-to @@ -20,9 +42,13 @@ COPY element.patch /home/matrix-to/matrix.to WORKDIR /home/matrix-to/matrix.to RUN git apply /home/matrix-to/matrix.to/element.patch \ - && rm -rf .git \ - && yarn \ - && yarn build + && rm -rf .git \ + && yarn \ + && yarn build + +COPY --from=hmalloc-builder /tmp/hardened_malloc/out/libhardened_malloc.so /usr/local/lib/ + +ENV LD_PRELOAD="/usr/local/lib/libhardened_malloc.so" EXPOSE 5000