diff --git a/.github/workflows/bandit.yml b/.github/workflows/bandit.yml new file mode 100644 index 0000000000000000000000000000000000000000..6d9eb560fd640a13d1e6689196d3ef09bd38da8d --- /dev/null +++ b/.github/workflows/bandit.yml @@ -0,0 +1,30 @@ + +name: bandit + +on: [push, pull_request] + +env: + GITHUB_REPO: pmem/pmdk + DOCKER_REPO: ghcr.io/pmem/pmdk + HOST_WORKDIR: /home/runner/work/pmdk/pmdk + WORKDIR: utils/docker + +jobs: + linux: + name: Linux + runs-on: ubuntu-latest + strategy: + matrix: + CONFIG: ["BANDIT=1 OS=ubuntu OS_VER=20.04"] + steps: + - name: Print out the current date and time + run: date + + - name: Clone the git repo + uses: actions/checkout@v2 + + - name: Pull or rebuild the image + run: cd $WORKDIR && ${{ matrix.CONFIG }} ./pull-or-rebuild-image.sh + + - name: Run the build + run: cd $WORKDIR && ${{ matrix.CONFIG }} ./build-CI.sh diff --git a/README.md b/README.md index 96bf234a5dd7da3349d0231afa06998e0927a4a9..e1bc296975fc2c022b4acf0a5d4f1c83f61e1879 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ [](https://github.com/pmem/pmdk/releases/latest) [](https://repology.org/project/pmdk/versions) [](https://lgtm.com/projects/g/pmem/pmdk/context:cpp) +[](https://github.com/pmem/pmdk/actions/workflows/bandit.yml) The **Persistent Memory Development Kit (PMDK)** is a collection of libraries and tools for System Administrators and Application Developers to simplify managing and accessing persistent memory devices. For more information, see https://pmem.io. diff --git a/src/tools/pmreorder/consistencycheckwrap.py b/src/tools/pmreorder/consistencycheckwrap.py index d553618b26b7319c595ce24246e5f82df16cc51b..bf55f7cff2de30905096a992ad54a59428be88d1 100644 --- a/src/tools/pmreorder/consistencycheckwrap.py +++ b/src/tools/pmreorder/consistencycheckwrap.py @@ -1,5 +1,5 @@ # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2018-2021, Intel Corporation +# Copyright 2018-2022, Intel Corporation from ctypes import cdll, c_char_p, c_int from loggingfacility import LoggingBase @@ -121,7 +121,13 @@ class ProgChecker(ConsistencyCheckerBase): cmd = "{0} {1} {2}".format(self._bin_path, self._bin_cmd, filename) self._logger.debug("Consistency check program command: {}".format(cmd)) - return system(cmd) + """ + We mark the call of this command as 'nosec' (for Bandit scan) because + pmreorder entirely relies on the execution of checkers, which are + user-developed programs. Therefore, it is the user's responsibility + to provide safe input as a consistency checker. + """ + return system(cmd) # nosec def get_checker(checker_type, checker_path_args, func_name, logger=None): diff --git a/utils/docker/build-CI.sh b/utils/docker/build-CI.sh index a1083305d80aadc02c954391e68fc99e17dd4e1b..d0cc9b2fb9556f4dec0bc14667b1729ac76083eb 100755 --- a/utils/docker/build-CI.sh +++ b/utils/docker/build-CI.sh @@ -50,6 +50,7 @@ containerName=pmdk-${OS}-${OS_VER} if [[ $MAKE_PKG -eq 0 ]] ; then command="./run-build.sh"; fi if [[ $MAKE_PKG -eq 1 ]] ; then command="./run-build-package.sh"; fi if [[ $COVERAGE -eq 1 ]] ; then command="./run-coverage.sh"; ci_env=`bash <(curl -s https://codecov.io/env)`; fi +if [[ $BANDIT -eq 1 ]] ; then command="./run-bandit.sh"; fi if [[ ( "$CI_EVENT_TYPE" == "cron" || "$CI_BRANCH" == "coverity_scan" )\ && "$COVERITY" -eq 1 ]]; then @@ -141,6 +142,7 @@ docker run --rm --name=$containerName -i $TTY \ --env CI_RUN=$CI_RUN \ --env SRC_CHECKERS=$SRC_CHECKERS \ --env BLACKLIST_FILE=$BLACKLIST_FILE \ + --env BANDIT=$BANDIT \ $ndctl_enable \ $pmemset_install \ --tmpfs /tmp:rw,relatime,suid,dev,exec,size=6G \ diff --git a/utils/docker/run-bandit.sh b/utils/docker/run-bandit.sh new file mode 100755 index 0000000000000000000000000000000000000000..edadc71a71b85e0c6b2b1ee7cac88f809d6b7697 --- /dev/null +++ b/utils/docker/run-bandit.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: BSD-3-Clause +# Copyright 2022, Intel Corporation + +# +# run-bandit.sh - is called inside a Docker container; runs bandit +# security checker for code written in python +# + +set -e + +# Get and prepare PMDK source +./prepare-for-build.sh + +cd $WORKDIR + +# set path to pmreorder tool +# at the moment pmreorder is the only python tool +# released in the PMDK +SCAN_DIR=src/tools/pmreorder + +echo "Start Bandit scan" + +bandit --version +bandit -r "$SCAN_DIR" + +echo "End Bandit scan"