Skip to content

Commit 6569353

Browse files
authored
Merge pull request #2846 from tarlepp/chore(ci)/trivy
Chore(ci) - Add Trivy to scan Docker image
2 parents b0adde3 + 597f47a commit 6569353

File tree

4 files changed

+41
-25
lines changed

4 files changed

+41
-25
lines changed

.github/workflows/main.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,3 +360,13 @@ jobs:
360360

361361
- name: Build the Docker image
362362
run: docker build . --file Dockerfile --tag symfony-flex-backend:${{ steps.vars.outputs.DOCKER_TAG }}
363+
364+
- name: Scan Docker image with Trivy vulnerability scanner
365+
uses: aquasecurity/trivy-action@0.24.0
366+
with:
367+
image-ref: 'symfony-flex-backend:${{ steps.vars.outputs.DOCKER_TAG }}'
368+
format: 'table'
369+
exit-code: '1'
370+
ignore-unfixed: true
371+
vuln-type: 'os,library'
372+
severity: 'CRITICAL,HIGH'

Dockerfile

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# syntax=docker/dockerfile:1.7-labs
12
FROM php:8.3.10-fpm
23

34
ENV APP_ENV prod
@@ -30,6 +31,14 @@ RUN install-php-extensions \
3031
pdo_mysql \
3132
zip
3233

34+
# Install security updates
35+
RUN apt-get update \
36+
&& apt-get install -y \
37+
debsecan \
38+
&& apt-get install --no-install-recommends -y \
39+
$(debsecan --suite bookworm --format packages --only-fixed) \
40+
&& rm -rf /var/lib/apt/lists/*
41+
3342
# Copy the Composer PHAR from the Composer image into the PHP image
3443
COPY --from=composer:2.7.7 /usr/bin/composer /usr/bin/composer
3544

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

3948
WORKDIR /app
4049

41-
COPY . /app
50+
COPY --exclude=./docker/* . /app
4251
COPY ./docker/php/php.ini /usr/local/etc/php/php.ini
4352
COPY ./docker/php/www.conf /usr/local/etc/php-fpm.d/www.conf
4453

4554
RUN chmod +x /app/bin/console
4655
RUN chmod +x /app/docker-entrypoint.sh
4756
RUN chmod +x /usr/bin/composer
4857

49-
RUN curl -s https://api.github.com/repos/fabpot/local-php-security-checker/releases/latest | \
50-
grep -E "browser_download_url(.+)linux_amd64" | \
51-
cut -d : -f 2,3 | \
52-
tr -d \" | \
53-
xargs -I{} wget -O local-php-security-checker {} \
54-
&& mv local-php-security-checker /usr/bin/local-php-security-checker \
55-
&& chmod +x /usr/bin/local-php-security-checker
56-
5758
RUN rm -rf /app/var \
5859
&& mkdir -p /app/var \
5960
&& rm -rf /app/public/check.php \
60-
&& php -d memory_limit=-1 /usr/bin/composer install --no-dev --optimize-autoloader
61+
&& php -d memory_limit=-1 /usr/bin/composer install --no-dev --optimize-autoloader \
62+
&& php /usr/bin/composer audit
6163

6264
EXPOSE 9000
6365

Dockerfile_dev

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ RUN install-php-extensions \
6969
xdebug \
7070
zip
7171

72+
# Install security updates
73+
RUN apt-get update \
74+
&& apt-get install -y \
75+
debsecan \
76+
&& apt-get install --no-install-recommends -y \
77+
$(debsecan --suite bookworm --format packages --only-fixed) \
78+
&& rm -rf /var/lib/apt/lists/*
79+
7280
# Copy the Composer PHAR from the Composer image into the PHP image
7381
COPY --from=composer:2.7.7 /usr/bin/composer /usr/bin/composer
7482

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

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

88-
RUN curl -s https://api.github.com/repos/fabpot/local-php-security-checker/releases/latest | \
89-
grep -E "browser_download_url(.+)linux_amd64" | \
90-
cut -d : -f 2,3 | \
91-
tr -d \" | \
92-
xargs -I{} wget -O local-php-security-checker {} \
93-
&& mv local-php-security-checker /usr/bin/local-php-security-checker \
94-
&& chmod +x /usr/bin/local-php-security-checker
95-
9696
RUN groupadd --gid ${HOST_GID} dev \
9797
&& useradd \
9898
-p $(perl -e 'print crypt($ARGV[0], "password")' 'dev') \

docker-entrypoint-dev.sh

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ set -e
66
# 0) Basic linting of current JSON configuration file
77
# 1) Export needed environment variables
88
# 2) Install all dependencies
9-
# 3) Generate JWT encryption keys
10-
# 4) Create database if it not exists yet
11-
# 5) Run possible migrations, so that database is always up to date
12-
# 6) Add needed symfony console autocomplete for bash
9+
# 3) Check if there are any security issues in dependencies
10+
# 4) Generate JWT encryption keys
11+
# 5) Create database if it not exists yet
12+
# 6) Run possible migrations, so that database is always up to date
13+
# 7) Add needed symfony console autocomplete for bash
1314
#
1415

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

2728
# Step 3
28-
make generate-jwt-keys
29+
composer audit
2930

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

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

3637
# Step 6
38+
./bin/console doctrine:migrations:migrate --no-interaction --allow-no-migration --all-or-nothing
39+
40+
# Step 7
3741
./bin/console completion bash >> /home/dev/.bashrc
3842

3943
exec "$@"

0 commit comments

Comments
 (0)