Skip to content
Snippets Groups Projects
Commit a57cbc44 authored by andreas.abel's avatar andreas.abel Committed by mergify-bot
Browse files

Re #7777 #7778: check requirements.txt for security advisory

There is a new make file,

    doc/Makefile

that defines these goals:

  - `check-requirements`:
    Check `requirements.txt` for security problems (CVEs) using `skjold`.
    This goal is intended for the "Users guide" CI.
    SKJOLD_GITHUB_API_TOKEN might have to be set if GITHUB_TOKEN is
    not in the environment, in order to access the GitHub GraphQL API.

  - `build-and-check-requirements`:
    Rebuild `requirements.txt` from `requirements.in` using `pip-compile`,
    and check with `check-requirements`.
    This goal is intended for manual invocation.

    It is invoked from the top Makefile via goal
    `users-guide-requirements`.

Alternatively, these goals could be coupled with the doc build
`make users-guide`.
However, since these goals require a couple of seconds to run, I think
it is annoying to call them on every build of the documentation.
parent 8760e3d3
No related branches found
No related tags found
No related merge requests found
...@@ -7,6 +7,9 @@ on: ...@@ -7,6 +7,9 @@ on:
branches: branches:
- master - master
paths: paths:
- 'doc/Makefile'
- 'doc/pyproject.toml'
- 'doc/requirements.in'
- 'doc/requirements.txt' - 'doc/requirements.txt'
- 'doc/*.inc' - 'doc/*.inc'
- 'doc/*.py' - 'doc/*.py'
...@@ -15,6 +18,9 @@ on: ...@@ -15,6 +18,9 @@ on:
- '.github/workflows/users-guide.yml' - '.github/workflows/users-guide.yml'
pull_request: pull_request:
paths: paths:
- 'doc/Makefile'
- 'doc/pyproject.toml'
- 'doc/requirements.in'
- 'doc/requirements.txt' - 'doc/requirements.txt'
- 'doc/*.inc' - 'doc/*.inc'
- 'doc/*.py' - 'doc/*.py'
...@@ -25,6 +31,10 @@ on: ...@@ -25,6 +31,10 @@ on:
types: types:
- created - created
defaults:
run:
shell: bash
jobs: jobs:
build: build:
if: | if: |
...@@ -59,3 +69,7 @@ jobs: ...@@ -59,3 +69,7 @@ jobs:
with: with:
name: users-guide-html name: users-guide-html
path: html/ path: html/
- name: Check security of requirements.txt
run: |
make SKJOLD_GITHUB_API_TOKEN=${{ secrets.GITHUB_TOKEN }} -C doc check-requirements
# trivial gitignore file
.cabal-sandbox/ .cabal-sandbox/
cabal.sandbox.config cabal.sandbox.config
cabal.project.local cabal.project.local
...@@ -15,7 +14,6 @@ dist-* ...@@ -15,7 +14,6 @@ dist-*
register.sh register.sh
./cabal.config ./cabal.config
cabal-tests.log cabal-tests.log
.python-sphinx-virtualenv/
/Cabal/dist/ /Cabal/dist/
/Cabal/tests/Setup /Cabal/tests/Setup
...@@ -68,6 +66,8 @@ register.sh ...@@ -68,6 +66,8 @@ register.sh
# python artifacts from documentation builds # python artifacts from documentation builds
*.pyc *.pyc
.python-sphinx-virtualenv/
/doc/.skjold_cache/
# macOS folder metadata # macOS folder metadata
.DS_Store .DS_Store
...@@ -76,4 +76,4 @@ register.sh ...@@ -76,4 +76,4 @@ register.sh
bench.html bench.html
# Emacs # Emacs
.projectile .projectile
\ No newline at end of file
...@@ -251,3 +251,12 @@ $(USERGUIDE_STAMP) : doc/*.rst ...@@ -251,3 +251,12 @@ $(USERGUIDE_STAMP) : doc/*.rst
.python-sphinx-virtualenv: .python-sphinx-virtualenv:
python3 -m venv .python-sphinx-virtualenv python3 -m venv .python-sphinx-virtualenv
(. ./.python-sphinx-virtualenv/bin/activate) (. ./.python-sphinx-virtualenv/bin/activate)
# This goal is intended for manual invocation, always rebuilds.
.PHONY: users-guide-requirements
users-guide-requirements: doc/requirements.txt
.PHONY: doc/requirements.txt
doc/requirements.txt: .python-sphinx-virtualenv
. .python-sphinx-virtualenv/bin/activate \
&& make -C doc build-and-check-requirements
# Build and safety-check requirements.txt
# skjold needs a personal github access token. This needs no permissions,
# it is only required to query the GitHub GraphQL API v4.
# See: https://pythonawesome.com/security-audit-python-project-dependencies-against-security-advisory-databases/
# We attempt to get it from the environment variable GITHUB_TOKEN.
# It can also be passed to this Makefile via either:
#
# make GITHUB_TOKEN=... (build-and-)check-requirements
# make SKJOLD_GITHUB_API_TOKEN=... (build-and-)check-requirements
#
#
SKJOLD_GITHUB_API_TOKEN=${GITHUB_TOKEN}
.PHONY: build-and-check-requirements
build-and-check-requirements: requirements.txt check-requirements
# Always rebuild requirements.txt
.PHONY: requirements.txt
# requirements.txt is generated from requirements.in
# via pip-compile included in the pip-tools package.
# See https://modelpredict.com/wht-requirements-txt-is-not-enough
requirements.txt: requirements.in
. ../.python-sphinx-virtualenv/bin/activate \
&& pip install pip-tools \
&& pip-compile requirements.in
# Check requirements.txt for security violations via skjold,
# configured in pyproject.toml.
# See: https://pythonawesome.com/security-audit-python-project-dependencies-against-security-advisory-databases/
.PHONY: check-requirements
check-requirements:
@if [ "\'${SKJOLD_GITHUB_API_TOKEN}\'" == "\'\'" ] \
; then \
echo "WARNING: Neither SKOLD_GITHUB_API_TOKEN nor GITHUB_TOKEN is set." \
; echo "Vulnerability check via skjold might fail when using the GitHub GraphQL API." \
; fi
. ../.python-sphinx-virtualenv/bin/activate \
&& pip install skjold \
&& skjold audit
# NB: For portability, we use '.' (sh etc.) instead of 'source' (bash).
# EOF
# https://pythonawesome.com/security-audit-python-project-dependencies-against-security-advisory-databases/
[tool.skjold]
sources = ['github', 'gemnasium', 'pyup']
report_only = false
# ALT: true # Report only, always exit with zero.
report_format = 'cli'
# ALT: 'json' # Output findings as `json`. Default is 'cli'.
verbose = true
cache_dir = '.skjold_cache'
cache_expires = 43200 # Cache max. age. (43200 = 12hrs)
ignore_file = '.skjoldignore'
sphinx >= 3.1 sphinx >= 3.1
sphinx_rtd_theme sphinx_rtd_theme
sphinx-jsonschema sphinx-jsonschema
# Pygments>=2.7.4 suggested by CVE-2021-20270 CVE-2021-27291
Pygments >= 2.7.4
...@@ -29,8 +29,10 @@ markupsafe==1.1.1 ...@@ -29,8 +29,10 @@ markupsafe==1.1.1
# via jinja2 # via jinja2
packaging==20.9 packaging==20.9
# via sphinx # via sphinx
pygments==2.5.2 pygments==2.10.0
# via sphinx # via
# -r requirements.in
# sphinx
pyparsing==2.4.7 pyparsing==2.4.7
# via packaging # via packaging
pytz==2021.3 pytz==2021.3
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment