Skip to content
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

tar ball scanning broken #120

Closed
timdittler opened this issue Jun 9, 2022 · 9 comments · Fixed by #134
Closed

tar ball scanning broken #120

timdittler opened this issue Jun 9, 2022 · 9 comments · Fixed by #134
Labels
documentation Improvements or additions to documentation question Further information is requested

Comments

@timdittler
Copy link

Thanks for providing trivy and the action. I'm trying to supply input to scan an image directly after building it. The action fails like this:

Running trivy with options:  --format  json --exit-code  1 --ignore-unfixed --vuln-type  os,library --severity  CRITICAL --no-progress --input /tmp/image.tar
Global options:  
[20](https://github.com/org/repo/runs/6794428833?check_suite_focus=true#step:8:21)22-06-08T13:33:04.686Z	INFO	Need to update DB
2022-06-08T13:33:04.686Z	INFO	DB Repository: ghcr.io/aquasecurity/trivy-db
2022-06-08T13:33:04.686Z	INFO	Downloading DB...
20[22](https://github.com/org/repo/runs/6794428833?check_suite_focus=true#step:8:23)-06-08T13:33:06.801Z	FATAL	image scan error: scan error: unable to initialize a scanner: unable to initialize the archive scanner: 2 errors occurred:
	* unable to open /tmp/image.tar as a Docker image: unable to open the file: open /tmp/image.tar: no such file or directory
	* unable to open /tmp/image.tar as an OCI Image: stat /tmp/image.tar/index.json: no such file or directory

Looking at #23 it seemed to work on day.

Trivy is actually trying to scan inside it's own container.
I can replicate the error locally. I have to mount the dir of the tarball to make it work

docker run -it -v /tmp:/tmp 740fe346690b "-a image" "-l /tmp/image.tar"
@timdittler
Copy link
Author

I can access the image if I copy it into $GITHUB_WORKSPACE, but it's not accessible in $RUNNER_TEMP.

The image is build with docker/build-push-action@v3 before, but it looks like they don't actually share the same tmp.

@simar7
Copy link
Member

simar7 commented Jun 10, 2022

hi @timdittler - thanks for the observation. I suspect something must have changed within the GitHub Action runtime that the $GITHUB_WORKSPACE and $RUNNER_TEMP are different.

Would you mind documenting this (your workaround that is)? Do you have any other ideas how we could solve it better? Open to thoughts.

@timdittler
Copy link
Author

No idea, sorry. But usually having an open issue including a workaround is the best way of documenting such limitations for me :)

@achton
Copy link
Contributor

achton commented Jun 19, 2022

Seems to me that a good starting point would be to add a test to test.bats that fails based on the above feedback, then work forward from there.

@toddbaert
Copy link

toddbaert commented Jun 21, 2022

I'm seeing the same issue. In my case, moving the tarball to $GITHUB_WORKSPACE doesn't seem to help either. The input method seems not to be usable at this point.

It definitely seems to be related to some nefarious runtime change by github. Everything works as expected running locally with https://github.com/nektos/act

@simar7
Copy link
Member

simar7 commented Jun 23, 2022

hi @toddbaert and @timdittler - just spent some time to investigate this. Looks like the following should help you:

name: build
on:
  push:
    branches:
    - master
  pull_request:
jobs:
  build:
    name: Build
    runs-on: ubuntu-20.04
    steps:
    - name: Checkout code
      uses: actions/checkout@v2

    - name: Generate tarball from image
      run: |
        docker pull <your-docker-image>
        docker save -o vuln-image.tar <your-docker-image>
        
    - name: Run Trivy vulnerability scanner in tarball mode
      uses: aquasecurity/trivy-action@master
      with:
        input: /github/workspace/vuln-image.tar
        severity: 'CRITICAL,HIGH'

$GITHUB_WORKSPACE is something like /home/runner/work/<repo>/<repo> but internally inside the trivy container it is mounted at "/github/workspace".

So using /github/workspace would be the correct path internally for trivy to use.

Let me know if it helps.

@simar7 simar7 added documentation Improvements or additions to documentation question Further information is requested labels Jun 23, 2022
@timdittler
Copy link
Author

timdittler commented Jun 28, 2022 via email

@toddbaert
Copy link

@simar7 I will give this a shot later today and report back. Thanks!

@toddbaert
Copy link

@simar7 confirmed that new advice fixed my issue. Thanks for updating the doc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants