Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Scan Local Image using Trivy #1506

Closed
bhuvi11 opened this issue Dec 22, 2021 · 10 comments
Closed

Scan Local Image using Trivy #1506

bhuvi11 opened this issue Dec 22, 2021 · 10 comments
Assignees
Labels
triage/needs-information Indicates an issue needs more information in order to work on it. triage/support Indicates an issue that is a support question.

Comments

@bhuvi11
Copy link

bhuvi11 commented Dec 22, 2021

I am trying to use trivy to scan a image locally built in my desktop
I used the command trivy image <image_name> and got the below error

-12-22T14:25:30.920Z FATAL scan error: unable to initialize a scanner: unable to initialize a docker scanner: 3 errors occurred:
* unable to inspect the image (index.docker.io/library/pipe-test8:latest): Error: No such image: index.docker.io/library/pipe-test8:latest
* unable to initialize Podman client: no podman socket found: stat podman/podman.sock: no such file or directory
* GET https://index.docker.io/v2/library/pipe-test8/manifests/latest: UNAUTHORIZED: authentication required; [map[Action:pull Class: Name:library/pipe-test8 Type:repository]]
Can someone help me

@bhuvi11 bhuvi11 added the kind/bug Categorizes issue or PR as related to a bug. label Dec 22, 2021
@knqyf263 knqyf263 added the triage/needs-information Indicates an issue needs more information in order to work on it. label Dec 22, 2021
@knqyf263
Copy link
Collaborator

Seems like your image doesn't exist in your local Docker daemon. Please make sure the image name and tag is correct.

@sbrinkerhoff
Copy link

sbrinkerhoff commented Dec 22, 2021

Working here with a local image present (MacOS, Docker Desktop, Trivy)

❯ trivy stan:latest
2021-12-22T17:47:40.450-0500	FATAL	scan error: unable to initialize a scanner: unable to initialize a docker scanner: 3 errors occurred:
	* unable to inspect the image (index.docker.io/library/stan:latest): Error: No such image: index.docker.io/library/stan:latest
	* unable to initialize Podman client: no podman socket found: stat podman/podman.sock: no such file or directory
	* GET https://index.docker.io/v2/library/stan/manifests/latest: UNAUTHORIZED: authentication required; [map[Action:pull Class: Name:library/stan Type:repository]]
	
❯ echo "FROM nginx:latest" >> Dockerfile
❯ docker build . -t stan:latest

❯ trivy stan:latest
2021-12-22T17:48:05.992-0500	INFO	Detected OS: debian
2021-12-22T17:48:05.992-0500	INFO	Detecting Debian vulnerabilities...
2021-12-22T17:48:06.032-0500	INFO	Number of language-specific files: 1
2021-12-22T17:48:06.032-0500	INFO	Detecting jar vulnerabilities...

stan:latest (debian 11.2)
=========================
Total: 98 (UNKNOWN: 0, LOW: 83, MEDIUM: 5, HIGH: 6, CRITICAL: 4)

@hazcod
Copy link

hazcod commented Dec 30, 2021

Works for me too.

@knqyf263 knqyf263 added triage/support Indicates an issue that is a support question. and removed kind/bug Categorizes issue or PR as related to a bug. labels Jan 25, 2022
@PenelopeFudd
Copy link

PenelopeFudd commented Jan 26, 2022

Ok, I think I've got the same problem:

# docker image ls 

REPOSITORY                                                               TAG       IMAGE ID       CREATED         SIZE
999999999999.dkr.ecr.us-west-2.amazonaws.com/foobar2-edge-cache-server   latest    6626baea4fd6   2 weeks ago     3.55GB
aquasec/trivy                                                            0.22.0    51c32101009b   4 weeks ago     61MB
<none>                                                                   <none>    9eeb7053d381   2 months ago    921MB
nginx                                                                    latest    ea335eea17ab   2 months ago    141MB
999999999999.dkr.ecr.us-west-2.amazonaws.com/foobar2-edge-cache-server   <none>    00d3704627b8   2 months ago    1.16GB
<none>                                                                   <none>    ecea4ed288b9   2 months ago    1.16GB
localhost:5000/ansible-base                                              latest    84bbce9e6c36   2 months ago    922MB
ansible-base                                                             latest    cbeaf85279a5   3 months ago    855MB
osdk-foobar2:5000/docker/ansible-base                                    latest    cbeaf85279a5   3 months ago    855MB
vagrant-mutate                                                           latest    cf0d30e2a697   3 months ago    354MB
vagrantlibvirt/vagrant-libvirt                                           latest    9e33cc799237   3 months ago    732MB
ubuntu                                                                   18.04     5a214d77f5d7   3 months ago    63.1MB
registry                                                                 2         b2cb11db9d3d   4 months ago    26.2MB
ubuntu                                                                   16.04     b6f507652425   4 months ago    135MB
ubuntu                                                                   latest    1318b700e415   6 months ago    72.8MB
ubuntu                                                                   14.04     13b66b487594   10 months ago   197MB
hello-world                                                              latest    d1165f221234   10 months ago   13.3kB
node                                                                     12.16.3   bdca973cfa07   20 months ago   916MB

I can run trivy image node, trivy image node:12.6.3, or trivy image localhost:5000/ansible-base, but not trivy image "<none>" (makes no sense) or trivy image ecea4ed288b9:

# trivy image ecea4ed288b9

