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:
|
|
|
|
|
SECURE_ANALYZERS_PREFIX: "registry.gitlab.com/gitlab-org/security-products/analyzers"
|
|
|
|
|
SECRETS_ANALYZER_VERSION: "3"
|
|
|
|
|
SECRET_DETECTION_EXCLUDED_PATHS: ""
|
|
|
|
|
|
|
|
|
|
.secret-analyzer:
|
|
|
|
|
stage: test
|
|
|
|
|
image: "$SECURE_ANALYZERS_PREFIX/secrets:$SECRETS_ANALYZER_VERSION"
|
|
|
|
|
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
|
|
|
|
|
- if [ "$CI_COMMIT_BRANCH" = "$CI_DEFAULT_BRANCH" ]; then echo "Running Secret Detection on default branch."; /analyzer run; exit 0; fi
|
2022-03-02 08:16:31 +05:30
|
|
|
|
- |
|
|
|
|
|
git fetch origin $CI_DEFAULT_BRANCH $CI_COMMIT_REF_NAME
|
|
|
|
|
git log --left-right --cherry-pick --pretty=format:"%H" refs/remotes/origin/${CI_DEFAULT_BRANCH}..refs/remotes/origin/${CI_COMMIT_REF_NAME} >${CI_COMMIT_SHA}_commit_list.txt
|
|
|
|
|
if [[ $(wc -l <${CI_COMMIT_SHA}_commit_list.txt) -eq "0" ]]; then
|
|
|
|
|
# if git log produces 0 or 1 commits we should scan $CI_COMMIT_SHA only
|
|
|
|
|
export SECRET_DETECTION_COMMITS=$CI_COMMIT_SHA
|
|
|
|
|
else
|
|
|
|
|
# +1 because busybox wc only counts \n and there is no trailing \n
|
|
|
|
|
echo "scanning $(($(wc -l <${CI_COMMIT_SHA}_commit_list.txt) + 1)) commits"
|
|
|
|
|
export SECRET_DETECTION_COMMITS_FILE=${CI_COMMIT_SHA}_commit_list.txt
|
|
|
|
|
fi
|
2021-09-04 01:27:46 +05:30
|
|
|
|
- /analyzer run
|
|
|
|
|
- rm "$CI_COMMIT_SHA"_commit_list.txt
|