Conversation
…alidation/security gaps (log injection, decompression-bomb-style oversized images, unbounded frame decoding, unbounded camera creation), adds a documented path for injecting secrets via environment variables instead of YAML, and significantly expands the Grafana dashboard with summary stats and better-styled panels. - **Security hardening** - `src/clockd/utils/log.py` (new): `sanitize_for_log()` strips control characters/newlines from untrusted strings before logging, preventing log injection; applied to uploaded filenames in `src/clockd/routers/process.py`. - `src/clockd/routers/calibrate.py`: rejects decoded calibration images wider/taller than 16384px (`MAX_IMAGE_DIM`), guarding against decompression-bomb-style images that are small on disk but huge once decoded. - `src/clockd/services/pipeline.py`: the frame-decode loop now also enforces `MAX_FRAMES` directly (not just via container metadata validation), since metadata can under-report actual frame count; adds a warning and stops cleanly at the cap. - `src/clockd/routers/cameras.py` + `src/clockd/config.py`: new `max_cameras` server setting (default 50) caps how many cameras can be created via `POST /cameras`, returning 409 once the limit is reached. - **Secrets via environment variables** - `src/clockd/config.py`: `ServerConfig` now supports nested env vars (`env_nested_delimiter="__"`) and overrides `settings_customise_sources` so env vars take precedence over `server.yaml`, letting secrets (NVR credentials, InfluxDB tokens) be injected at deploy time (e.g. Kubernetes Secrets) instead of living in the config file. - `configs/server.yaml` and `README.md` document the new env-var override pattern and example variable names. - `deploy/k8s-example.yaml` (new): a full hardened Kubernetes Deployment example (secrets via env vars, non-root, read-only root filesystem, dropped capabilities). - **Grafana dashboard** (`grafana/clockd-dashboard.json`): adds four new stat panels (Total Detections, Vehicles >25mph, Average Speed, Top Speed), restyles the speed timeseries (smoothed lines, raw-point overlay, red threshold shading above 25mph), reworks several panels (renamed "Vehicles Detected" → "Detections", "HTTP Requests" → "Requests/sec" with proper `reqps` unit), and hides legends across timeseries panels for a cleaner layout. - **Tests**: new/updated coverage for the oversized-image rejection, frame cap enforcement, env-var/YAML precedence and nested secret merging, and camera-limit enforcement (`tests/test_calibrate.py`, `tests/test_pipeline_integration.py`, `tests/test_config.py`, `tests/test_api_cameras.py` (new), `tests/test_log_utils.py` (new)). - Files changed: 12 tracked (479 insertions, 69 deletions) + 4 new untracked files (`deploy/k8s-example.yaml`, `src/clockd/utils/log.py`, `tests/test_api_cameras.py`, `tests/test_log_utils.py`)
nathan-v
added a commit
that referenced
this pull request
Jul 14, 2026
## Summary Fixes the production CrashLoopBackOff that took Clockd offline for ~24h. Kubernetes injects legacy Docker-link env vars for every Service in a namespace: a Service named `clockd` produces `CLOCKD_PORT=tcp://<cluster-ip>:8000` in every pod. Since #1 made env vars override YAML config (for Secret-based credential injection), that injected value beat the ConfigMap's `port: 8000` and failed integer validation, crashing the app at startup on every restart. ## Changes - **`src/clockd/config.py`**: wrap the env settings source to drop `tcp://…` values for the `port` field. Real integer `CLOCKD_PORT` values still override YAML as intended. - **`deploy/k8s-example.yaml`**: set `enableServiceLinks: false` (with an explanatory comment) so the example manifest doesn't reproduce the collision. This is also the mitigation applied to the live deployment. - **`tests/test_config.py`**: three regression tests — service-link value ignored with YAML port, without YAML port, and a legitimate env port still winning. ## Testing - 151 passed locally (`pytest -q`), ruff check + format clean. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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.
This is a hardening and observability pass: it closes several input-validation/security gaps (log injection, decompression-bomb-style oversized images, unbounded frame decoding, unbounded camera creation), adds a documented path for injecting secrets via environment variables instead of YAML, and significantly expands the Grafana dashboard with summary stats and better-styled panels.
Security hardening
src/clockd/utils/log.py(new):sanitize_for_log()strips control characters/newlines from untrusted strings before logging, preventing log injection; applied to uploaded filenames insrc/clockd/routers/process.py.src/clockd/routers/calibrate.py: rejects decoded calibration images wider/taller than 16384px (MAX_IMAGE_DIM), guarding against decompression-bomb-style images that are small on disk but huge once decoded.src/clockd/services/pipeline.py: the frame-decode loop now also enforcesMAX_FRAMESdirectly (not just via container metadata validation), since metadata can under-report actual frame count; adds a warning and stops cleanly at the cap.src/clockd/routers/cameras.py+src/clockd/config.py: newmax_camerasserver setting (default 50) caps how many cameras can be created viaPOST /cameras, returning 409 once the limit is reached.Secrets via environment variables
src/clockd/config.py:ServerConfignow supports nested env vars (env_nested_delimiter="__") and overridessettings_customise_sourcesso env vars take precedence overserver.yaml, letting secrets (NVR credentials, InfluxDB tokens) be injected at deploy time (e.g. Kubernetes Secrets) instead of living in the config file.configs/server.yamlandREADME.mddocument the new env-var override pattern and example variable names.deploy/k8s-example.yaml(new): a full hardened Kubernetes Deployment example (secrets via env vars, non-root, read-only root filesystem, dropped capabilities).Grafana dashboard (
grafana/clockd-dashboard.json): adds four new stat panels (Total Detections, Vehicles >25mph, Average Speed, Top Speed), restyles the speed timeseries (smoothed lines, raw-point overlay, red threshold shading above 25mph), reworks several panels (renamed "Vehicles Detected" → "Detections", "HTTP Requests" → "Requests/sec" with properreqpsunit), and hides legends across timeseries panels for a cleaner layout.Tests: new/updated coverage for the oversized-image rejection, frame cap enforcement, env-var/YAML precedence and nested secret merging, and camera-limit enforcement (
tests/test_calibrate.py,tests/test_pipeline_integration.py,tests/test_config.py,tests/test_api_cameras.py(new),tests/test_log_utils.py(new)).Files changed: 12 tracked (479 insertions, 69 deletions) + 4 new untracked files (
deploy/k8s-example.yaml,src/clockd/utils/log.py,tests/test_api_cameras.py,tests/test_log_utils.py)