When resolving Terraform modules from registry, Trivy does not utilize remote service discovery #7982
Replies: 2 comments 4 replies
-
That's right, Trivy does not currently support remote service discovery. |
Beta Was this translation helpful? Give feedback.
-
I'm experiencing basically what @marcinbelczewski has said I'm working on trying to migrate from tfsec to trivy currently, and we utilize GitLab self-hosted with GitLab Terraform Registry. I help with devsecops pipelines for a team with hundreds upon hundreds of published internal module versions inside a private registry. With Trivy, I'm seeing the following log
Gitlab's documentation also shows a different endpoint schema https://docs.gitlab.com/ee/api/packages/terraform-modules.html#list-available-versions-for-a-specific-module :
However, if I were to run
The logs from terraform show the proper versions endpoint:
would you concur this is the same issue? |
Beta Was this translation helpful? Give feedback.
-
Description
This is the same problem as described in closed discussion #7777 however, here I can provide all the necessary details.
When scanning Terraform code containing definition of a module source from the private Terraform registry, Trivy assumes certain endpoints URLs, which are invalid for example for Terraform registries deployed on JFrog Artifactory.
Desired Behavior
Trivy is able to utilize Terraform HTTP API's Remote Service Discovery to resolve endpoints of private Terraform registries, with URL schemes different than those of public Terraform Registry.
Actual Behavior
Trivy fails with HTTP 404 because it assumes private Terraform registries will have URL scheme exactly the same as public Terraform Registry.
Reproduction Steps
As can be seen, Trivy assumes
https://repo.example.com/v1/modules/
URL scheme for the registry to download the module, however, the actual URL scheme can be learned by utilizing Terraform Registry HTTP API Remote Service Discovery:As can be seen above, the correct URL scheme to download the module should be:
https://repo.example.com/artifactory/api/terraform/v1/modules/
rather than
https://repo.example.com/v1/modules/
Trivy used.Trivy should preferrably utilize the same discovery mechanism that Terraform CLI does:
DiscoverServiceUrl method from terraform-svchost package
Terraform CLI code for endpoints discovery
Operating System
MacOs 14
Version
2024-11-21T19:34:40+01:00 INFO Loaded file_path="trivy.yaml" Version: 0.57.0 Check Bundle: Digest: sha256:b381d8e123c2568845a65f751635033051b076e66c460ab0037b4084845c19de DownloadedAt: 2024-11-21 08:44:39.470903 +0000 UTC
Checklist
trivy clean --all
Beta Was this translation helpful? Give feedback.
All reactions