Skip to content

Conversation

@DmitriyLewen
Copy link
Contributor

@DmitriyLewen DmitriyLewen commented Sep 4, 2025

Description

There is a problem with xhttp.Client — Trivy aws-sdk cannot connect to IMDS.
That is why some users cannot get credentials.

The aws docs recommend using BuildableClienthttps://docs.aws.amazon.com/sdk-for-go/v2/developer-guide/configure-http.html

This PR changes xhttp.Client to BuildableClient with the insecure option.

Related issues

Related PRs

Checklist

  • I've read the guidelines for contributing to this repository.
  • I've followed the conventions in the PR title.
  • I've added tests that prove my fix is effective or that my feature works.
  • I've updated the documentation with the relevant information (if needed).
  • I've added usage information (if the PR introduces new options)
  • I've included a "before" and "after" example to the description (if the PR is a user interface change).

@DmitriyLewen DmitriyLewen self-assigned this Sep 4, 2025
@DmitriyLewen DmitriyLewen marked this pull request as ready for review September 4, 2025 14:14
@knqyf263
Copy link
Collaborator

knqyf263 commented Sep 8, 2025

@DmitriyLewen Did you figure out how BuidlableClient is different from xhttp.Client? I don't see any critical differences.
https://github.com/aws/aws-sdk-go-v2/blob/1cdc15880e2f5087470b6f813eb0a5cd1451c95f/aws/transport/http/client.go#L180-L198

@DmitriyLewen
Copy link
Contributor Author

aws-sdk uses different values:
• KeepAlive == 30 sec (we use the default value — 15 sec)
• DualStack == true (but this field shouldn’t matter — // Deprecated: Fast Fallback is enabled by default.)
• MaxIdleConnsPerHost == 10 (we use the default value — 0, no limit)
• ForceAttemptHTTP2 == true
• TLSClientConfig.MinVersion == 771 (we use the default value — 0)

The other fields should match.
But I don’t know how this could affect it…
I can’t reproduce this case, so I can’t identify the field in Trivy’s transport that triggers the issue.

@knqyf263
Copy link
Collaborator

knqyf263 commented Sep 9, 2025

I'm confused. The default values I saw are different from the ones you mentioned. Am I missing something?

• KeepAlive == 30 sec (we use the default value — 15 sec)

Isn't the default value 30 sec in DefaultTransport?
https://github.com/golang/go/blob/6447ff409ac7e2a621bc8ca5c44b2eaed751fbaa/src/net/http/transport.go#L50

• MaxIdleConnsPerHost == 10 (we use the default value — 0, no limit)

Isn't it 2?
https://github.com/golang/go/blob/6447ff409ac7e2a621bc8ca5c44b2eaed751fbaa/src/net/http/transport.go#L59-L61

• ForceAttemptHTTP2 == true

We also set true.
https://github.com/golang/go/blob/6447ff409ac7e2a621bc8ca5c44b2eaed751fbaa/src/net/http/transport.go#L52

• TLSClientConfig.MinVersion == 771 (we use the default value — 0)

Also, the minimum version is TLS 1.2 by default.
https://github.com/golang/go/blob/6447ff409ac7e2a621bc8ca5c44b2eaed751fbaa/src/crypto/tls/common.go#L761-L768

@DmitriyLewen
Copy link
Contributor Author

Isn't the default value 30 sec in DefaultTransport?
golang/go@6447ff4/src/net/http/transport.go#L50

We overwrite this value here:

d := &net.Dialer{
Timeout: timeout,
}

Isn't it 2?
golang/go@6447ff4/src/net/http/transport.go#L59-L61

Nice catch. You are right.
https://github.com/golang/go/blob/6447ff409ac7e2a621bc8ca5c44b2eaed751fbaa/src/net/http/transport.go#L1125-L1127

We also set true.
golang/go@6447ff4/src/net/http/transport.go#L52

Oops, my mistake.

Also, the minimum version is TLS 1.2 by default.
golang/go@6447ff4/src/crypto/tls/common.go#L761-L768

I don't know why i didn't check nested package.
You are right.


So looks like we have 2 difference fields - KeepAlive and MaxIdleConnsPerHost.

@knqyf263
Copy link
Collaborator

knqyf263 commented Sep 9, 2025

looks like we have 2 difference fields - KeepAlive and MaxIdleConnsPerHost

Hmm, but they don't appaear to fail authentication...

@knqyf263
Copy link
Collaborator

knqyf263 commented Sep 9, 2025

I also discovered that, but since it seems to suppress following redirects (and it only happens with S3?), I thought it might not be related to the current issue. In any case, it’s difficult to fix without being able to reproduce it.

I don’t prefer fixing it without understanding the cause, as that could lead to the issue recurring in the future, but it might be acceptable to temporarily switch to BuildableClient, release it, and then investigate more thoroughly afterward.

@DmitriyLewen
Copy link
Contributor Author

DmitriyLewen commented Sep 9, 2025

The users who got this issue are cooperating and trying to help us reproduce the problem.
There are only three of them, so it may be better not to merge this now.
If we don’t find a solution before the release, we’ll merge this PR.

On the other hand, this is the recommended AWS solution, and we’re busy with partner tasks.
So it may indeed make sense to merge this PR.
It’s up to you to decide.

@knqyf263
Copy link
Collaborator

knqyf263 commented Sep 9, 2025

By switching to BuildableClient, an easily anticipated issue is that the configurations in x/http will not be applied. The purpose of x/http is to ensure that the same configurations (such as insecure or mTLS settings) are used consistently across all locations in Trivy, but this will no longer be achieved with BuildableClient. Ideally, this auth problem should be fixed by modifying x/http if possible.

I hope to find time to debug it further.

Copy link
Collaborator

@knqyf263 knqyf263 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried again but could not reproduce it. I will merge this PR for now and investigate further later when I have time.

@knqyf263 knqyf263 added this pull request to the merge queue Sep 30, 2025
Merged via the queue into aquasecurity:main with commit fa6f1bf Sep 30, 2025
15 checks passed
@DmitriyLewen DmitriyLewen deleted the fix/use-aws-transport branch September 30, 2025 06:14
alexlebens pushed a commit to alexlebens/infrastructure that referenced this pull request Sep 30, 2025
This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [mirror.gcr.io/aquasec/trivy](https://www.aquasec.com/products/trivy/) ([source](https://github.com/aquasecurity/trivy)) | minor | `0.66.0` -> `0.67.0` |

---

### Release Notes

<details>
<summary>aquasecurity/trivy (mirror.gcr.io/aquasec/trivy)</summary>

### [`v0.67.0`](https://github.com/aquasecurity/trivy/blob/HEAD/CHANGELOG.md#0670-2025-09-30)

[Compare Source](aquasecurity/trivy@v0.66.0...v0.67.0)

##### Features

- add documentation URL for database lock errors ([#&#8203;9531](aquasecurity/trivy#9531)) ([eba48af](aquasecurity/trivy@eba48af))
- **cli:** change --list-all-pkgs default to true ([#&#8203;9510](aquasecurity/trivy#9510)) ([7b663d8](aquasecurity/trivy@7b663d8))
- **cloudformation:** support default values and list results in Fn::FindInMap ([#&#8203;9515](aquasecurity/trivy#9515)) ([42b3bf3](aquasecurity/trivy@42b3bf3))
- **cyclonedx:** preserve SBOM structure when scanning SBOM files with vulnerability updates ([#&#8203;9439](aquasecurity/trivy#9439)) ([aff03eb](aquasecurity/trivy@aff03eb))
- **redhat:** add os-release detection for RHEL-based images ([#&#8203;9458](aquasecurity/trivy#9458)) ([cb25a07](aquasecurity/trivy@cb25a07))
- **sbom:** added support for CoreOS ([#&#8203;9448](aquasecurity/trivy#9448)) ([6d562a3](aquasecurity/trivy@6d562a3))
- **seal:** add seal support ([#&#8203;9370](aquasecurity/trivy#9370)) ([e4af279](aquasecurity/trivy@e4af279))

##### Bug Fixes

- **aws:** use `BuildableClient` insead of `xhttp.Client` ([#&#8203;9436](aquasecurity/trivy#9436)) ([fa6f1bf](aquasecurity/trivy@fa6f1bf))
- close file descriptors and pipes on error paths ([#&#8203;9536](aquasecurity/trivy#9536)) ([a4cbd6a](aquasecurity/trivy@a4cbd6a))
- **db:** Dowload database when missing but metadata still exists ([#&#8203;9393](aquasecurity/trivy#9393)) ([92ebc7e](aquasecurity/trivy@92ebc7e))
- **k8s:** disable parallel traversal with fs cache for k8s images ([#&#8203;9534](aquasecurity/trivy#9534)) ([c0c7a6b](aquasecurity/trivy@c0c7a6b))
- **misconf:** handle tofu files in module detection ([#&#8203;9486](aquasecurity/trivy#9486)) ([bfd2f6b](aquasecurity/trivy@bfd2f6b))
- **misconf:** strip build metadata suffixes from image history ([#&#8203;9498](aquasecurity/trivy#9498)) ([c938806](aquasecurity/trivy@c938806))
- **misconf:** unmark cty values before access ([#&#8203;9495](aquasecurity/trivy#9495)) ([8e40d27](aquasecurity/trivy@8e40d27))
- **misconf:** wrap legacy ENV values in quotes to preserve spaces ([#&#8203;9497](aquasecurity/trivy#9497)) ([267a970](aquasecurity/trivy@267a970))
- **nodejs:** parse workspaces as objects for package-lock.json files ([#&#8203;9518](aquasecurity/trivy#9518)) ([404abb3](aquasecurity/trivy@404abb3))
- **nodejs:** use snapshot string as `Package.ID` for pnpm packages ([#&#8203;9330](aquasecurity/trivy#9330)) ([4517e8c](aquasecurity/trivy@4517e8c))
- **vex:** don't  suppress vulns for packages with infinity loop ([#&#8203;9465](aquasecurity/trivy#9465)) ([78f0d4a](aquasecurity/trivy@78f0d4a))
- **vuln:** compare `nuget` package names in lower case ([#&#8203;9456](aquasecurity/trivy#9456)) ([1ff9ac7](aquasecurity/trivy@1ff9ac7))

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0MS4xMTYuNiIsInVwZGF0ZWRJblZlciI6IjQxLjExNi42IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJpbWFnZSJdfQ==-->

Reviewed-on: https://gitea.alexlebens.dev/alexlebens/infrastructure/pulls/1622
Co-authored-by: Renovate Bot <[email protected]>
Co-committed-by: Renovate Bot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(aws): Trivy can't connect to IMDS to get credentials

2 participants