Skip to content

Feature/container scan#194

Merged
andrzej-janczak merged 10 commits intomainfrom
feature/container-scan
Feb 2, 2026
Merged

Feature/container scan#194
andrzej-janczak merged 10 commits intomainfrom
feature/container-scan

Conversation

@andrzej-janczak
Copy link
Contributor

@andrzej-janczak andrzej-janczak commented Feb 2, 2026

tested:

go run cli-v2.go container-scan alpine:3.7
🔍 Scanning container image: alpine:3.7

2026-02-02T10:32:54+01:00       INFO    [vuln] Vulnerability scanning is enabled
2026-02-02T10:32:56+01:00       INFO    Detected OS     family="alpine" version="3.7.3"
2026-02-02T10:32:56+01:00       INFO    [alpine] Detecting vulnerabilities...   os_version="3.7" repository="3.7" pkg_num=13
2026-02-02T10:32:56+01:00       WARN    This OS version is no longer supported by the distribution      family="alpine" version="3.7.3"
2026-02-02T10:32:56+01:00       WARN    The vulnerability detection may be insufficient because security updates are not provided

Report Summary

┌───────────────────────────┬────────┬─────────────────┐
│          Target           │  Type  │ Vulnerabilities │
├───────────────────────────┼────────┼─────────────────┤
│ alpine:3.7 (alpine 3.7.3) │ alpine │        2        │
└───────────────────────────┴────────┴─────────────────┘
Legend:
- '-': Not scanned
- '0': Clean (no security findings detected)


alpine:3.7 (alpine 3.7.3)

Total: 2 (HIGH: 0, CRITICAL: 2)

┌────────────┬────────────────┬──────────┬────────┬───────────────────┬───────────────┬──────────────────────────────────────────────────────────┐
│  Library   │ Vulnerability  │ Severity │ Status │ Installed Version │ Fixed Version │                          Title                           │
├────────────┼────────────────┼──────────┼────────┼───────────────────┼───────────────┼──────────────────────────────────────────────────────────┤
│ musl       │ CVE-2019-14697 │ CRITICAL │ fixed  │ 1.1.18-r3         │ 1.1.18-r4     │ musl libc through 1.1.23 has an x87 floating-point stack │
│            │                │          │        │                   │               │ adjustment im ......                                     │
│            │                │          │        │                   │               │ https://avd.aquasec.com/nvd/cve-2019-14697               │
├────────────┤                │          │        │                   │               │                                                          │
│ musl-utils │                │          │        │                   │               │                                                          │
│            │                │          │        │                   │               │                                                          │
│            │                │          │        │                   │               │                                                          │
└────────────┴────────────────┴──────────┴────────┴───────────────────┴───────────────┴──────────────────────────────────────────────────────────┘

📣 Notices:
  - Version 0.69.0 of Trivy is now available, current version is 0.66.0

To suppress version checks, run Trivy scans with the --skip-version-check flag


❌ Scanning failed: vulnerabilities found in the container image
exit status 1
go run cli-v2.go container-scan alpine:latest
🔍 Scanning container image: alpine:latest

2026-02-02T10:33:23+01:00       INFO    [vuln] Vulnerability scanning is enabled
2026-02-02T10:33:25+01:00       INFO    Detected OS     family="alpine" version="3.23.3"
2026-02-02T10:33:25+01:00       WARN    This OS version is not on the EOL list  family="alpine" version="3.23"
2026-02-02T10:33:25+01:00       INFO    [alpine] Detecting vulnerabilities...   os_version="3.23" repository="3.23" pkg_num=16

Report Summary

┌───────────────────────────────┬────────┬─────────────────┐
│            Target             │  Type  │ Vulnerabilities │
├───────────────────────────────┼────────┼─────────────────┤
│ alpine:latest (alpine 3.23.3) │ alpine │        0        │
└───────────────────────────────┴────────┴─────────────────┘
Legend:
- '-': Not scanned
- '0': Clean (no security findings detected)


📣 Notices:
  - Version 0.69.0 of Trivy is now available, current version is 0.66.0

To suppress version checks, run Trivy scans with the --skip-version-check flag


✅ Success: No vulnerabilities found matching the specified criteria

franciscoovazevedo and others added 9 commits January 19, 2026 14:42
… update related tests. Removed support for multiple images in command usage and adjusted the execution logic accordingly.
…o CommandRunner interface and implementing isScanFailure check. Introduced tests for scan failure scenarios and updated MockCommandRunner to support stderr handling.
…Adjusted rule indices for existing vulnerabilities and added a new entry for eslint vulnerability CVE-2025-50537.
Copilot AI review requested due to automatic review settings February 2, 2026 09:25
@codacy-production
Copy link

codacy-production bot commented Feb 2, 2026

Codacy's Analysis Summary

0 new issue (≤ 1 medium issue)
0 new security issue (≤ 0 issue)
90 complexity
3 duplications

Review Pull Request in Codacy →

AI Reviewer available: add the codacy-review label to get contextual insights without leaving GitHub.

@codacy-production
Copy link

codacy-production bot commented Feb 2, 2026

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
+1.61% (target: -0.50%) 74.17% (target: 50.00%)
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (e1bb1bc) 5798 1179 20.33%
Head commit (e4b5e94) 5948 (+150) 1305 (+126) 21.94% (+1.61%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#194) 151 112 74.17%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a new container-scan command that leverages Trivy to scan container images for vulnerabilities, and adjusts configuration/validation paths so it can run without a codacy.yaml. It also updates the Trivy SARIF expected output and adds comprehensive tests around the new behavior and arguments.

Changes:

  • Add container-scan Cobra command, including image-name validation, Trivy auto-install/lookup, error handling, and argument construction for Trivy.
  • Exempt container-scan from configuration validation and from requiring an existing codacy.yaml when invoked from main.
  • Update Trivy SARIF expected output fixture to account for new vulnerability findings and rule indices, and add extensive unit tests for the new command and helpers.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
plugins/tools/trivy/test/expected.sarif Updates the expected Trivy SARIF output (including a new eslint CVE entry and adjusted ruleIndex values) to align tests with the current Trivy behavior.
cmd/validation.go Extends the shouldSkipValidation list so container-scan bypasses codacy.yaml validation, matching its design to work without project config.
cmd/container_scan.go Implements the container-scan command, including Docker image name validation, Trivy path resolution and installation, scan execution with stderr classification between “scan failed” vs “vulns found”, and argument building based on flags.
cmd/container_scan_test.go Adds unit tests covering getTrivyPath, executeContainerScan exit-code behavior, image name validation, Trivy argument construction, command argument rules, flag defaults, and the validation-skip behavior for container-scan.
cli-v2.go Adjusts main so container-scan is treated like init/update/version/help and can run even when the project configuration file is missing or invalid.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +196 to +200
trivyPath, err := getTrivyPath()
if err != nil {
handleTrivyNotFound(err)
return 2
}
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

executeContainerScan both calls handleTrivyNotFound(err) (which invokes exitFunc(2)) and then returns 2, which runContainerScan passes again to exitFunc. In production this double-exit isn’t observable because os.Exit terminates the process immediately, but it mixes responsibilities for exiting between lower- and higher-level helpers and forces the tests to stub exitFunc around both places. To simplify control flow and make the code easier to reason about and test, consider having executeContainerScan only return an exit code (for example by changing handleTrivyNotFound to just log and return a code) and let runContainerScan be the single place that calls exitFunc.

Copilot uses AI. Check for mistakes.
args = append(args, "--ignore-unfixed")
}

// Apply --severity (use default if not specified)
Copy link
Contributor

@franciscoovazevedo franciscoovazevedo Feb 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

"--scanners", "vuln",
}

// Apply --ignore-unfixed if enabled (default: true)
Copy link
Contributor

@franciscoovazevedo franciscoovazevedo Feb 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should not allow users to define this flags

}
args = append(args, "--severity", severity)

// Apply --pkg-types (use default if not specified)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

flags are removed

…s flags. Default values for severity and package types are now hardcoded in the buildTrivyArgs function. Updated related tests to reflect these changes.
@andrzej-janczak andrzej-janczak merged commit da0cd76 into main Feb 2, 2026
10 checks passed
@andrzej-janczak andrzej-janczak deleted the feature/container-scan branch February 2, 2026 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants