Skip to content

fix: report the failing URL when install.sh download fails - #11734

Open
1ub7 wants to merge 2 commits into
aquasecurity:mainfrom
1ub7:fix/install-sh-download-errors
Open

1ub7 wants to merge 2 commits into
aquasecurity:mainfrom
1ub7:fix/install-sh-download-errors

Conversation

@1ub7

@1ub7 1ub7 commented Nov 25, 2026 •

Copy link
Copy Markdown

Description

contrib/install.sh runs with set -e. In http_download_curl, the assignment
code=$(curl ...) exits the whole script as soon as curl itself fails
(DNS failure, connection refused, blocked egress, ...), before the error
handling below it runs. Combined with curl -s, users only see the exit code
with no URL or reason.

Users hit this during the recent get.trivy.dev DNS outage (#11533), where
CI logs only showed Process completed with exit code 6. The same silent
failure happens in CI environments that restrict egress and do not allow
get.trivy.dev.

This PR:

  • captures the curl/wget exit code with || rc=$? and logs the failing URL
    and exit code with log_err
  • keeps the same exit code as before, so existing callers are not affected
  • reports non-200 HTTP responses with log_err instead of log_debug
    (which is hidden by default)
  • shows curl's own error message by using -sSL instead of -sL
    (e.g. curl: (6) Could not resolve host: get.trivy.dev)
  • also improves the tag lookup path (github_release → http_copy): previously only
    "unable to find ''" was shown; now the failing github.com/.../releases/<tag> URL
    and curl's exit code are reported as well

It does not change the download host or the download logic.

How to reproduce

Make get.trivy.dev unreachable inside a container:

docker run --rm --add-host get.trivy.dev:127.0.0.1 -v "$PWD:/src" -w /src alpine \
  sh -c 'apk add -q curl >/dev/null; sh contrib/install.sh -b /tmp/b v0.76.1; echo "exit=$?"'

Before

aquasecurity/trivy info checking GitHub for tag 'v0.76.1'
aquasecurity/trivy info found version: 0.76.1 for v0.76.1/Linux/64bit
exit=7

After

aquasecurity/trivy info checking GitHub for tag 'v0.76.1'
aquasecurity/trivy info found version: 0.76.1 for v0.76.1/Linux/64bit
curl: (7) Failed to connect to get.trivy.dev:443 after 9 ms: Could not connect to server
aquasecurity/trivy err failed to download https://get.trivy.dev/trivy?os=Linux&arch=64bit&version=0.76.1&type=tar.gz&client=install-script (curl exit code 7)
exit=7

Success path (unchanged)

aquasecurity/trivy info checking GitHub for tag 'v0.76.1'
aquasecurity/trivy info found version: 0.76.1 for v0.76.1/Linux/64bit
aquasecurity/trivy info installed /tmp/b/trivy
exit=0

Related issues

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.
    • There are no automated tests for contrib/install.sh. Verified manually with the
      reproduction above (dash and bash, curl and wget-only environments); shellcheck reports no warnings.
  • I've updated the documentation with the relevant information (if needed).
    • Not needed: no behavior or option changes.
  • I've added usage information (if the PR introduces new options)
    • Not applicable: no new options.
  • I've included a "before" and "after" example to the description (if the PR is a user interface change).

@jamesconwaydev jamesconwaydev left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks for this. It's a real pain to debug in CI when all you get is exit code 6. Read only, didn't run it. I traced both paths that reach the new messages on main's contrib/install.sh:

  • Tarball and checksum (execute, lines 59-60): these are plain calls, so set -e applies. The new return "$rc" propagates out of http_download and the script still exits with curl's code, as you say. A 404 used to exit 1 with nothing printed, because log_debug is hidden at the default _logp=6 (line 144). Now it prints at err.
  • Tag lookup (github_release via http_copy, lines 299/309, called as REALTAG=$(github_release ...) && true at line 79): here set -e is suspended inside the function, so on main a curl failure fell through with code=000 and only "unable to find 'v0.76.1'" appeared. With this PR the failing github.com/.../releases/<tag> URL and curl's exit code also appear on stderr (log_err uses echoerr), so that path improves too. That's worth a line in the description.

One small suggestion: curl's -sL could become -sSL. -S keeps the progress meter off but still prints curl's own reason, e.g. curl: (6) Could not resolve host: get.trivy.dev, so users get the cause and not just the number. It's a one-character change in both branches, and it doesn't touch the -w '%{http_code}' output that gets captured into code.

@1ub7

1ub7 commented Nov 27, 2026

Copy link
Copy Markdown
Author

@jamesconwaydev
Thanks for the careful review!

  • Switched both curl calls to -sSL in 1e75e00. curl's reason now shows up on stderr,
    and code still only captures the -w '%{http_code}' output.
  • Updated the description to mention the tag lookup path as well.

Re-tested with --add-host get.trivy.dev:127.0.0.1:

aquasecurity/trivy info checking GitHub for tag 'v0.76.1'
aquasecurity/trivy info found version: 0.76.1 for v0.76.1/Linux/64bit
curl: (7) Failed to connect to get.trivy.dev:443 after 9 ms: Could not connect to server
aquasecurity/trivy err failed to download https://get.trivy.dev/trivy?os=Linux&arch=64bit&version=0.76.1&type=tar.gz&client=install-script (curl exit code 7)
exit=7

@jamesconwaydev jamesconwaydev left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

1e75e00 reads right to me (read only, I didn't run it). With -S curl's own reason lands on stderr, and since -w '%{http_code}' is the only thing on stdout, code stays clean.

I also followed the tag lookup, since it goes through the same function now. A tag that doesn't exist gets a 404 from github_release, so you'll see failed to download https://github.com/aquasecurity/trivy/releases/vX (HTTP status 404) and then the existing unable to find 'vX' line. That reads as useful context to me rather than noise, but it is a new line on that path, so worth a mention for the maintainers.

This branch has not been deployed

No deployments
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.

2 participants