Skip to content

feat(echo): Add Echo Support #528

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 28 commits into from
May 29, 2025
Merged

Conversation

orizerah
Copy link
Contributor

@orizerah orizerah commented May 6, 2025

Adding support for Echo Images to Trivy

Vuln List Pull Request: vuln-list-update
Relevant Discussion: aquasecurity/trivy#8834

@orizerah orizerah requested a review from knqyf263 as a code owner May 6, 2025 16:25
@CLAassistant
Copy link

CLAassistant commented May 6, 2025

CLA assistant check
All committers have signed the CLA.

orizerah and others added 15 commits May 19, 2025 13:22
…ecurity#503)

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
…e elsa ids for aqua storage,remove them before saving into oss db (aquasecurity#484)

Co-authored-by: DmitriyLewen <[email protected]>
…ty#526)

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: DmitriyLewen <[email protected]>
Comment on lines 25 to 26
echoDir = "echo"
distroName = "echo"
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can use distroName as dir name to avoid creating two constants with the same values.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done 👍

if err := json.NewDecoder(f).Decode(&advisory); err != nil {
return eb.With("file_path", filePath).Wrapf(err, "json decode error")
}
advisoryMap[pkgName] = advisory
Copy link
Contributor

@DmitriyLewen DmitriyLewen May 21, 2025

Choose a reason for hiding this comment

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

You'll still check the advisory in another cycle later.
Perhaps we can save package here?

Copy link
Contributor Author

@orizerah orizerah May 21, 2025

Choose a reason for hiding this comment

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

@DmitriyLewen
I'm not sure I understand, you mean to save the package vulnerabilities separately for each package?

Copy link
Contributor

@DmitriyLewen DmitriyLewen May 21, 2025

Choose a reason for hiding this comment

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

Never mind. I looked at my idea again and I think your solution is good.

}
}

ids := strings.Fields(cveID)
Copy link
Contributor

Choose a reason for hiding this comment

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

can there be several CVEs 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.

Nope, only one. Fixed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you also add test for Get fucntion?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added 👍

if err != nil {
return eb.With("file_path", filePath).Wrapf(err, "failed to open file")
}
defer f.Close()
Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest small refactoring to avoid using defer in loop:

diff --git a/pkg/vulnsrc/echo/echo.go b/pkg/vulnsrc/echo/echo.go
index c103ac3..ddb109b 100644
--- a/pkg/vulnsrc/echo/echo.go
+++ b/pkg/vulnsrc/echo/echo.go
@@ -63,17 +63,9 @@ func (vs VulnSrc) Update(dir string) error {
 			continue
 		}
 
-		filePath := filepath.Join(rootDir, entry.Name())
-		f, err := os.Open(filePath)
+		pkgName, advisory, err := vs.readAdvisory(rootDir, entry.Name())
 		if err != nil {
-			return eb.With("file_path", filePath).Wrapf(err, "failed to open file")
-		}
-		defer f.Close()
-
-		pkgName := strings.TrimSuffix(entry.Name(), filepath.Ext(entry.Name()))
-		var advisory Advisory
-		if err := json.NewDecoder(f).Decode(&advisory); err != nil {
-			return eb.With("file_path", filePath).Wrapf(err, "json decode error")
+			return eb.With("file_name", entry.Name()).Wrapf(err, "failed to read advisory")
 		}
 		advisoryMap[pkgName] = advisory
 	}
@@ -85,6 +77,23 @@ func (vs VulnSrc) Update(dir string) error {
 	return nil
 }
 
+func (vs VulnSrc) readAdvisory(rootDir, fileName string) (string, Advisory, error) {
+	filePath := filepath.Join(rootDir, fileName)
+	f, err := os.Open(filePath)
+	if err != nil {
+		return "", Advisory{}, oops.Wrapf(err, "failed to open file")
+	}
+	defer f.Close()
+
+	pkgName := strings.TrimSuffix(fileName, filepath.Ext(fileName))
+	var advisory Advisory
+	if err := json.NewDecoder(f).Decode(&advisory); err != nil {
+		return "", Advisory{}, oops.Wrapf(err, "json decode error")
+	}
+
+	return pkgName, advisory, nil
+}
+
 func (vs VulnSrc) save(advisoryMap map[string]Advisory) error {
 	err := vs.dbc.BatchUpdate(func(tx *bolt.Tx) error {
 		if err := vs.dbc.PutDataSource(tx, distroName, source); err != nil {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done :)

@orizerah
Copy link
Contributor Author

@DmitriyLewen I went through all of the comments

}
}

func Test_readPackageAdvisory(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is too much :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Haha okay, I removed it.

@DmitriyLewen
Copy link
Contributor

and one more ask:
Can you run Trivy DB workflow in your fork and create container with new trivy-db (e.g. in ghcr.io)?

To show that new trivy-db contains echo advisories

@orizerah
Copy link
Contributor Author

@DmitriyLewen I see now that the vuln-list-update pr was reverted, so vuln-list doesn't contain the Echo advisory

@DmitriyLewen
Copy link
Contributor

workflow should take vuln-list of repo owner (so from your fork)

@orizerah
Copy link
Contributor Author

@DmitriyLewen It's running.
https://github.com/orizerah/trivy-db/actions/runs/15162449074/job/42631579054

Should I re-open the vuln-list-update pr?

@DmitriyLewen
Copy link
Contributor

DmitriyLewen commented May 21, 2025

It's running.

You may need to add credentials for DockerHub and ECR or remove the steps to login and download them (i do the similar for trivy-java-db - aquasecurity/trivy-java-db@c200179).

Should I re-open the vuln-list-update pr?

Don't need it now, we will write about it later

@orizerah
Copy link
Contributor Author

I ran the workflow
https://github.com/orizerah/trivy-db/actions/runs/15163318963/job/42634524060
You can pull it from
oras pull ghcr.io/orizerah/trivy-db:latest

@DmitriyLewen
Copy link
Contributor

@orizerah FYI - i did small renaming for function names and variables - 471d20b

Copy link
Contributor

@DmitriyLewen DmitriyLewen left a comment

Choose a reason for hiding this comment

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

LGTM
@orizerah Thanks for your contribution!

cc. @knqyf263

@DmitriyLewen
Copy link
Contributor

DmitriyLewen commented May 22, 2025

@orizerah I found the following case:
изображение

Does it mean that all version are affected?

@orizerah
Copy link
Contributor Author

orizerah commented May 22, 2025

@DmitriyLewen Umm no, it means it's fixed in all versions

@DmitriyLewen
Copy link
Contributor

hmm.. this is a bit weird, but okay.
let's use this. We can change it later (if needed).

@knqyf263
Copy link
Collaborator

@DmitriyLewen Umm no, it means it's fixed in all versions

In that case, we don't need to insert the record, right? This advisory will not detect any vulnerabilities.

@orizerah
Copy link
Contributor Author

We can remove these rows from our published advisory instead. That way there is no need for special use cases in trivy-db.

@knqyf263
Copy link
Collaborator

We can remove these rows from our published advisory instead. That way there is no need for special use cases in trivy-db.

That would be great.

@orizerah
Copy link
Contributor Author

@knqyf263 Done

@knqyf263
Copy link
Collaborator

@DmitriyLewen Would you check if this PR works once vuln-list is updated?

@DmitriyLewen
Copy link
Contributor

I just ran vuln-list update to check this - https://github.com/aquasecurity/vuln-list-update/actions/runs/15317997089/job/43095416156

@DmitriyLewen
Copy link
Contributor

I can confirm that trivy-db build from new vuln-list contains echo advisories:
изображение

@DmitriyLewen DmitriyLewen added this pull request to the merge queue May 29, 2025
Merged via the queue into aquasecurity:main with commit 0ee57d4 May 29, 2025
2 checks passed
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.

7 participants