极狐GitLab CI/CD 安全扫描镜像清单及隔离环境的下载使用
有些场景下,我们的GitLab实例可能搭建在隔离环境中,但CI/CD安全扫描使用的镜像又是在公网,针对这种场景,我们可以将安全扫描使用到的镜像下载下来,再导入到隔离环境的私有仓库中。
1. CI/CD 安全扫描类型
- 静态代码扫描(SAST)
- 容器扫描(Container Scanning)
- 依赖扫描(Dependency Scanning)
- 许可证扫描(License Scanning)
- 动态代码扫描(DAST)
2. 下载和导入容器镜像
-
如果目标环境允许中转机存在,即中转机可以连接公网,也可以连接内网,那么可以在中转机上拉取、标记和上传以下容器镜像到私有仓库中。
-
如果目标仓库是完全离线的,需要将镜像保存成文件。例如:
docker pull gitlab-jh-public.tencentcloudcr.com/security-products/analyzers/bandit:2
docker save -o bandit.tar gitlab-jh-public.tencentcloudcr.com/security-products/analyzers/bandit:2
# 拷贝文件bandit.tar到内网服务器上
docker load < bandit.tar
docker tag gitlab-jh-public.tencentcloudcr.com/security-products/analyzers/bandit:2 lab.alexju.cn:8443/gitlab/bandit:2
docker login lab.alexju.cn:8443
docker push lab.alexju.cn:8443/gitlab/bandit:2
批量方式:
2.1 静态代码扫描(SAST)镜像
- gitlab-jh-public.tencentcloudcr.com/security-products/analyzers/bandit:2
- gitlab-jh-public.tencentcloudcr.com/security-products/analyzers/brakeman:2
- gitlab-jh-public.tencentcloudcr.com/security-products/analyzers/eslint:2
- gitlab-jh-public.tencentcloudcr.com/security-products/analyzers/flawfinder:2
- gitlab-jh-public.tencentcloudcr.com/security-products/analyzers/kubesec:2
- gitlab-jh-public.tencentcloudcr.com/security-products/analyzers/gosec:3
- gitlab-jh-public.tencentcloudcr.com/security-products/analyzers/mobsf:2
- gitlab-jh-public.tencentcloudcr.com/security-products/analyzers/nodejs-scan:2
- gitlab-jh-public.tencentcloudcr.com/security-products/analyzers/phpcs-security-audit:2
- gitlab-jh-public.tencentcloudcr.com/security-products/analyzers/security-code-scan:2
- gitlab-jh-public.tencentcloudcr.com/security-products/analyzers/semgrep:2
- gitlab-jh-public.tencentcloudcr.com/security-products/analyzers/sobelow:2
- gitlab-jh-public.tencentcloudcr.com/security-products/analyzers/pmd-apex:2
- gitlab-jh-public.tencentcloudcr.com/security-products/analyzers/spotbugs:2
- gitlab-jh-public.tencentcloudcr.com/security-products/analyzers/secrets:3
2.2 动态代码扫描(DAST)镜像
- gitlab-jh-public.tencentcloudcr.com/security-products/analyzers/dast:2
- gitlab-jh-public.tencentcloudcr.com/security-products/analyzers/api-fuzzing:1
- gitlab-jh-public.tencentcloudcr.com/security-products/analyzers/dast-runner-validation:1
2.3 依赖扫描镜像
- gitlab-jh-public.tencentcloudcr.com/security-products/analyzers/bundler-audit:2
- gitlab-jh-public.tencentcloudcr.com/security-products/analyzers/retire.js:2
- gitlab-jh-public.tencentcloudcr.com/security-products/analyzers/gemnasium:2
- gitlab-jh-public.tencentcloudcr.com/security-products/analyzers/gemnasium-maven:2
- gitlab-jh-public.tencentcloudcr.com/security-products/analyzers/gemnasium-python:2
2.4 许可证扫描镜像
2.5 容器扫描镜像
- gitlab-jh-public.tencentcloudcr.com/security-products/analyzers/container-scanning:4
- registry.gitlab.com/security-products/container-scanning/grype:4
- registry.gitlab.com/security-products/container-scanning/trivy:4
- registry.gitlab.com/gitlab-org/security-products/analyzers/klar:3
2.6 其他镜像
可从docker hub下载:
- gitlab/gitlab-runner-helper:x86_64-775dd39d
- busybox:latest
- docker:19.03.12
- docker:19.03.12-dind
- ubuntu:18.04
- maven:3.3.9-jdk-8
- conanio/gcc9:1.34.0
- node:15.14
- python:3.8.5-alpine
3. CICD使用自定义镜像样例
.gitlab-ci.yml
示例,涉及镜像拉取以及上传:
include:
- template: Security/SAST.gitlab-ci.yml
- template: Dependency-Scanning.gitlab-ci.yml
- template: License-Scanning.gitlab-ci.yml
- template: Container-Scanning.gitlab-ci.yml
- template: DAST.gitlab-ci.yml
variables:
CI_REGISTRY: "lab.alexju.cn:8443" # Harbor Docker registry
CI_REGISTRY_USER: "alexju" # Harbor用户
CI_REGISTRY_IMAGE: $CI_REGISTRY/gitlab/$CI_PROJECT_NAME # Build阶段制作镜像名称
SECURE_ANALYZERS_PREFIX: $CI_REGISTRY/gitlab # 镜像仓库地址前缀
stages:
- build
- test
build:
image: $SECURE_ANALYZERS_PREFIX/docker:19.03.12
stage: build
services:
- name: $SECURE_ANALYZERS_PREFIX/docker:19.03.12-dind
alias: docker
variables:
DOCKER_DRIVER: overlay2
DOCKER_HOST: tcp://docker:2375
DOCKER_TLS_CERTDIR: ""
script:
- docker info
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
- docker build --pull -t "$CI_REGISTRY_IMAGE:$CI_COMMIT_SHA" .
- docker push "$CI_REGISTRY_IMAGE:$CI_COMMIT_SHA"