Skip to content

build(docker): harden geo-database downloads in Dockerfile#2294

Open
Tsunami43 wants to merge 1 commit into
lavanet:mainfrom
Tsunami43:fix/dockerfile-geo-download-hardening
Open

build(docker): harden geo-database downloads in Dockerfile#2294
Tsunami43 wants to merge 1 commit into
lavanet:mainfrom
Tsunami43:fix/dockerfile-geo-download-hardening

Conversation

@Tsunami43

Copy link
Copy Markdown

The two curl calls that fetch the IP geolocation databases (ip2asn-v4.tsv.gz, countries.csv) had no error or integrity checking:

  1. RUN curl https://iptoasn.com/data/ip2asn-v4.tsv.gz -o /tmp/...
  2. RUN curl https://storage.googleapis.com/.../countries.csv -o /tmp/...

Without -f, curl exits 0 on an HTTP 4xx/5xx and writes the error page body into the output file. The build then succeeds and the image silently ships a corrupt geo database. There was also no verification that the downloaded payload is what was expected.

Changes:

  • Add -fsSL so curl fails loudly on HTTP errors and follows redirects.
  • Add test -s after each download (and after gunzip) so an empty or
    truncated file fails the build instead of being baked into the image.
  • Add optional IP2ASN_SHA256 / COUNTRIES_SHA256 build args; when set, the download is checksum-verified with sha256sum -c. They default to empty (skipped) because the ip2asn dataset is refreshed upstream frequently, so operators can pin a known-good digest at build time without breaking the default build.

The two `curl` calls that fetch the IP geolocation databases
(ip2asn-v4.tsv.gz, countries.csv) had no error or integrity checking:

  RUN curl https://iptoasn.com/data/ip2asn-v4.tsv.gz -o /tmp/...
  RUN curl https://storage.googleapis.com/.../countries.csv -o /tmp/...

Without `-f`, curl exits 0 on an HTTP 4xx/5xx and writes the error
page body into the output file. The build then succeeds and the image
silently ships a corrupt geo database. There was also no verification
that the downloaded payload is what was expected.

Changes:
- Add `-fsSL` so curl fails loudly on HTTP errors and follows redirects.
- Add `test -s` after each download (and after gunzip) so an empty or
  truncated file fails the build instead of being baked into the image.
- Add optional `IP2ASN_SHA256` / `COUNTRIES_SHA256` build args; when
set,
  the download is checksum-verified with `sha256sum -c`. They default to
  empty (skipped) because the ip2asn dataset is refreshed upstream
  frequently, so operators can pin a known-good digest at build time
  without breaking the default build.

Note: the bucket name `lavanet-public-asssets` (triple-s) is the actual
GCS bucket and is intentionally left unchanged.
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant