【问题标题】:GitLab Secrets Detection - Pipeline doesn't fail - Only checks last commitGitLab 秘密检测 - 管道不会失败 - 只检查最后一次提交
【发布时间】:2022-12-20 23:57:16
【问题描述】:

为了在我的 GitLab 存储库中通过管道对合并请求实施秘密检测器,我在此处遵循了 GitLab 的这份文档:"Enable Secret Detection | Edit the .gitlab.ci.yml file manually"

但是如果检测到任何秘密,管道不会失败。此外,它只检查合并请求中的最后一次提交,这使得它毫无用处。

如何处理这两个问题?

【问题讨论】:

    标签: gitlab gitlab-ci merge-request app-secret secrets


    【解决方案1】:

    我使用以下代码在存储库的根级别创建了一个名为 .gitlab-ci.yml 的文件:

    include:
    - template: Security/Secret-Detection.gitlab-ci.yml
    
    secret_detection:
      extends: .secret-analyzer
      variables:
        SECRET_DETECTION_LOG_OPTIONS: origin/${CI_DEFAULT_BRANCH}..HEAD # Check commits to default branch, e.g. master
      before_script:
        - git fetch origin ${CI_DEFAULT_BRANCH} # Needed for SECRET_DETECTION_LOG_OPTIONS
      script:
        - apk add jq
        - /analyzer run
        - NUMBER_OF_VULNERABILITIES=$(cat gl-secret-detection-report.json | jq --raw-output '.vulnerabilities | length')
        - exit $NUMBER_OF_VULNERABILITIES
    

    如果检测到任何秘密,此代码不仅会使管道失败,而且还会检查合并请求的源分支中的所有提交。

    【讨论】:

      猜你喜欢
      • 2021-05-03
      • 1970-01-01
      • 1970-01-01
      • 2020-04-16
      • 2022-07-04
      • 1970-01-01
      • 1970-01-01
      • 2020-08-04
      • 2011-01-21
      相关资源
      最近更新 更多