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

Add a Markdown format template #3201

Closed
ohmer opened this issue Nov 19, 2022 · 21 comments
Closed

Add a Markdown format template #3201

ohmer opened this issue Nov 19, 2022 · 21 comments
Labels
kind/feature Categorizes issue or PR as related to a new feature.

Comments

@ohmer
Copy link

ohmer commented Nov 19, 2022

Hi there,

Not exactly a feature request, more of an humble proposal to include a new report formatter.

I am using Trivy in GitHub Actions to scan container images. I wanted to make report easy to read in the context of a PR check. SARIF looked like great way to get there but I do not have Advanced Security. So I created a report template that generates Markdown compatible HTML to reach my goal. Maybe it could be useful to the community hence this proposal.

Here is how it looks like when added to a job summary:

image

Note that the CVE link is automatically generated by GitHub which leads to similar references as in the report.

Example of usage:

  trivy:
    name: Trivy scan
    runs-on: ubuntu-latest
    needs: build
    steps:
      - uses: actions/checkout@v3
      - uses: actions/download-artifact@v3
        with:
          name: build
          path: .
      - run: mkdir oci && tar -C oci -xf ${{ github.sha }}.tar
      - uses: aquasecurity/trivy-action@master
        with:
          input: oci
          format: template
          template: "@trivy/github-markdown.tpl"
          output: trivy.md
          security-checks: vuln
          ignore-unfixed: true
          severity: CRITICAL,HIGH
          exit-code: 1
      - run: cat trivy.md >> $GITHUB_STEP_SUMMARY
        if: always()
@ohmer ohmer added the kind/feature Categorizes issue or PR as related to a new feature. label Nov 19, 2022
@knqyf263
Copy link
Collaborator

Thanks for your proposal. Please let us see how much this feature is needed in the community to decide if we will accept this proposal.

@michadvorak-cen38289
Copy link

Just stumbled on the exactly same issue, please add this template, thanks!

@michadvorak-cen38289
Copy link

michadvorak-cen38289 commented Nov 29, 2022

@ohmer You can actually output directly to step summary, even thou it is missing in the documentation (I'm pretty sure by accident), via ${{ github.step_summary }}

- uses: aquasecurity/trivy-action@master
  with:
    format: template
    template: "@trivy/github-markdown.tpl"
    output: ${{ github.step_summary }}

@saerosV
Copy link

saerosV commented Dec 7, 2022

I think this is a great addition to Trivy, it would greatly benefit people who don't have access to GitHub Advanced Security.

A similar feature was already proposed and discussed earlier this year, in the Trivy Action repository, but the maintainers there apparently put it on hold.

@knqyf263

@knqyf263
Copy link
Collaborator

knqyf263 commented Dec 8, 2022

Thank you guys for your thoughts. We'll look into @ohmer's PR.

@github-actions
Copy link

github-actions bot commented Feb 7, 2023

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 Feb 7, 2023
@tperka-catalogicsoftware

Is it implemented now? I would also love to use this

@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 Feb 11, 2023
@saerosV
Copy link

saerosV commented Feb 16, 2023

@michadvorak-cen38289

Were you able to make the following piece of code work, with an existing format or template?

- uses: aquasecurity/trivy-action@master
  with:
    format: template
    template: "@trivy/github-markdown.tpl"
    output: ${{ github.step_summary }}

I tested it with the markdown template ("@trivy/github-markdown.tpl") and other formats, but all I got in return was the following error:

flag error: report flag error: failed to create an output file: open /home/runner/work/_temp/_runner_file_commands/step_summary_id-number: no such file or directory

@dstrates
Copy link

dstrates commented Feb 16, 2023

@michadvorak-cen38289 @saerosV

I'm receiving the same error in a GitHub hosted runner. Any tips?

I assumed the markdown template needs to exist in the GitHub workspace context and that we prefix this with @ (i.e. "@github-markdown.tpl") as per the documentation examples.

@saerosV
Copy link

saerosV commented Feb 16, 2023

Hi @dstrates.

Correct, the template needs to exist.

I tested using the HTML template:

format: template
template: "@/contrib/html.tpl"
output: ${{ github.step_summary }}

and the table format, but still got the same results.

@dstrates
Copy link

FWIW ohmer's original example works fine with the separate step:

      - uses: aquasecurity/trivy-action@master
        with:
          input: oci
          format: template
          template: "@trivy/github-markdown.tpl"
          output: trivy.md
          security-checks: vuln
          ignore-unfixed: true
          severity: CRITICAL,HIGH
          exit-code: 1
  - run: cat trivy.md >> $GITHUB_STEP_SUMMARY
        if: always()

@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 18, 2023
@saerosV
Copy link

saerosV commented Apr 18, 2023

This issue can now be closed since #3202 (related PR) was also closed.

@itaysk.

@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 Apr 19, 2023
@itaysk itaysk closed this as not planned Won't fix, can't repro, duplicate, stale Apr 19, 2023
@AshwinSarimin
Copy link

AshwinSarimin commented Feb 15, 2024

I have solved this by creating the markdown.tpl in the repository, with the content provided by ohmer (https://github.com/aquasecurity/trivy/pull/3202/files), and with the following code I am able to the results in the job summary:

- name: Run Trivy config scanner - High,Critical
      uses: aquasecurity/trivy-action@master
      with:
        scan-ref: ${{ inputs.moduleFolderPath }}
        scan-type: 'config'
        hide-progress: false
        exit-code: '1'
        ignore-unfixed: true
        severity: 'CRITICAL,HIGH'
        format: template
        template: "@/github/workspace/software/trivy/templates/markdown.tpl"
        output: trivy-high-critical.md

Because the Trivy scanner runs inside a docker instance, it mounts the checked out repository as a volume inside that container. The volume is mounted as:

-v "/home/runner/work/REPOSITORY":"/github/workspace"

So to be able the retrieve the markdown template from the repository I have to use '@/github/workspace/' and then the template file location (software/trivy/templates/markdown.tpl)

Not my preferred way of doing this, but it works.

@pantelis-karamolegkos
Copy link

does this template 👉🏻 @trivy/github-markdown.tpl still exist?
does it need to be fetched locally or is the reference made directly to the remote repo of trivy?

I am getting the following error

Fatal error	report error: unable to write results: failed to initialize template writer: error retrieving template from path: open trivy/github-markdown.tpl: no such file or directory

@itaysk
Copy link
Contributor

itaysk commented May 30, 2024

trivy never had a build it markdown template #3202 (comment)

@pantelis-karamolegkos
Copy link

What is the usefulness of the github output type? The output is not readable in the step summary when using it.

@pantelis-karamolegkos
Copy link

pantelis-karamolegkos commented Jun 10, 2024

So @itaysk the github format is only for dependency information and does not produce reports for image vulnerabilities?

edit: I mean it cannot be used to update the GitHub actions summary with a report of the vulnerabilities found?

@itaysk
Copy link
Contributor

itaysk commented Jun 13, 2024

yes github format was created only for github's dependencies tab integration

@VegardEikenes
Copy link

This feature is still needed, especially when using reusable workflows. This should be easy to implement, as the template is already written.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature Categorizes issue or PR as related to a new feature.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants