kubeslice / kubeslice/kubeslice-controller
Bug: Trivy security gate always reports 0 CRITICAL vulnerabilities
- Dominant language
- Go
- Stars
- 73
- Forks
- 48
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 8
Description
### 📜 Description
Both `base-image-critical.sh` and `binary-image-critical.sh` use `while read -r line; do x=$(grep -o "CRITICAL: [0-9]*" | awk '{print $2}'); done < final.txt`. The `< final.txt` redirect feeds the file to the `while read` loop's stdin file descriptor. Inside the loop, `grep` reads from the same shared stdin rather than from `$line` (which is never passed to `grep`). On the first iteration `read` consumes line 1 from stdin; `grep` then consumes lines 2–N. Because the CRITICAL summary typically appears on line 1, `grep` never sees it, `$x` is empty, and `$sum` is always 0. The security gate that should block PRs with critical CVEs never triggers.
### 👟 Reproduction steps
1. Read `.github/workflows/scripts/base-image-critical.sh:8-12` — `$line` is set by `read` but never passed to `grep`; `grep` reads from shared stdin.
2. Create a test file:
```bash
echo "CRITICAL: 5" > final.txt
```
3. Run the script:
```bash
bash .github/workflows/scripts/base-image-critical.sh
```
4. Output: `base image critical value is 0` — even though `final.txt` contains `CRITICAL: 5`.
### 👍 Expected behavior
The script correctly extracts all CRITICAL counts from the scan file, sums them, and exits 1 when any CRITICAL vulnerability is found.
### 👎 Actual Behavior
`grep` reads from the shared stdin rather than from `$line`. The CRITICAL count is always 0. The script exits 0 regardless of real CVE counts.
### 🐚 Relevant log output
### Version
_No response_
### 🖥️ What operating system are you seeing the problem on?
_No response_
### ✅ Proposed Solution
Remove the `while read` loop entirely. Pass the scan file directly to `grep` as a file argument, capture all CRITICAL count matches in one pass, and sum them in a simple `for` loop over the results.
### 👀 Have you spent some time to check if this issue has been raised before?
- [x] I checked and didn't find any similar issue
### Code of Conduct
- [x] I agree to follow this project's Code of Conduct
Contributor guide
Assessment
This issue has not been assessed yet.