Closed tspearconquest closed 1 year ago
Trivy currently needs to write cache somewhere. If you don't want, you can also use Redis. https://aquasecurity.github.io/trivy/v0.32/docs/vulnerability/examples/cache/
Hi, that's issue #3040 for the fanal.db
. This is in regards to the trivy.db
file which is not the cache.
Also, I mentioned we are using this in our pipelines so it's not feasible or reasonable to even have the cache.
Now that I changed the file permissions on /trivycache/fanal/fanal.db, I expected that Trivy would honor the --skip-db-update flag, and simply open the file /trivycache/db/trivy.db for reading, but not writing.
Currently trivy seems to require that the db is opened in read/write mode, even with --skip-db-update flag passed. This is the bug.
It is not saying it will open in read only. It just says it skips downloading the database.
Yes, but if it is skipping downloading, Trivy should not need write permissions for trivy.db. So I am asking to fix the logic in opening the DB so if --skip-db-update
is passed then it will open in readonly mode. :)
Yes, I know what you meant, so it is a feature request.
This issue is stale because it has been labeled with inactivity.
Please remove the stale lifecycle :)
This issue is stale because it has been labeled with inactivity.
/remove-lifecycle stale
This issue is stale because it has been labeled with inactivity.
Description
In #3040 I reported that it is not possible to run Trivy in an immutable container due to Trivy trying to write to the cache.
This issue is similar but reporting a bug with the
--skip-db-update
flag.I have tweaked my Dockerfile to allow for the fanal.db to be writable and attempted again to run Trivy.
My Dockerfile now looks as below:
As you can see, I have set the permissions to prevent the user account from overwriting the cache directory where the database is currently stored.
I do this for security reasons to protect the db from being overwritten. Because we download the DB once per hour in our pipeline, we are expecting to be able to have the image be completely immutable, but it seems that even with the
--skip-db-update
flag, Trivy is still trying to write to the path/trivycache/db/trivy.db
What did you expect to happen?
Now that I changed the file permissions on
/trivycache/fanal/fanal.db
, I expected that Trivy would honor the--skip-db-update
flag, and simply open the file/trivycache/db/trivy.db
for reading, but not writing.What happened instead?
It appears based on the debug output below, that the flag is not being honored completely.
When I looked into the code, I found that the
NewRunner
function is correctly taking the--skip-db-update
flag, however it is not checking the flag in this code. Instead it is passing it straight toinitDB
on line 120.Furthermore, in the
initDB
function, I can see that it is also correctly taking the flag, however in here it also is not checking the flag. I can see the flag is passed on toDownloadDB
in line 275. This function succeeds, and then the code continues on todb.Init
on line 283.From there, it is passed into the
aquasecurity/trivy-db
module code in theInit
function on line 61 ofdb.go
wherein there is a sanity check of the DB which tries to delete the DB if it is corrupt, or tries to open the DB with write permission on line 76.This DB was just freshly downloaded since I had just created this image, so it appears that there are 2 bugs.
The first bug is that the DB should not be erased if it is corrupt when the
--skip-db-update
flag is passed. Instead it should throw an error about the DB being corrupt, and Trivy should exit.The second bug is that the code should not be trying to open the DB with write permissions when
--skip-db-update
is passed on the command line.Output of run with
-debug
:Output of
trivy -v
:Additional details (base image name, container registry info...):