Repository navigation
Fix container vulnerabilities: upgrade dependencies and harden Docker image (v4.0.1) - #48
Merged
Merged
Conversation
Upgrade all locked dependencies with `uv lock --upgrade` to address vulnerabilities reported in the Docker image scan, and fix the issues surfaced by the upgrade: - Declare httpx as a direct dependency; it was only available transitively through openai, which now depends on httpx2. - Annotate SQL model datetime fields as NaiveDatetime, as newer sqlmodel rejects naive datetimes and reports were silently not being saved. Make CI pass again with current tooling: - Pin ruff (0.15.22) and ty (0.0.89) in the Makefile. - Update SentimentFilter to the `ranges` format sent to the search API. - Fix type errors in the metrics classes. - Fix entity tickers always being empty due to a stale `metadata_1` alias from the old SDK response. Also remove the UI section from the README, as the frontend is temporarily disabled and `/` redirects to `/docs`.
- Use a multi-stage build so build tools (build-base, openssl-dev, git, etc.) are not shipped in the runtime image. - Pin the base image (python:3.13-alpine3.24) and uv (0.13.1), and run `apk upgrade` to pick up the latest Alpine security patches. - Remove pip, curl, uv and dev dependencies from the runtime image; the healthcheck now uses Python and the app runs directly from the venv. - Build release images without cache and with a fresh base image pull, and load the image locally so the security scan checks the new build. Trivy reports 0 vulnerabilities on the new image (vs. 5 critical and 70 high on the current production image), and the image size drops from 569MB to 210MB.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Security found vulnerabilities in the Docker image caused by its age. The image is only rebuilt on release, the lockfile hadn't changed since October 2025, and the final image shipped build tools and other unneeded packages.
This PR upgrades the Python dependencies, hardens the Docker image, fixes the issues the upgrade surfaced, and gets CI passing again. It bumps the version to 4.0.1.
Trivy (0.69.0) results:
Dependency upgrade
Ran
uv lock --upgrade. The security-relevant packages are now on current versions (starlette,fastapi,urllib3,aiohttp,PyJWT,requests,certifi).Some upgrades cross major versions:
openai1.97 → 3.35starlette0.47 → 1.9,fastapi0.116 → 0.146sqlalchemy2.0 → 2.1,sqlmodel0.0.24 → 0.0.48Fixes needed after the upgrade:
sqlmodelrejects datetimes without a timezone, and the save error is caught and logged. The SQL datetime columns are nowNaiveDatetime, which keeps current behaviour and stays compatible with existing data.query_service/api.pyimportshttpx, which used to come in throughopenai(now onhttpx2). It's now declared as a direct dependency.Docker image hardening
build-base,openssl-dev,git, …) are no longer in the final image.python:3.13-alpine3.24anduv0.13.1, plusapk upgradefor the latest Alpine patches.pip(its vendored packages were being flagged),curl,uv, dev dependencies and the uv cache.python -m bigdata_briefsstraight from the venv.build.yml: the build that gets scanned now pulls a fresh base image and skips the cache, so OS patches aren't taken from a stale layer. It also loads the image locally so the scan checks this build. Previously nothing was loaded, so the scan may have been checking the previous:latest. The push step reuses the layers from the scanned build.Getting CI to pass
CI was already failing on
master: the Makefile ranuvx ruffanduvx tywithout versions, and newer releases flag existing code. Because type-check runs first, the unit tests were being skipped as well.ruffto 0.15.22 (the newest version where lint passes) andtyto 0.0.89.SentimentFilter: changed the type to therangesformat the code already sends (valuesis deprecated by the API). The request itself is unchanged.metrics.py: declaredmetrics_queueandlockon the base class, and aligned theWarningsMetrics.track_usagesignature with the base class.Entity.tickerstill read frommetadata_1, a field name left over from the old SDK, so tickers were dropped. This changes prompt output: entities now appear as e.g. "Apple (AAPL)".Other
/redirects to/docs.CHANGELOG.md: added the 4.0.1 entry and set the 4.0.0 release date (2025-11-21).Testing
make type-check,make lint-checkandmake formatall pass./healthreturns 4.0.1,/redirects to/docs, and static files load.bigdatauser, the SQLite database is written to/data, and the container reports healthy.