简体   繁体   English

Gitlab CI/CD 中的秘密检测

[英]Secrets Detection in Gitlab CI/CD

I'm having some troubles understanding how to activate Secrets Detection in Gitlab CI/CD.我在理解如何在 Gitlab CI/CD 中激活秘密检测时遇到了一些麻烦。 I created a new NodeJS Express from template and then i activated auto-devops from Settings > CI/CD and checked the checkbox Default to Auto Devops pipeline under the Auto Devops Menu.我从模板创建了一个新的 NodeJS Express,然后我从Settings > CI/CD激活了 auto-devops,并选中了 Auto Devops 菜单下的Default to Auto Devops pipeline复选框。 After that i opened the app.js file in the project folder and inserted a variable that looks like a key-value.之后,我在项目文件夹中打开了 app.js 文件并插入了一个看起来像键值的变量。 Here's the piece of code where i inserted the line:这是我插入该行的一段代码:

...
var app = express();

var key = "api-12321321321321321";

// view engine setup
app.set('views', path.join(__dirname, 'views'));
...

After committing the changes i expected the pipeline to fail because of the leak of the secret.提交更改后,我预计管道会因为秘密泄露而失败。 Here's an images that shows that secret dection passed.这是一张显示秘密检测通过的图像。 在此处输入图像描述

Can anyone tell me how to make so that the pipeline reports the error?谁能告诉我如何使管道报告错误?

GitLab has a full post about setting this up in a pipeline: https://docs.gitlab.com/ee/user/application_security/secret_detection/ GitLab 有一篇关于在管道中进行设置的完整帖子: https://docs.gitlab.com/ee/user/application_security/secret_detection/

EDIT:编辑:

The given instructions are a bit unclear:给定的说明有点不清楚:

You need to add the include tag at "root-level" of your configuration.您需要在配置的“根级别”添加include标签。

Example例子

stages:
    - build
    - test

image: node:latest

build:
    stage: build
    script:
        - echo "Building"
        - npm install typescript
        - yarn run build
test:
    stage: test
    script:
        - echo "Testing"

include:
    - template: Security/Secret-Detection.gitlab-ci.yml

The secret detection will run in the test stage: Pipeline秘密检测将在测试阶段运行: Pipeline

This should be easier with GitLab 13.12 (May 2021):使用GitLab 13.12 (2021 年 5 月)应该会更容易:

Configuration tool for Secret Detection秘密检测配置工具

Following in the footsteps of the GitLab SAST configuration tool we are adding support for Secret Detection on the Security Configuration page.跟随GitLab SAST 配置工具的脚步,我们将在安全配置页面上添加对秘密检测的支持。
We believe that security is a team effort and this configuration experience makes it easier for non-CI experts to get started with GitLab Secret Detection .我们相信安全是一个团队的努力,这种配置经验使非 CI 专家更容易开始使用GitLab 秘密检测

The tool helps a user create a merge request to enable Secret Detection scanning while leveraging best configuration practices like using the GitLab-managed SAST.gitlab-ci.yml template .该工具可帮助用户创建合并请求以启用秘密检测扫描,同时利用最佳配置实践,例如使用 GitLab 管理SAST.gitlab-ci.yml模板
The Configuration tool can create a new .gitlab-ci.yml file if one does not exist or update existing simple GitLab CI files, allowing the tool to be used with projects that already have GitLab CI setup.配置工具可以创建一个新.gitlab-ci.yml文件(如果不存在)或更新现有的简单 GitLab CI 文件,允许该工具用于已经具有 GitLab CI 设置的项目。

https://about.gitlab.com/images/13_12/secret_config_button_13_12.png -- 秘密检测配置工具

See Documentation and Epic .请参阅文档史诗

This behavior has confused me as well when I have first tried it out.当我第一次尝试时,这种行为也让我感到困惑。

However, it seems that GitLab did this on purpose.但是,GitLab 似乎是故意这样做的。 Here is what the official documentation says:这是官方文档所说的:

gitlab 文档

So with a free or premium account, you can just use this reporter, but you won't see any results, unless you download the JSON report.因此,对于免费或高级帐户,您可以只使用此报告器,但您不会看到任何结果,除非您下载 JSON 报告。

Also, there is NO mention that the job will fail.此外,没有提到这项工作会失败。 This is just our expectation.这只是我们的期望。

In other words, if you are on a free/premium account this feature is almost useless, as nobody will go to the job and manually inspect it.换句话说,如果您使用的是免费/高级帐户,则此功能几乎没有用,因为没有人会 go 去工作并手动检查它。

The only workaround would be to override the secret_detection job, parse the gl-secret-detection-report.json, check if it passed or failed and decide to PASS or FAIL the JOB.唯一的解决方法是覆盖secret_detection作业,解析 gl-secret-detection-report.json,检查它是通过还是失败,然后决定通过或失败作业。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM