Harden model downloads, output disclosure, and supply chain - #1
Merged
Conversation
Addresses a 7-finding security review of the model registry and container build. No behavior change for trusted zoo models. - Model download size caps (registry): per-model byte cap enforced on the declared Content-Length and again as a running total, plus a total-cache byte cap. New settings CORALAPI_MAX_MODEL_BYTES and CORALAPI_MAX_MODEL_CACHE_BYTES; label sidecars get a tight own cap. - Optional model integrity pinning via CORALAPI_MODEL_CHECKSUMS: a download whose sha256 does not match is deleted and rejected. - Image format allowlist via CORALAPI_ALLOWED_IMAGE_FORMATS (415 on a disallowed decoded format); full PIL content validation still runs. - Stop leaking internals: /v1/reset failures route through errors.py; /v1/models returns filenames not absolute paths; /readyz, /v1/status, and the reset response report device counts, not sysfs paths. - Supply chain: pin the uv image by version and verify the libedgetpu .deb and any URL-sourced tflite wheel against a sha256 build-arg. - Bound the K8s models emptyDir with sizeLimit: 5Gi. Docs: README config table, build profiles, and security model; SECURITY.md. Tests: byte caps, checksum match/mismatch, path redaction, format allowlist, reset error-leak. 108 passing.
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.
Security-hardening pass on the model registry and container build, from a 7-finding review. No behavior change for trusted zoo models; the mocked suite (108 tests) passes and a full default-profile
docker buildsucceeds.Findings addressed
registry._fetchnow enforces a per-model byte cap twice: it rejects a declaredContent-Lengthover the limit, then tracks a running total during streaming so a lying server can't overshoot (partial.partcleaned up). Added a total-cache byte cap alongside the existing count cap. New:CORALAPI_MAX_MODEL_BYTES(256 MB),CORALAPI_MAX_MODEL_CACHE_BYTES(4 GB); label sidecars get a tight 16 MB cap.CORALAPI_ALLOWED_IMAGE_FORMATS(opt-in) → 415 on a disallowed decoded format. Full PIL content validation still runs regardless./v1/resetfailures route througherrors.pyinstead of returningstr(exc).CORALAPI_MODEL_CHECKSUMS; a mismatched download is deleted and rejected.uvby version (was:latest) and verifies thelibedgetpu.deb and any URL-sourcedtflitewheel against asha256sumbuild-arg, failing the build on mismatch./v1/modelsreturns filenames not absolute paths;/readyz,/v1/status, and the reset response report device counts, not sysfs paths.sizeLimit: 5Gi.Verification
ruff check/ruff format --checkclean.docker buildof the default (avx2) profile succeeds, exercising the new checksum verification and uv pin.Redeploy note
Rebuilding the compat profile now requires passing its libedgetpu checksum (documented in the README build-profiles table):
--build-arg LIBEDGETPU_SHA256=4ffb6c2251b61535afb6b368d821211a914d2d4783770ec7e6001c073c2d193b