Skip to content

Commit 8858d83

Browse files
committed
detect-secrets: add in IBM secret scanner
If a repository has a .secrets.baseline then the current commit will be scanned for any new secrets and fail the CI job if any are found. Signed-off-by: Andrew Geissler <[email protected]>
1 parent 64fa1b4 commit 8858d83

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

scripts/build-unit-test-docker

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -940,11 +940,14 @@ RUN apt-get update && apt-get dist-upgrade -yy && apt-get install -yy \
940940
wget \
941941
xxd
942942
943+
RUN pip install --break-system-packages --upgrade "git+https://github.com/ibm/detect-secrets.git@master#egg=detect-secrets"
944+
943945
RUN update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-14 14 \
944946
--slave /usr/bin/g++ g++ /usr/bin/g++-14 \
945947
--slave /usr/bin/gcov gcov /usr/bin/gcov-14 \
946948
--slave /usr/bin/gcov-dump gcov-dump /usr/bin/gcov-dump-14 \
947949
--slave /usr/bin/gcov-tool gcov-tool /usr/bin/gcov-tool-14
950+
948951
RUN update-alternatives --remove cpp /usr/bin/cpp && \
949952
update-alternatives --install /usr/bin/cpp cpp /usr/bin/cpp-14 14
950953

scripts/format-code.sh

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ LINTERS_ALL=( \
3737
markdownlint \
3838
prettier \
3939
shellcheck \
40+
detect_secrets \
4041
)
4142
LINTERS_DISABLED=()
4243
LINTERS_ENABLED=()
@@ -278,6 +279,13 @@ function do_clang_format() {
278279
"${CLANG_FORMAT}" -i "$@"
279280
}
280281

282+
LINTER_REQUIRE+=([detect_secrets]="detect-secrets;.secrets.baseline")
283+
LINTER_TYPES+=([detect_secrets]="c;cpp;bash;sh;json;python")
284+
function do_detect_secrets() {
285+
detect-secrets scan --update .secrets.baseline
286+
detect-secrets audit --report --fail-on-unaudited --fail-on-live --fail-on-audited-real .secrets.baseline
287+
}
288+
281289
function get_file_type()
282290
{
283291
case "$(basename "$1")" in
@@ -433,7 +441,13 @@ fi
433441
# Check for differences.
434442
if [ -z "$OPTION_NO_DIFF" ]; then
435443
echo -e " ${BLUE}Result differences...${NORMAL}"
436-
if ! git --no-pager diff --exit-code ; then
444+
# .secrets.baseline will have its date updated everytime we run so
445+
# just restore it
446+
if [ -e .secrets.baseline ]
447+
then
448+
git restore .secrets.baseline
449+
fi
450+
if ! git --no-pager diff --exit-code; then
437451
echo -e "Format: ${RED}FAILED${NORMAL}"
438452
exit 1
439453
else

0 commit comments

Comments
 (0)