debian-mirror-gitlab/lib/gitlab/ci/templates/Jobs/Secret-Detection.gitlab-ci.yml

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

68 lines
3.1 KiB
YAML
Raw Normal View History

2021-09-04 01:27:46 +05:30
# Read more about this feature here: https://docs.gitlab.com/ee/user/application_security/secret_detection
#
# Configure the scanning tool through the environment variables.
# List of the variables: https://docs.gitlab.com/ee/user/application_security/secret_detection/#available-variables
# How to set: https://docs.gitlab.com/ee/ci/yaml/#variables
variables:
2022-05-07 20:08:51 +05:30
SECURE_ANALYZERS_PREFIX: "registry.gitlab.com/security-products"
2022-06-21 17:19:12 +05:30
SECRET_DETECTION_IMAGE_SUFFIX: ""
2021-09-04 01:27:46 +05:30
SECRETS_ANALYZER_VERSION: "3"
SECRET_DETECTION_EXCLUDED_PATHS: ""
.secret-analyzer:
stage: test
2022-06-21 17:19:12 +05:30
image: "$SECURE_ANALYZERS_PREFIX/secrets:$SECRETS_ANALYZER_VERSION$SECRET_DETECTION_IMAGE_SUFFIX"
2021-09-04 01:27:46 +05:30
services: []
allow_failure: true
2022-03-02 08:16:31 +05:30
variables:
GIT_DEPTH: "50"
2021-09-04 01:27:46 +05:30
# `rules` must be overridden explicitly by each child job
# see https://gitlab.com/gitlab-org/gitlab/-/issues/218444
artifacts:
reports:
secret_detection: gl-secret-detection-report.json
secret_detection:
extends: .secret-analyzer
rules:
- if: $SECRET_DETECTION_DISABLED
when: never
- if: $CI_COMMIT_BRANCH
script:
2021-10-27 15:23:28 +05:30
- if [ -n "$CI_COMMIT_TAG" ]; then echo "Skipping Secret Detection for tags. No code changes have occurred."; exit 0; fi
2022-05-07 20:08:51 +05:30
# Historic scan
2022-06-21 17:19:12 +05:30
- if [ "$SECRET_DETECTION_HISTORIC_SCAN" == "true" ]; then echo "Running Secret Detection Historic Scan"; /analyzer run; exit; fi
2022-05-07 20:08:51 +05:30
# Default branch scan
- if [ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]; then echo "Running Secret Detection on default branch."; /analyzer run; exit; fi
# Push event
- |
if [ "$CI_COMMIT_BEFORE_SHA" == "0000000000000000000000000000000000000000" ];
then
# first commit on a new branch
echo ${CI_COMMIT_SHA} >${CI_COMMIT_SHA}_commit_list.txt
git fetch --depth=2 origin $CI_COMMIT_REF_NAME
else
# determine commit range so that we can fetch the appropriate depth
# check the exit code to determine if we need to limit the commit_list.txt to CI_COMMIT_SHA.
if ! git log --pretty=format:"%H" ${CI_COMMIT_BEFORE_SHA}..${CI_COMMIT_SHA} >${CI_COMMIT_SHA}_commit_list.txt;
then
echo "unable to determine commit range, limiting to ${CI_COMMIT_SHA}"
echo ${CI_COMMIT_SHA} >${CI_COMMIT_SHA}_commit_list.txt
else
# append newline to to list since `git log` does not end with a
# newline, this is to keep the log messages consistent
echo >> ${CI_COMMIT_SHA}_commit_list.txt
fi
2022-04-04 11:22:00 +05:30
2022-05-07 20:08:51 +05:30
# we need to extend the git fetch depth to the number of commits + 1 for the following reasons:
# to include the parent commit of the base commit in this MR/Push event. This is needed because
# `git diff -p` needs something to compare changes in that commit against
git fetch --depth=$(($(wc -l <${CI_COMMIT_SHA}_commit_list.txt) + 1)) origin $CI_COMMIT_REF_NAME
fi
echo "scanning $(($(wc -l <${CI_COMMIT_SHA}_commit_list.txt))) commits for a push event"
2022-04-04 11:22:00 +05:30
export SECRET_DETECTION_COMMITS_FILE=${CI_COMMIT_SHA}_commit_list.txt
2021-09-04 01:27:46 +05:30
- /analyzer run
- rm "$CI_COMMIT_SHA"_commit_list.txt