2022-01-26T15:47:49.322-0800	FATAL	scan error: unable to initialize a scanner: unable to initialize a docker scanner: 3 errors occurred:
	* unable to inspect the image (index.docker.io/library/ecea4ed288b9:latest): Error: No such image: index.docker.io/library/ecea4ed288b9:latest
	* unable to initialize Podman client: no podman socket found: stat podman/podman.sock: no such file or directory
	* GET https://index.docker.io/v2/library/ecea4ed288b9/manifests/latest: UNAUTHORIZED: authentication required; [map[Action:pull Class: Name:library/ecea4ed288b9 Type:repository]]

Is there a way to scan images by image id? In a forensic investigation of a live system, it would be a bad idea to modify the docker image metadata, as that would alter the evidence and could jeopardize the case.

Thanks.

@tatulea
Copy link

tatulea commented Feb 3, 2022

I'm also interested in scanning the image using image id

@github-actions
Copy link

This issue is stale because it has been labeled with inactivity.

@github-actions github-actions bot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and will be auto-closed. label Apr 13, 2022
@davehodg
Copy link

davehodg commented Jun 9, 2022

I have built a named local image and I get:

% trivy i platform    
2022-06-09T14:34:15.794+0100	FATAL	image scan error: scan error: unable to initialize a scanner: unable to initialize a docker scanner: 3 errors occurred:
	* unable to inspect the image (platform): Error: No such image: platform
	* unable to initialize Podman client: no podman socket found: stat podman/podman.sock: no such file or directory
	* GET https://index.docker.io/v2/library/platform/manifests/latest: UNAUTHORIZED: authentication required; [map[Action:pull Class: Name:library/platform Type:repository]]

Freshly brew updated trivy.

@github-actions github-actions bot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and will be auto-closed. label Jul 11, 2022
@apankowski
Copy link

TL;DR

You might have not exported the image to your local docker image cache. Without providing information on your exact setup used to build the images it's hard to tell (OS, do you use containerd, docker, buildx, which versions, etc.).

Longer version

Today I decided to include Trivy scan of docker images built for my project with GitHub Actions. Built images are local to the GitHub Actions runner host. I got (pretty much) the same error in my initial build:

2022-12-03T11:10:36.407Z	FATAL	image scan error: scan error: unable to initialize a scanner: unable to initialize a docker scanner: 4 errors occurred:
	* unable to inspect the image (apankowski/garcon:07776268f3b753caa640f474ab41eac29c25a554): Error: No such image: apankowski/garcon:07776268f3b753caa640f474ab41eac29c25a554
	* unable to initialize Podman client: no podman socket found: stat podman/podman.sock: no such file or directory
	* containerd socket not found: /run/containerd/containerd.sock
	* GET https://index.docker.io/v2/apankowski/garcon/manifests/07776268f3b753caa640f474ab41eac29c25a554: UNAUTHORIZED: authentication required; [map[Action:pull Class: Name:apankowski/garcon Type:repository]]

Initially I thought it was because I used apankowski/ prefix but that wasn't it. Inspecting the logs carefully I found this output from my image building command:

WARNING: No output specified with docker-container driver. Build result will only remain in the build cache. To push result image into registry use --push or to load image into docker use --load

This made sense -- I'm using docker buildx for building.
So, following advice in the warning message, I added --load to the build command which made buildx export the image to local docker image cache, making it visible to Trivy.

So: I suggest verifying that your build image is visible to docker using docker image ls. Also provide the exact setup you're using to build the image (OS, do you use containerd, docker, buildx, which versions, etc.)

@autarchprinceps
Copy link

I have exactly the same issue, but no --load doesn't help. Trivy doesn't use the local version, but always tries to pull from docker hub:

❯ docker images | grep test
test                                                     latest            c33738aa1932   4 minutes ago   744MB
❯ trivy i test
2023-01-11T15:50:41.776+0100	INFO	Vulnerability scanning is enabled
2023-01-11T15:50:41.777+0100	INFO	Secret scanning is enabled
2023-01-11T15:50:41.777+0100	INFO	If your scanning is slow, please try '--security-checks vuln' to disable secret scanning
2023-01-11T15:50:41.777+0100	INFO	Please see also https://aquasecurity.github.io/trivy/v0.36/docs/secret/scanning/#recommendation for faster secret detection
2023-01-11T15:50:43.258+0100	FATAL	image scan error: scan error: unable to initialize a scanner: unable to initialize a docker scanner: 4 errors occurred:
	* unable to inspect the image (test): Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
	* unable to initialize Podman client: no podman socket found: stat podman/podman.sock: no such file or directory
	* containerd socket not found: /run/containerd/containerd.sock
	* GET https://index.docker.io/v2/library/test/manifests/latest: UNAUTHORIZED: authentication required; [map[Action:pull Class: Name:library/test Type:repository]]

But testing a docker hub image works on the same machine, so clearly non of the other problems it considers are there.

❯ trivy --version
Version: 0.36.1
On Mac

@knqyf263
Copy link
Collaborator

@autarchprinceps Your issue is different from others. Trivy can't connect to the Docker daemon. Do you have special DOCKER_HOST?

  • unable to inspect the image (test): Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

@aquasecurity aquasecurity locked and limited conversation to collaborators May 10, 2023
@knqyf263 knqyf263 converted this issue into discussion #4270 May 10, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
triage/needs-information Indicates an issue needs more information in order to work on it. triage/support Indicates an issue that is a support question.
Projects
None yet
Development

No branches or pull requests

10 participants