【问题标题】:Adding Container-Scanning to CI in GitLab在 GitLab 中将容器扫描添加到 CI
【发布时间】:2020-05-15 18:50:27
【问题描述】:

所以我试图在 gitlab 中设置容器扫描,我尝试了很多方法,但似乎都没有,我错过了什么?

我的gitlab版本是:GitLab Community Edition 12.9.4

本机中的gitlab-runner为:Version: 12.10.2

这是我的 .gitlab-ci.yml

variables:
  vulnerable_tag: vulnerable
  non_vulnerable_tag: non_vulnerable
  IMAGE_NAME: test
  CLAIR_OUTPUT: High 

stages:
    - build
    - test

build:
  image: docker
  stage: build
  variables:
    IMAGE_NAME: test
    IMAGE_TAG: $CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG:$CI_COMMIT_SHA
  script:
    - uname -a
    - docker build -t $IMAGE_NAME .
    - docker run -d -p 80:80 $IMAGE_NAME 
    - docker ps
    - curl localhost
    - mkdir output
    - echo $IMAGE_NAME"/"$CI_COMMIT_REF_SLUG":"$CI_COMMIT_SHA >> output/file.txt
  tags:
    - testingtag
#  artifacts:
#    paths: 
#      - output/

stop_container:
  stage: test
  script:
    - docker stop $(docker ps -q)

是一个简单的 nginx 容器,只显示一个普通的 index.hmtl

我尝试过的(.gitlab-ci.yml 中的所有内容)都不起作用

include:
  - template: Container-Scanning.gitlab-ci.yml 

这就是文档所说的以及它应该如何工作,但它会引发错误This GitLab CI configuration is invalid: Included file `Container-Scanning.gitlab-ci.yml` is empty or does not exist!

include:
 - remote: 'https://gitlab.com/gitlab-org/gitlab/-/raw/master/lib/gitlab/ci/templates/Security/Container-Scanning.gitlab-ci.yml'

这不会引发错误,但什么也不做。 (链接是相同的Container-Scanning.gitlab-ci.yml,但为明文)

最后,将 Container-Scanning.gitlab-ci.yml 的内容添加为作业

# Read more about this feature here: https://docs.gitlab.com/ee/user/application_security/container_scanning/

variables:
  # Setting this variable will affect all Security templates
  # (SAST, Dependency Scanning, ...)
  SECURE_ANALYZERS_PREFIX: "registry.gitlab.com/gitlab-org/security-products/analyzers"

  CS_MAJOR_VERSION: 2

container_scanning:
  stage: test
  image: $SECURE_ANALYZERS_PREFIX/klar:$CS_MAJOR_VERSION
  variables:
    # By default, use the latest clair vulnerabilities database, however, allow it to be overridden here with a specific image
    # to enable container scanning to run offline, or to provide a consistent list of vulnerabilities for integration testing purposes
    CLAIR_DB_IMAGE_TAG: "latest"
    CLAIR_DB_IMAGE: "$SECURE_ANALYZERS_PREFIX/clair-vulnerabilities-db:$CLAIR_DB_IMAGE_TAG"
    # Override the GIT_STRATEGY variable in your `.gitlab-ci.yml` file and set it to `fetch` if you want to provide a `clair-whitelist.yml`
    # file. See https://docs.gitlab.com/ee/user/application_security/container_scanning/index.html#overriding-the-container-scanning-template
    # for details
    GIT_STRATEGY: none
  allow_failure: true
  services:
    - name: $CLAIR_DB_IMAGE
      alias: clair-vulnerabilities-db
  script:
    - /analyzer run
  artifacts:
    reports:
      container_scanning: gl-container-scanning-report.json
  dependencies: []
  rules:
    - if: $CONTAINER_SCANNING_DISABLED
      when: never
    - if: $CI_COMMIT_BRANCH &&
          $GITLAB_FEATURES =~ /\bcontainer_scanning\b/

CI 只是跳过这项工作,因为它不存在

【问题讨论】:

  • 问题解决了吗?我遇到同样的错误
  • @merla 不,我无法让它工作,经过一周的尝试我就放弃了

标签: git gitlab gitlab-ci


【解决方案1】:

GitLab 社区版不包含容器扫描功能。目前,它仅在 Ultimate 和 Gold 订阅中可用,如 at the top of this page 所述。

如果未检测到容器扫描功能,这部分 CI 配置 GitLab 也会跳过整个扫描步骤,因为您运行的是社区版,所以不会:

  rules:  
    - if: $CONTAINER_SCANNING_DISABLED  
      when: never  
    - if: $CI_COMMIT_BRANCH &&  
          $GITLAB_FEATURES =~ /\bcontainer_scanning\b/

【讨论】:

  • 你好。请下次提交帖子后检查它的格式是否正确。
【解决方案2】:

如果您检查模板的路径,它包含Security,因此以下代码应该可以工作:

include:
  - template: Securtiy/Container-Scanning.gitlab-ci.yml 

【讨论】:

    猜你喜欢
    • 2020-08-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-02
    • 2014-10-11
    • 2019-09-26
    • 2021-07-10
    • 2018-01-26
    相关资源
    最近更新 更多