Skip to content

Commit e8e6268

Browse files
authored
add Dockerfile CVE check, update vulnerability scanning to use trivy action (#941)
* update vulnerability scanning to use trivy action * Update Dockerfile * update setuptools * test k8s/helm securityContext * update setuptools and use pip3 * move to python:3.10-slim-buster * test Dockerfile with apt upgrade * minor doc fixes
1 parent fc5bda8 commit e8e6268

11 files changed

+52
-38
lines changed

.github/workflows/vulnerabilities.yml

+24-18
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,33 @@ on:
1414
- released
1515

1616
jobs:
17-
clone:
18-
runs-on: ubuntu-22.04
19-
steps:
20-
- name: Setup Python
21-
uses: actions/setup-python@v1
22-
with:
23-
python-version: '3.10'
24-
architecture: x64
25-
- name: Checkout pycsw
26-
uses: actions/checkout@master
2717

2818
vulnerabilities:
29-
needs: [clone]
3019
runs-on: ubuntu-22.04
31-
20+
defaults:
21+
run:
22+
working-directory: .
3223
steps:
24+
- name: Checkout pycsw
25+
uses: actions/checkout@v4
3326
- name: Scan vulnerabilities with trivy
27+
uses: aquasecurity/trivy-action@master
28+
with:
29+
scan-type: fs
30+
exit-code: 1
31+
ignore-unfixed: true
32+
severity: CRITICAL,HIGH
33+
scanners: vuln,misconfig,secret
34+
scan-ref: .
35+
- name: Build locally the image from Dockerfile
3436
run: |
35-
sudo apt-get install -y wget apt-transport-https gnupg lsb-release
36-
wget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key | gpg --dearmor | sudo tee /usr/share/keyrings/trivy.gpg > /dev/null
37-
echo "deb [signed-by=/usr/share/keyrings/trivy.gpg] https://aquasecurity.github.io/trivy-repo/deb $(lsb_release -sc) main" | sudo tee -a /etc/apt/sources.list.d/trivy.list
38-
sudo apt-get update
39-
sudo apt-get install -y trivy
40-
trivy --exit-code 1 fs --scanners vuln,misconfig,secret --severity HIGH,CRITICAL --ignore-unfixed .
37+
docker buildx build -t ${{ github.repository }}:${{ github.sha }} --platform linux/amd64 --no-cache -f Dockerfile .
38+
- name: Scan locally built Docker image for vulnerabilities with trivy
39+
uses: aquasecurity/trivy-action@master
40+
with:
41+
scan-type: image
42+
exit-code: 1
43+
ignore-unfixed: true
44+
severity: CRITICAL,HIGH
45+
vuln-type: os,library
46+
image-ref: '${{ github.repository }}:${{ github.sha }}'

Dockerfile

+9-8
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,18 @@
3636
#
3737
# =================================================================
3838

39-
FROM python:3.8-slim-buster
39+
FROM python:3.10-slim-buster
4040
4141

4242
# Build arguments
4343
# add "--build-arg BUILD_DEV_IMAGE=true" to Docker build command when building with test/doc tools
4444

4545
ARG BUILD_DEV_IMAGE="false"
4646

47-
RUN apt-get update && apt-get install --yes \
48-
ca-certificates libexpat1 \
49-
&& rm -rf /var/lib/apt/lists/*
47+
RUN apt-get update --yes && \
48+
apt-get upgrade --yes && \
49+
apt-get install --yes --no-install-recommends ca-certificates libexpat1 python3-setuptools && \
50+
rm -rf /var/lib/apt/lists/*
5051

5152
RUN adduser --uid 1000 --gecos '' --disabled-password pycsw
5253

@@ -63,19 +64,19 @@ COPY --chown=pycsw \
6364
requirements-dev.txt \
6465
./
6566

66-
RUN pip install -U pip && \
67-
python3 -m pip install \
67+
RUN pip3 install -U pip setuptools && \
68+
pip3 install \
6869
--requirement requirements.txt \
6970
--requirement requirements-standalone.txt \
7071
psycopg2-binary gunicorn \
71-
&& if [ "$BUILD_DEV_IMAGE" = "true" ] ; then python3 -m pip install -r requirements-dev.txt; fi
72+
&& if [ "$BUILD_DEV_IMAGE" = "true" ] ; then python3 -m pip3 install -r requirements-dev.txt; fi
7273

7374
COPY --chown=pycsw . .
7475

7576
COPY docker/pycsw.yml ${PYCSW_CONFIG}
7677
COPY docker/entrypoint.py /usr/local/bin/entrypoint.py
7778

78-
RUN python3 -m pip install --editable .
79+
RUN pip3 install --editable .
7980

8081
WORKDIR /home/pycsw
8182

docker/helm/templates/db-statefulset.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ spec:
3636
volumeMounts:
3737
- mountPath: {{ .Values.db.volume_path }}
3838
name: {{ .Values.db.volume_name }}
39+
securityContext:
40+
readOnlyRootFilesystem: true
3941
restartPolicy: Always
4042
volumeClaimTemplates:
4143
- metadata:

docker/helm/templates/pycsw-deployment.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ spec:
3131
volumeMounts:
3232
- mountPath: {{ .Values.pycsw.volume_path }}
3333
name: {{ .Values.pycsw.volume_name }}
34+
securityContext:
35+
readOnlyRootFilesystem: true
3436
restartPolicy: Always
3537
volumes:
3638
- name: {{ .Values.pycsw.volume_name }}

docker/kubernetes/db-deployment.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ spec:
3434
volumeMounts:
3535
- mountPath: /var/lib/postgresql/data/pgdata
3636
name: db-data
37+
securityContext:
38+
readOnlyRootFilesystem: true
3739
restartPolicy: Always
3840
volumes:
3941
- name: db-data

docker/kubernetes/pycsw-deployment.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ spec:
3030
volumeMounts:
3131
- mountPath: /etc/pycsw
3232
name: pycsw-config
33+
securityContext:
34+
readOnlyRootFilesystem: true
3335
restartPolicy: Always
3436
volumes:
3537
- name: pycsw-config

docs/docker.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ The following instructions set up a fully working development environment::
165165

166166
.. note::
167167

168-
Please note that the pycsw image only uses python 3.8 and that it also does
168+
The pycsw image uses a specific Python version and does
169169
not install pycsw in editable mode. As such it is not possible to
170170
use ``tox``.
171171

docs/installation.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,9 @@ WSGI mode, use ``pycsw/wsgi.py`` in your WSGI server environment.
221221

222222
.. note::
223223

224-
``mod_wsgi`` supports only the version of python it was compiled with. If the target server
225-
already supports WSGI applications, pycsw will need to use the same python version.
226-
`WSGIDaemonProcess`_ provides a ``python-path`` directive that may allow a virtualenv created from the python version ``mod_wsgi`` uses.
224+
``mod_wsgi`` supports only the version of Python it was compiled with. If the target server
225+
already supports WSGI applications, pycsw will need to use the same Python version.
226+
`WSGIDaemonProcess`_ provides a ``python-path`` directive that may allow a virtualenv created from the Python version ``mod_wsgi`` uses.
227227

228228
Below is an example of configuring with Apache:
229229

docs/testing.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ Examples:
289289
.. code:: bash
290290
291291
# install tox on your system
292-
sudo pip install tox
292+
sudo pip3 install tox
293293
294294
# run all tests on multiple Python versions against all databases,
295295
# with default arguments

setup.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def get_package_version():
8585
'fgdc',
8686
'dif',
8787
'ebrim',
88-
'inspire',
88+
'inspire'
8989
]),
9090
author='Tom Kralidis',
9191
author_email='[email protected]',
@@ -97,7 +97,7 @@ def get_package_version():
9797
include_package_data=True,
9898
entry_points={
9999
'console_scripts': [
100-
'pycsw-admin.py=pycsw.core.admin:cli',
100+
'pycsw-admin.py=pycsw.core.admin:cli'
101101
]
102102
},
103103
classifiers=[
@@ -108,9 +108,8 @@ def get_package_version():
108108
'License :: OSI Approved :: MIT License',
109109
'Operating System :: OS Independent',
110110
'Programming Language :: Python',
111-
'Programming Language :: Python :: 3.6',
112-
'Programming Language :: Python :: 3.7',
113-
'Programming Language :: Python :: 3.8',
114-
'Topic :: Scientific/Engineering :: GIS',
111+
'Programming Language :: Python :: 3.10',
112+
'Programming Language :: Python :: 3.11',
113+
'Topic :: Scientific/Engineering :: GIS'
115114
]
116115
)

tox.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Tox (http://tox.testrun.org/) is a tool for running tests
22
# in multiple virtualenvs. This configuration file will run the
3-
# test suite on all supported python versions. To use it, "pip install tox"
3+
# test suite on all supported python versions. To use it, "pip3 install tox"
44
# and then run "tox" from this directory.
55

66
[tox]

0 commit comments

Comments
 (0)