Skip to content

Chore(ci) - Add Trivy to scan Docker image #2846

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 29 commits into from
Sep 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
7caed3d
Updated PHP, nvm, Node.js and mlocati/php-extension-installer versions
tarlepp Aug 23, 2024
e0649cb
IDE settings
tarlepp Aug 23, 2024
3ccc129
Chore(CI) - Added Trivy to scan Docker image
tarlepp Aug 29, 2024
7e164b1
Added `docker` directory to Docker ignore list
tarlepp Aug 29, 2024
abccf67
Use specific ignore directory
tarlepp Aug 29, 2024
a939895
Remove `docker` folder in build process
tarlepp Aug 29, 2024
50739f0
Add some debug
tarlepp Aug 29, 2024
c788019
Hmm, something weird is happeing here
tarlepp Aug 29, 2024
5b0902f
Another try
tarlepp Aug 29, 2024
5eccb53
Typo fix
tarlepp Aug 29, 2024
d5f888a
Yet another try
tarlepp Aug 29, 2024
69abb1a
Another try
tarlepp Aug 29, 2024
b0adde3
Merge pull request #2845 from tarlepp/chore(env)/php-update
tarlepp Aug 31, 2024
9743313
Chore(CI) - Added Trivy to scan Docker image
tarlepp Aug 29, 2024
018b4dd
Added `docker` directory to Docker ignore list
tarlepp Aug 29, 2024
aa8b96c
Use specific ignore directory
tarlepp Aug 29, 2024
bfdb45d
Remove `docker` folder in build process
tarlepp Aug 29, 2024
9596189
Add some debug
tarlepp Aug 29, 2024
2bd61ef
Hmm, something weird is happeing here
tarlepp Aug 29, 2024
f4ca11a
Another try
tarlepp Aug 29, 2024
558a1ef
Typo fix
tarlepp Aug 29, 2024
9c8a7d8
Yet another try
tarlepp Aug 29, 2024
fc371e6
Another try
tarlepp Aug 29, 2024
16ada13
Use `composer audit`
tarlepp Aug 31, 2024
0b536be
Merge remote-tracking branch 'origin/chore(ci)/trivy' into chore(ci)/…
tarlepp Aug 31, 2024
50e4e70
Force to new Docker syntax
tarlepp Aug 31, 2024
7edabf6
Remove obsolete `rm` command
tarlepp Aug 31, 2024
34b335e
Apply available security updates
tarlepp Sep 4, 2024
597f47a
Fixed indentations
tarlepp Sep 4, 2024
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
10 changes: 10 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -360,3 +360,13 @@ jobs:

- name: Build the Docker image
run: docker build . --file Dockerfile --tag symfony-flex-backend:${{ steps.vars.outputs.DOCKER_TAG }}

- name: Scan Docker image with Trivy vulnerability scanner
uses: aquasecurity/trivy-action@0.24.0
with:
image-ref: 'symfony-flex-backend:${{ steps.vars.outputs.DOCKER_TAG }}'
format: 'table'
exit-code: '1'
ignore-unfixed: true
vuln-type: 'os,library'
severity: 'CRITICAL,HIGH'
14 changes: 0 additions & 14 deletions .idea/php-test-framework.xml

This file was deleted.

4 changes: 2 additions & 2 deletions .idea/php.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/symfony-flex-backend.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 14 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FROM php:8.3.9-fpm
# syntax=docker/dockerfile:1.7-labs
FROM php:8.3.10-fpm

ENV APP_ENV prod
ENV APP_DEBUG 0
Expand All @@ -18,7 +19,7 @@ RUN apt-get update \
&& rm -rf /var/lib/apt/lists/*

# Copy the install-php-extensions (Easily install PHP extension in official PHP Docker containers)
COPY --from=mlocati/php-extension-installer:2.2.18 /usr/bin/install-php-extensions /usr/local/bin/
COPY --from=mlocati/php-extension-installer:2.4.0 /usr/bin/install-php-extensions /usr/local/bin/

# Install and enable all necessary PHP extensions
RUN install-php-extensions \
Expand All @@ -30,6 +31,14 @@ RUN install-php-extensions \
pdo_mysql \
zip

# Install security updates
RUN apt-get update \
&& apt-get install -y \
debsecan \
&& apt-get install --no-install-recommends -y \
$(debsecan --suite bookworm --format packages --only-fixed) \
&& rm -rf /var/lib/apt/lists/*

# Copy the Composer PHAR from the Composer image into the PHP image
COPY --from=composer:2.7.7 /usr/bin/composer /usr/bin/composer

Expand All @@ -38,26 +47,19 @@ RUN composer completion bash > /etc/bash_completion.d/composer

WORKDIR /app

COPY . /app
COPY --exclude=./docker/* . /app
COPY ./docker/php/php.ini /usr/local/etc/php/php.ini
COPY ./docker/php/www.conf /usr/local/etc/php-fpm.d/www.conf

RUN chmod +x /app/bin/console
RUN chmod +x /app/docker-entrypoint.sh
RUN chmod +x /usr/bin/composer

RUN curl -s https://api.github.com/repos/fabpot/local-php-security-checker/releases/latest | \
grep -E "browser_download_url(.+)linux_amd64" | \
cut -d : -f 2,3 | \
tr -d \" | \
xargs -I{} wget -O local-php-security-checker {} \
&& mv local-php-security-checker /usr/bin/local-php-security-checker \
&& chmod +x /usr/bin/local-php-security-checker

RUN rm -rf /app/var \
&& mkdir -p /app/var \
&& rm -rf /app/public/check.php \
&& php -d memory_limit=-1 /usr/bin/composer install --no-dev --optimize-autoloader
&& php -d memory_limit=-1 /usr/bin/composer install --no-dev --optimize-autoloader \
&& php /usr/bin/composer audit

EXPOSE 9000

Expand Down
24 changes: 12 additions & 12 deletions Dockerfile_dev
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM php:8.3.9-fpm
FROM php:8.3.10-fpm

# Let's use bash as a default shell with login each time
SHELL ["/bin/bash", "--login", "-c"]
Expand All @@ -9,8 +9,8 @@ ARG HOST_GID

# Declare constants
ENV PATH "$PATH:/home/dev/.composer/vendor/bin:/app/vendor/bin"
ENV NVM_VERSION v0.39.7
ENV NODE_VERSION 22.4.0
ENV NVM_VERSION v0.40.0
ENV NODE_VERSION 22.7.0

# Update package list and install necessary libraries
RUN apt-get update \
Expand Down Expand Up @@ -56,7 +56,7 @@ ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8

# Copy the install-php-extensions (Easily install PHP extension in official PHP Docker containers)
COPY --from=mlocati/php-extension-installer:2.2.18 /usr/bin/install-php-extensions /usr/local/bin/
COPY --from=mlocati/php-extension-installer:2.4.0 /usr/bin/install-php-extensions /usr/local/bin/

# Enable all necessary PHP packages
RUN install-php-extensions \
Expand All @@ -69,6 +69,14 @@ RUN install-php-extensions \
xdebug \
zip

# Install security updates
RUN apt-get update \
&& apt-get install -y \
debsecan \
&& apt-get install --no-install-recommends -y \
$(debsecan --suite bookworm --format packages --only-fixed) \
&& rm -rf /var/lib/apt/lists/*

# Copy the Composer PHAR from the Composer image into the PHP image
COPY --from=composer:2.7.7 /usr/bin/composer /usr/bin/composer

Expand All @@ -85,14 +93,6 @@ COPY ./docker/php/www-dev.conf /usr/local/etc/php-fpm.d/www.conf

RUN chmod -R o+s+w /usr/local/etc/php

RUN curl -s https://api.github.com/repos/fabpot/local-php-security-checker/releases/latest | \
grep -E "browser_download_url(.+)linux_amd64" | \
cut -d : -f 2,3 | \
tr -d \" | \
xargs -I{} wget -O local-php-security-checker {} \
&& mv local-php-security-checker /usr/bin/local-php-security-checker \
&& chmod +x /usr/bin/local-php-security-checker

RUN groupadd --gid ${HOST_GID} dev \
&& useradd \
-p $(perl -e 'print crypt($ARGV[0], "password")' 'dev') \
Expand Down
18 changes: 11 additions & 7 deletions docker-entrypoint-dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ set -e
# 0) Basic linting of current JSON configuration file
# 1) Export needed environment variables
# 2) Install all dependencies
# 3) Generate JWT encryption keys
# 4) Create database if it not exists yet
# 5) Run possible migrations, so that database is always up to date
# 6) Add needed symfony console autocomplete for bash
# 3) Check if there are any security issues in dependencies
# 4) Generate JWT encryption keys
# 5) Create database if it not exists yet
# 6) Run possible migrations, so that database is always up to date
# 7) Add needed symfony console autocomplete for bash
#

# Step 0
Expand All @@ -25,15 +26,18 @@ export XDEBUG_SESSION=PHPSTORM
COMPOSER_MEMORY_LIMIT=-1 composer install --optimize-autoloader

# Step 3
make generate-jwt-keys
composer audit

# Step 4
./bin/console doctrine:database:create --no-interaction --if-not-exists
make generate-jwt-keys

# Step 5
./bin/console doctrine:migrations:migrate --no-interaction --allow-no-migration --all-or-nothing
./bin/console doctrine:database:create --no-interaction --if-not-exists

# Step 6
./bin/console doctrine:migrations:migrate --no-interaction --allow-no-migration --all-or-nothing

# Step 7
./bin/console completion bash >> /home/dev/.bashrc

exec "$@"
Loading