Skip to content

"Failed to attach findings to engagement" error when sending trivy k8s scan results to DefectDojo #2271

Closed

Description

@danil-smirnov

🐞 Bug report

Describe the bug

We scan Kubernetes cluster using trivy k8s command with the flag --scanners=misconfig,rbac and the hook secureCodeBox/persistence-defectdojo fails with the following error:

Exception in thread "main" io.securecodebox.persistence.defectdojo.exception.PersistenceException: Failed to attach findings to engagement.
	at io.securecodebox.persistence.defectdojo.service.DefaultImportScanService.createFindings(DefaultImportScanService.java:124)
	at io.securecodebox.persistence.defectdojo.service.DefaultImportScanService.reimportScan(DefaultImportScanService.java:75)
	at io.securecodebox.persistence.strategies.VersionedEngagementsStrategy.run(VersionedEngagementsStrategy.java:105)
	at io.securecodebox.persistence.DefectDojoPersistenceProvider.main(DefectDojoPersistenceProvider.java:43)

Steps To Reproduce

Run trivy scan with the following yaml:

apiVersion: "execution.securecodebox.io/v1"
kind: Scan
metadata:
  name: "trivy-k8s"
spec:
  scanType: "trivy-k8s"
  parameters:
    - "--scanners"
    - "misconfig,rbac"
    - "cluster"

Check if the hook persistence-defectdojo succeeds.

Expected behavior

The hook should succeed.

System (please complete the following information):

  • operator-4.3.0
  • trivy-4.3.0
  • persistence-defectdojo-4.3.0

Google Kubernetes Engine

Client Version: version.Info{Major:"1", Minor:"25", GitVersion:"v1.25.4", GitCommit:"872a965c6c6526caa949f0c6ac028ef7aff3fb78", GitTreeState:"clean", BuildDate:"2022-11-09T13:28:30Z", GoVersion:"go1.19.3", Compiler:"gc", Platform:"darwin/arm64"}
Kustomize Version: v4.5.7
Server Version: version.Info{Major:"1", Minor:"26", GitVersion:"v1.26.10-gke.1101000", GitCommit:"375ed214cfa092ed25d2472c1709db5d7dcda078", GitTreeState:"clean", BuildDate:"2023-11-06T09:23:17Z", GoVersion:"go1.20.10 X:boringcrypto", Compiler:"gc", Platform:"linux/amd64"}

Screenshots / Logs

Additional context

Activity

  1. moved this from Backlog to Todo in secureCodeBoxon Feb 9, 2024
  2. Weltraumschaf commented on Feb 9, 2024

    @Weltraumschaf
    Member

    Hi @danil-smirnov,

    thanks for submitting this issue. We'll investigate this.

  3. self-assigned this
    on Feb 9, 2024
  4. moved this from Todo to In Progress in secureCodeBoxon Feb 9, 2024
  5. changed the title [-]"Failed to attach findings to engagement" error when sending trivy scan results to DefectDojo[/-] [+]"Failed to attach findings to engagement" error when sending trivy k8s scan results to DefectDojo[/+] on Feb 13, 2024
  6. added a commit that references this issue on Feb 13, 2024
  7. Weltraumschaf commented on Feb 13, 2024

    @Weltraumschaf
    Member

    The exception came from the defectdojo-client-java lib:

    at io.securecodebox.persistence.defectdojo.service.DefaultImportScanService.createFindings(DefaultImportScanService.java:124)
    

    The used lib version in the hook in 4.3.0 is:

    implementation group: 'io.securecodebox', name: 'defectdojo-client', version: '1.0.1'
    
  8. added a commit that references this issue on Feb 14, 2024
  9. added 4 commits that reference this issue on Feb 14, 2024
  10. Weltraumschaf commented on Feb 14, 2024

    @Weltraumschaf
    Member

    @danil-smirnov We are not sure where this error came from. In general the file upload of the findings works in the underlying code, but uploading Trivy results to DefectDojo is very rarely used. We try to reproduce this bug.

    Until then, I've improved the error logging. Frankly, the error you got is not very helpful :-| We plan release of 4.4.0 at the end of week. You can try that version and give as the full stack trace.

  11. added 4 commits that reference this issue on Feb 14, 2024
  12. danil-smirnov commented on Feb 17, 2024

    @danil-smirnov
    Author

    @Weltraumschaf Now the error message is quite clear:

    2024-02-17 09:21:18 INFO  DefectDojoPersistenceProvider:36 - Starting DefectDojo persistence provider
    2024-02-17 09:21:26 INFO  DefectDojoPersistenceProvider:42 - Downloading Scan Result
    2024-02-17 09:21:36 INFO  DefectDojoPersistenceProvider:47 - Uploading Findings to DefectDojo at: https://defectdojo.infra.mana.wtf
    2024-02-17 09:21:38 INFO  VersionedEngagementsStrategy:95 - Running with DefectDojo User Id: 1
    2024-02-17 09:21:38 INFO  VersionedEngagementsStrategy:248 - Looking for ID of ProductType 'Application'
    2024-02-17 09:21:38 INFO  VersionedEngagementsStrategy:255 - Using ProductType Id: 3
    2024-02-17 09:21:40 ERROR DefaultImportScanService:128 - Exception while attaching findings to engagement: 413 Request Entity Too Large: "<html><EOL><EOL><head><title>413 Request Entity Too Large</title></head><EOL><EOL><body><EOL><EOL><center><h1>413 Request Entity Too Large</h1></center><EOL><EOL><hr><center>nginx</center><EOL><EOL></body><EOL><EOL></html><EOL><EOL>"
    2024-02-17 09:21:40 ERROR DefectDojoPersistenceProvider:30 - Failed to attach findings to engagement.
    io.securecodebox.persistence.defectdojo.exception.PersistenceException: Failed to attach findings to engagement.
    	at io.securecodebox.persistence.defectdojo.service.DefaultImportScanService.createFindings(DefaultImportScanService.java:129)
    	at io.securecodebox.persistence.defectdojo.service.DefaultImportScanService.reimportScan(DefaultImportScanService.java:80)
    	at io.securecodebox.persistence.strategies.VersionedEngagementsStrategy.run(VersionedEngagementsStrategy.java:144)
    	at io.securecodebox.persistence.DefectDojoPersistenceProvider.execute(DefectDojoPersistenceProvider.java:50)
    	at io.securecodebox.persistence.DefectDojoPersistenceProvider.main(DefectDojoPersistenceProvider.java:28)
    Caused by: org.springframework.web.client.HttpClientErrorException: 413 Request Entity Too Large: "<html><EOL><EOL><head><title>413 Request Entity Too Large</title></head><EOL><EOL><body><EOL><EOL><center><h1>413 Request Entity Too Large</h1></center><EOL><EOL><hr><center>nginx</center><EOL><EOL></body><EOL><EOL></html><EOL><EOL>"
    	at org.springframework.web.client.HttpClientErrorException.create(HttpClientErrorException.java:145)
    	at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:168)
    	at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:122)
    	at org.springframework.web.client.ResponseErrorHandler.handleError(ResponseErrorHandler.java:63)
    	at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:825)
    	at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:783)
    	at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:717)
    	at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:608)
    	at io.securecodebox.persistence.defectdojo.service.DefaultImportScanService.exchangeRequest(DefaultImportScanService.java:135)
    	at io.securecodebox.persistence.defectdojo.service.DefaultImportScanService.createFindings(DefaultImportScanService.java:126)
    	... 4 more
    

    There were 618 findings for this scan and the result hasn't passed through the DefectDojo ingress. We fixed this via the following annotations on the DefectDojo side:

                nginx.ingress.kubernetes.io/proxy-body-size: 100m
                nginx.ingress.kubernetes.io/proxy-read-timeout: "300"
                nginx.ingress.kubernetes.io/proxy-send-timeout: "300"
    

    Closing the issue.

  13. moved this from In Progress to Done in secureCodeBoxon Feb 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions