一、静态应用程序安全测试(SAST)
将以下内容添加到您的.gitlab-ci.yml文件中
sast:
stage: sast
tags:
- maven
script:
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
- docker run --rm
--env SAST_CONFIDENCE_LEVEL="${SAST_CONFIDENCE_LEVEL:-3}"
--volume "$PWD":/code
--volume /etc/localtime:/etc/localtime:ro
--volume /var/run/docker.sock:/var/run/docker.sock
"registry.gitlab.com/gitlab-org/security-products/sast:${SP_VERSION}" /app/bin/run /code
artifacts:
reports:
sast: gl-sast-report.json
二、依赖项扫描
将以下内容添加到您的.gitlab-ci.yml文件中
dependency:
stage: dependency
tags:
- maven
script:
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
- docker run --rm
--env DEP_SCAN_DISABLE_REMOTE_CHECKS="${DEP_SCAN_DISABLE_REMOTE_CHECKS:-false}"
--volume "$PWD:/code"
--volume /etc/localtime:/etc/localtime:ro
--volume /var/run/docker.sock:/var/run/docker.sock
"registry.gitlab.com/gitlab-org/security-products/dependency-scanning:$SP_VERSION" /code
artifacts:
reports:
dependency_scanning: gl-dependency-scanning-report.json
三、动态应用程序安全性测试(DAST)
将以下内容添加到您的.gitlab-ci.yml文件中
include:
- template: DAST.gitlab-ci.yml
variables:
DAST_WEBSITE: https://example.com #访问地址需要修改为系统可访问的url
DAST_USERNAME: admin #系统登陆用户名
DAST_PASSWORD: ****** #系统登陆密码
四、容器扫描
将以下内容添加到您的.gitlab-ci.yml文件中
include:
- template: Container-Scanning.gitlab-ci.yml
五、许可证合规
将以下内容添加到您的.gitlab-ci.yml文件中
include:
- template: License-Scanning.gitlab-ci.yml
六、合并的.gitlab-ci.yml
stages:
- build
- test
- deploy
- sast
- dependency
sast:
stage: sast
tags:
- maven
script:
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
- docker run --rm
--env SAST_CONFIDENCE_LEVEL="${SAST_CONFIDENCE_LEVEL:-3}"
--volume "$PWD":/code
--volume /etc/localtime:/etc/localtime:ro
--volume /var/run/docker.sock:/var/run/docker.sock
"registry.gitlab.com/gitlab-org/security-products/sast:${SP_VERSION}" /app/bin/run /code
artifacts:
reports:
sast: gl-sast-report.json
dependency:
stage: dependency
tags:
- maven
script:
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
- docker run --rm
--env DEP_SCAN_DISABLE_REMOTE_CHECKS="${DEP_SCAN_DISABLE_REMOTE_CHECKS:-false}"
--volume "$PWD:/code"
--volume /etc/localtime:/etc/localtime:ro
--volume /var/run/docker.sock:/var/run/docker.sock
"registry.gitlab.com/gitlab-org/security-products/dependency-scanning:$SP_VERSION" /code
artifacts:
reports:
dependency_scanning: gl-dependency-scanning-report.json
include:
- template: License-Scanning.gitlab-ci.yml
- template: Container-Scanning.gitlab-ci.yml
- template: DAST.gitlab-ci.yml
variables:
DAST_WEBSITE: https://example.com #访问地址需要修改为系统可访问的url
DAST_USERNAME: admin #系统登陆用户名
DAST_PASSWORD: ****** #系统登陆密码
说明:
静态应用程序安全测试(SAST) 、依赖项扫描 中使用的 runner 注册时Runner executor 要选择 shell
动态应用程序安全性测试(DAST) 、容器扫描、许可证合规 中使用的 runner 注册时Runner executor 要选择 docker
参考文档:
官网文档:https://docs.gitlab.com/ee/user/application_security/security_dashboard/#gitlab-security-dashboard-ultimate
其他文档:https://www.linuxea.com/1832.html
Runner executor:https://docs.gitlab.com/runner/executors/README.html