upload-sarif does not handle relative paths when trivy runs on a subfolder
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 42/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- github-actions, typescript
Hướng nghiên cứu
Tái hiện workflow được minh họa bằng cách dùng Trivy quét terraform/01-bootstrap và upload-sarif, sau đó kiểm tra action upload-sarif và mục checkout_path được tham chiếu trong analyze/action.yml. So sánh cách các URI artifact tương đối, uriBaseId và các đường dẫn checkout được xử lý; hoàn tất khi các finding xuất hiện dưới những đường dẫn như terraform/01-bootstrap/eks.tf trong tab bảo mật.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Originally posted by @rofreytag in #2215
I run into an issue when using trivy config scan on a subfolder. The reported issues appear in the security tab, but the folder/path reference of files inside the repo is not correctly presented.
Example finding:
The expected path should be terraform/01-bootstrap/eks.tf.
The generated sarif file by trivy:
- uses URLs relative to
terraform/some-module(i.e.main.tf) - uses relative URLs for module invocations like
../modules/other-module/main.tf. - includes the correct
uriBaseId
GitHub interprets all these URls relative to the repo root without using uriBaseId.
I am happy to try a workaround, but currently
- I can not yet find a way to make trivy generate absolute URLs, which I believe resolves the issue.
- Neither can I tell the upload-action that I am using relative URLs in my repo
expected behavior
Either have the upload-action use the uriBaseId of the sarif file, or
have an existing param like checkout_path (or a new param) in the action, to respect and transform relative URLs, so that they correctly appear in the report.
Example:
- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@ff0a06e83cb2de871e5a09832bc6a81e7276941f # v3.28.18
with:
sarif_file: 'trivy-results.sarif'
category: trivy-my-module
checkout_path: ${{ github.workspace }}/terraform/01-bootstrap/
Here an excerpt of the generated sarif file that shows the URLs of each finding
"message": {
"text": "Artifact: eks.tf\nType: terraform\nVulnerability aws-vpc-add-description-to-security-group-rule\nSeverity: LOW\nMessage: Security group rule does not have a description.\nLink: [aws-vpc-add-description-to-security-group-rule](https://avd.aquasec.com/misconfig/aws-vpc-add-description-to-security-group-rule)"
},
"locations": [
{
"physicalLocation": {
"artifactLocation": {
"uri": "eks.tf",
"uriBaseId": "ROOTPATH"
},
"message": {
"text": "Artifact: ../modules/rdb/main.tf\nType: terraform\nVulnerability AVD-AWS-0098\nSeverity: LOW\nMessage: Secret explicitly uses the default key.\nLink: [AVD-AWS-0098](https://avd.aquasec.com/misconfig/avd-aws-0098)"
},
"locations": [
{
"physicalLocation": {
"artifactLocation": {
"uri": "../modules/rdb/main.tf",
"uriBaseId": "ROOTPATH"
},
and the originalUriBaseId section at the end:
"originalUriBaseIds": {
"ROOTPATH": {
"uri": "file:///home/runner/work/redacted/redacted/terraform/01-bootstrap/"
}
}
}
]
}
Here is my full workflow file
name: Code Scan
on:
push:
branches: [ "main" ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ "main" ]
schedule:
- cron: '27 23 * * 2'
permissions:
contents: read # for actions/checkout to fetch code
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
jobs:
analyze-tf:
runs-on: ubuntu-latest
name: Analyze (${{ matrix.config.path }})
strategy:
matrix:
config:
- path: terraform/00-shared
varfile: configs/sai-shared-prod.tfvars
- path: terraform/01-bootstrap
varfile: configs/sai-prod.tfvars
- path: terraform/02-k8s
varfile: configs/sai-prod.tfvars
- path: terraform/03-services
varfile: configs/sai-prod.tfvars
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Run Trivy scanner
uses: aquasecurity/trivy-action@6c175e9c4083a92bbca2f9724c8a5e33bc2d97a5 #v0.30.0
with:
scan-type: 'config'
scan-ref: ${{ matrix.config.path }}
tf-vars: ${{ matrix.config.path }}/${{ matrix.config.varfile }}
format: 'sarif'
output: 'trivy-results.sarif'
severity: 'CRITICAL,HIGH,MEDIUM'
version: v0.61.1
- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@ff0a06e83cb2de871e5a09832bc6a81e7276941f # v3.28.18
with:
sarif_file: 'trivy-results.sarif'
# need to add unique category, so the results in one commit do not overwrite each other
category: trivy-${{ matrix.config.path }}
# I tried this with no luck
# checkout_path: ${{ github.workspace }}/${{ matrix.config.path }}/
- Ngôn ngữ chính
- TypeScript
- Star
- 1.6k
- Fork
- 493
- Merge trung bình
- 1 ngày 13 giờ
- Pull request đã merge (30 ngày)
- 44
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của github/codeql-action
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
github/codeql-action#4052 · 4 bình luận ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
github/codeql-action#4078 · 1 bình luận ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
github/codeql-action#4008 · 9 bình luận ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 52/100
github/codeql-action#3978 · 4 bình luận · 1 reaction ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 48/100
github/codeql-action#3915 · 6 bình luận · 3 reaction ·
Tất cả issue của github/codeql-action
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
copse-dev/agent-pane#2953 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
Eynzof/Hermes-CN-Desktop#610 ·
-
[Bug]: Matrix progress drafts fail with "Matrix runtime not initialized" during tool activity Đang mởbug clawsweeper:linked-pr-open clawsweeper:needs-live-repro clawsweeper:no-new-fix-pr impact:message-loss issue-rating: 🐚 platinum hermit P2 regression
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
Client support matrix inclusion Đang mởenhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
-
calcite-components needs triage refactor
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Esri/calcite-design-system#15203 ·