Skip to main content

Quick start (setup & get reports)

Overview

  • Step 1: Tạo project trên Sonarqube.
  • Step 2: Request cấp phát tài nguyên CICD.
  • Step 3: Thiết lập cấu hình file CICD. (.gitlab-ci.yml)
  • Step 4: Chờ quá trình quyét hoàn tất, truy cập kết quả.

Step 1: Tạo project trên Sonarqube.

Tạo project trên sonarqube. Đây là nơi chứa kết quả của tool sonarqube và dependency-check. Guide: https://cicd.runsystem.work/docs/integrated-with-cicd/sonarqube-intergrated

Step 2: Request cấp phát tài nguyên CICD.

Tạo request cấp phát tài nguyên dành cho CICD nếu trước đó repository chưa được thiết lập để sử dụng quy trình CICD. Request Url: https://jira8.runsystem.info/plugins/servlet/desk/portal/1/create/470

Note: Những thông tin gửi kèm request bao gồm:

  • UrL Gitlab của các repoítory cần tích hợp Cicd.
  • Url của sonaqube project tạo ở step 1.
  • Tên user của sonarqube (sẽ cấp quyền admin sonar cho user này để view issuse và add member). Truy cập: https://sq.runsystem.info/account

Step 3: Thiết lập file cấu hình CICD.

File cấu hình ví dụ cho Gitlab CI (Áp dụng tất cả các ngôn ngữ, ngoại trừ Java & Flutter)

Tạo mới hoặc copy nội dung bên duới vào file .gitlab-ci.yml trong 1 branch bất kỳ của repository muốn quét.

stages:
- gitleaks
- dependencycheck
- sonarqube
- license-scancode

sonarqube:
stage: sonarqube
image:
name: sonarsource/sonar-scanner-cli:latest
entrypoint: [ "" ]
variables:
SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar"
SONAR_HOST_URL: https://sq.runsystem.info
SONAR_TOKEN: "${SONAR_TOKEN}"
SONAR_SCANNER_OPTS: "-Dsonar.projectKey=${SONAR_PROJECT_KEY}"
cache:
key: "${CI_JOB_NAME}"
paths:
- .sonar/cache
script:
- sonar-scanner -Dsonar.sources=. -Dsonar.dependencyCheck.htmlReportPath=./dependency-check-report.html -Dsonar.exclusions=**/dependency-check-report.html,**/*.java,**/*.yml -Dsonar.dependencyCheck.severity.critical=4.0
allow_failure: true

gitleaks:
stage: gitleaks
image:
name: zricethezav/gitleaks:latest
entrypoint: [""]
script:
- git config --global --add safe.directory $CI_PROJECT_DIR
- gitleaks detect -v ./ | tee gitleaks-result.log
allow_failure: true
artifacts:
when: always # or 'on_failure'
paths:
- ./gitleaks-result.log
expire_in: 1 week

dependencycheck:
stage: dependencycheck
image:
name: mannk98/dependency-check:latest
entrypoint: [ "" ]
script:
- /usr/share/dependency-check/bin/dependency-check.sh --project Project --out . --scan . --format "HTML" --format "CSV" --format "JSON" --enableExperimental --failOnCVSS 4 --noupdate
allow_failure: true
artifacts:
when: always # or 'on_failure'
paths:
- ./dependency-check-report.html
- ./dependency-check-report.csv
- ./dependency-check-report.csv
expire_in: 1 week

license-scancode:
stage: license-scancode
image: gianlucadb0/scancode-toolkit
script:
- scancode -clpeui -n 4 --cyclonedx results-cyclonedx --spdx-tv results-spdx --json-pp results.json --html result.html ./
allow_failure: true
artifacts:
when: always # or 'on_failure'
paths:
- results-cyclonedx
- results-spdx
- results.json
expire_in: 1 week

Sau khi cấu hình như trên, các tool Dependency check, scancode (license), git leaks, sonar sẽ được thêm vào quy trình Cicd của dự án.

File cấu hình ví dụ cho Gitlab CI (Java project)

stages:
- gitleaks
- dependencycheck
- sonarqube
- license-scancode

sonarqube:
stage: sonarqube
image:
name: sonarsource/sonar-scanner-cli:latest
entrypoint: [ "" ]
variables:
SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar"
SONAR_HOST_URL: https://sq.runsystem.info
SONAR_TOKEN: "${SONAR_TOKEN}"
SONAR_SCANNER_OPTS: "-Dsonar.projectKey=${SONAR_PROJECT_KEY}"
cache:
key: "${CI_JOB_NAME}"
paths:
- .sonar/cache
script:
- sonar-scanner -Dsonar.sources=. -Dsonar.dependencyCheck.htmlReportPath=./dependency-check-report.html -Dsonar.exclusions=**/dependency-check-report.html,**/*.yaml,**/*.yml,**/*.sh -Dsonar.java.binaries=. -Dsonar.dependencyCheck.severity.critical=4.0
allow_failure: true

gitleaks:
stage: gitleaks
image:
name: zricethezav/gitleaks:latest
entrypoint: [""]
script:
- git config --global --add safe.directory $CI_PROJECT_DIR
- gitleaks detect -v ./ | tee gitleaks-result.log
allow_failure: true
artifacts:
when: always # or 'on_failure'
paths:
- ./gitleaks-result.log
expire_in: 1 week

dependencycheck:
stage: dependencycheck
image:
name: mannk98/dependency-check:latest
entrypoint: [ "" ]
script:
- /usr/share/dependency-check/bin/dependency-check.sh --project Project --out . --scan . --format "HTML" --format "CSV" --format "JSON" --enableExperimental --failOnCVSS 4 --noupdate
allow_failure: true
artifacts:
when: always # or 'on_failure'
paths:
- ./dependency-check-report.html
- ./dependency-check-report.csv
- ./dependency-check-report.csv
expire_in: 1 week

license-scancode:
stage: license-scancode
image: gianlucadb0/scancode-toolkit
script:
- scancode -clpeui -n 4 --cyclonedx results-cyclonedx --spdx-tv results-spdx --json-pp results.json --html result.html ./
allow_failure: true
artifacts:
when: always # or 'on_failure'
paths:
- results-cyclonedx
- results-spdx
- results.json
expire_in: 1 week

File cấu hình ví dụ cho Gitlab CI (Flutter project)

stages:
- gitleaks
- dependencycheck
- sonarqube
- license-scancode

sonarqube:
stage: sonarqube
image:
name: mannk98/sonar-scanner-cli:latest
entrypoint: [ "" ]
variables:
SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar"
SONAR_HOST_URL: https://sq.runsystem.info
SONAR_TOKEN: 54cf56912dc4bda1d26f8708737e87bf26a0c84b
SONAR_SCANNER_OPTS: "-Dsonar.projectKey=manualLocalscan.flutter-test"
cache:
key: "${CI_JOB_NAME}"
paths:
- .sonar/cache
script:
- sonar-scanner -Dsonar.sources=. -Dsonar.dependencyCheck.htmlReportPath=./dependency-check-report.html -Dsonar.exclusions=**/dependency-check-report.html,**/*.java -Dsonar.dependencyCheck.severity.critical=4.0
allow_failure: true

gitleaks:
stage: gitleaks
image:
name: zricethezav/gitleaks:latest
entrypoint: [""]
script:
- git config --global --add safe.directory $CI_PROJECT_DIR
- gitleaks detect -v ./ | tee gitleaks-result.log
allow_failure: true
artifacts:
when: always # or 'on_failure'
paths:
- ./gitleaks-result.log
expire_in: 1 week

dependencycheck:
stage: dependencycheck
image:
name: mannk98/dependency-check:latest
entrypoint: [ "" ]
script:
- /usr/share/dependency-check/bin/dependency-check.sh --project Project --out . --scan . --format "HTML" --format "CSV" --format "JSON" --enableExperimental --failOnCVSS 4 --noupdate
allow_failure: true
artifacts:
when: always # or 'on_failure'
paths:
- ./dependency-check-report.html
- ./dependency-check-report.csv
- ./dependency-check-report.csv
expire_in: 1 week

license-scancode:
stage: license-scancode
image: gianlucadb0/scancode-toolkit
script:
- scancode -clpeui -n 4 --cyclonedx results-cyclonedx --spdx-tv results-spdx --json-pp results.json --html result.html ./
allow_failure: true
artifacts:
when: always # or 'on_failure'
paths:
- results-cyclonedx
- results-spdx
- results.json
expire_in: 1 week

Step 4: Truy cập kết quả quét.

Lấy kết quả các tools (trừ sonar): Mục Build --> Pipelines --> Dowload artifacts. (Hướng dẫn xem artifact xem cụ thể tại mục hướng dẫn của từng tools)

View kết quả Sonar,Dependency Check: Truy cập sonarqube từ kết quả quét.

  • Ví dụ: Kết quả chạy của stage sonar-qube cho thấy stage đã success. Có thể truy cập vào sonar project từ link bổi đỏ.

Step 5: PM dự án cấp quyền cho các member sử dụng Sonar.

Truy cập Project Settings --> Permission --> Tìm user bằng tên/mail --> Cấp quyền như hình.