Skip to content

Commit 1cd56de

Browse files
committed
fix: Patch security update from latest CVS
1 parent dc2b33c commit 1cd56de

10 files changed

Lines changed: 125 additions & 50 deletions

File tree

.env.example

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ TELEMETRYFLOW_SERVICE_NAME=my-service
5858
TELEMETRYFLOW_SERVICE_VERSION=1.2.0
5959
TELEMETRYFLOW_SERVICE_NAMESPACE=telemetryflow
6060
TELEMETRYFLOW_ENVIRONMENT=development
61-
TELEMETRYFLOW_INSECURE=true
61+
# SECURITY WARNING: TELEMETRYFLOW_INSECURE=true disables TLS — ONLY for development
62+
TELEMETRYFLOW_INSECURE=false
6263

6364

6465
#================================================================================================
@@ -176,14 +177,14 @@ TFO_PLATFORM_VERSION=1.4.0
176177
POSTGRES_VERSION=16-alpine
177178
POSTGRES_DB=telemetryflow_db
178179
POSTGRES_USERNAME=tfo_admin
179-
POSTGRES_PASSWORD=telemetryflow123
180+
POSTGRES_PASSWORD=
180181
PORT_POSTGRES=5432
181182

182183
# ClickHouse
183184
CLICKHOUSE_VERSION=latest
184185
CLICKHOUSE_DB=telemetryflow_db
185186
CLICKHOUSE_USER=tfo_admin
186-
CLICKHOUSE_PASSWORD=telemetryflow123
187+
CLICKHOUSE_PASSWORD=
187188
PORT_CLICKHOUSE_HTTP=8123
188189
PORT_CLICKHOUSE_NATIVE=9000
189190

@@ -204,10 +205,10 @@ PORT_NATS_MONITOR=8222
204205
NODE_ENV=development
205206
PORT_BACKEND=3000
206207
ENABLE_BULLMQ=true
207-
JWT_SECRET=dev-secret-change-me-in-production
208+
JWT_SECRET=
208209
JWT_EXPIRES_IN=24h
209-
SESSION_SECRET=dev-session-secret-change-me
210-
CORS_ORIGIN=*
210+
SESSION_SECRET=
211+
CORS_ORIGIN=http://localhost:8080
211212
LOGGER_TYPE=winston
212213
LOG_PRETTY_PRINT=false
213214
OTEL_SERVICE_NAME=telemetryflow-platform
@@ -307,8 +308,8 @@ DB_PASSWORD=
307308
#================================================================================================
308309
# [20] SECURITY (for RESTful API generator)
309310
#================================================================================================
310-
SECRET_KEY=change-me-in-production
311-
JWT_SECRET_KEY=change-me-in-production
311+
SECRET_KEY=
312+
JWT_SECRET_KEY=
312313
JWT_EXPIRES=3600
313314

314315

.github/workflows/docker.yml

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -179,37 +179,50 @@ jobs:
179179
# =============================================================================
180180
# TelemetryFlow Python SDK - Multi-stage Dockerfile
181181
# =============================================================================
182-
FROM python:3.12-slim AS builder
182+
FROM python:3.14-slim AS builder
183183
184184
ARG VERSION=dev
185185
ARG GIT_COMMIT=unknown
186186
ARG BUILD_TIME=unknown
187187
188188
WORKDIR /build
189189
190-
# Install build dependencies
191-
RUN apt-get update && apt-get install -y --no-install-recommends \
190+
# Install build dependencies and upgrade system packages to fix CVEs
191+
RUN apt-get update && \
192+
apt-get upgrade -y && \
193+
apt-get install -y --no-install-recommends \
192194
git \
193195
&& rm -rf /var/lib/apt/lists/*
194196
195197
# Copy package files
196198
COPY pyproject.toml README.md ./
197199
COPY src/ ./src/
198200
199-
# Build wheel
200-
RUN pip install --no-cache-dir build && \
201+
# Build wheel (upgrade pip to fix CVEs)
202+
RUN pip install --upgrade pip build && \
201203
python -m build --wheel
202204
203205
# =============================================================================
204206
# Final image
205207
# =============================================================================
206-
FROM python:3.12-slim
208+
FROM python:3.14-slim
207209
208210
ARG VERSION=dev
209211
210-
# Install the built wheel
212+
# Upgrade ALL system packages to patch CVEs (ncurses, glibc, util-linux, xz, zlib, tar, systemd, sqlite)
213+
# Remove perl to eliminate Archive::Tar, IO::Compress CVEs
214+
RUN apt-get update && \
215+
apt-get upgrade -y && \
216+
apt-get install -y --no-install-recommends \
217+
ca-certificates \
218+
&& apt-get remove -y --purge perl \
219+
&& apt-get autoremove -y --purge \
220+
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
221+
222+
# Install the built wheel (upgrade pip to fix CVEs)
211223
COPY --from=builder /build/dist/*.whl /tmp/
212-
RUN pip install --no-cache-dir /tmp/*.whl && \
224+
RUN pip install --upgrade pip && \
225+
pip install --no-cache-dir /tmp/*.whl && \
213226
rm /tmp/*.whl
214227
215228
# Labels

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
107107
### Fixed
108108

109109
- **gRPC Header Case Sensitivity**: Fixed gRPC exporter to use lowercase header keys (gRPC metadata specification requires lowercase keys)
110+
- **Security - Credentials Exposure**: Removed partial API key secret leak in `Credentials.__str__()` — now masks secret completely with `***` instead of exposing first 8 characters
111+
- **Security - Plaintext Secret Header**: Removed `X-TelemetryFlow-Key-Secret` from `auth_headers()` — API key secret is now only transmitted via the `Authorization` header
112+
- **Security - Endpoint SSRF Validation**: Added regex-based `host:port` validation in `TelemetryConfig._validate()` to prevent Server-Side Request Forgery via malformed endpoints
113+
- **Security - Insecure TLS Warning**: Added `logging.warning()` when `with_insecure(True)` is called to alert developers that TLS is disabled
114+
- **Security - Hardcoded Secrets**: Removed all hardcoded default passwords from `docker-compose.yml` — PostgreSQL, ClickHouse, JWT, and session secrets now require explicit configuration via `${VAR:?msg}` pattern
115+
- **Security - CORS Wildcard**: Changed default `CORS_ORIGIN` from `*` to `http://localhost:8080` in `docker-compose.yml` and `.env.example`
116+
- **Security - Weak Defaults**: Removed weak default secrets (`change-me-in-production`, `telemetryflow123`) from `.env.example` — all secret fields now empty by default
117+
- **Security - Insecure Default**: Changed `TELEMETRYFLOW_INSECURE` default from `true` to `false` in `.env.example` with security warning
118+
- **Security - Docker Root User**: Added non-root `telemetryflow` user (UID 10001) to `Dockerfile.dev` with `USER` directive
119+
- **Security - Docker CVE Hardening**: Updated `Dockerfile`, `Dockerfile.dev`, and `docker.yml` workflow to patch Trivy-detected CVEs:
120+
- `apt-get upgrade -y` to patch ncurses, glibc, util-linux, xz, zlib, tar, systemd, sqlite vulnerabilities
121+
- Removed `perl` package to eliminate Archive::Tar, IO::Compress, IO::Uncompress::Unzip CVEs
122+
- Upgraded `pip` to latest version to fix arbitrary code execution, path traversal, and improper archive handling
123+
- **Version Alignment (CVS)**: Fixed `version.py` from stale `1.1.1` to `1.2.0` matching `pyproject.toml` and `CHANGELOG.md`
124+
- **Version Alignment (CVS)**: Updated `Dockerfile` `ARG VERSION` and OCI labels from `1.1.1` to `1.2.0`
125+
- **Version Alignment (CVS)**: Updated `Dockerfile` build comments from `1.1.1` to `1.2.0`
110126

111127
### SDK Configuration Structure
112128

Dockerfile

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
FROM python:3.14-slim AS builder
2828

2929
# Build arguments
30-
ARG VERSION=1.1.1
30+
ARG VERSION=1.2.0
3131
ARG GIT_COMMIT=unknown
3232
ARG GIT_BRANCH=unknown
3333
ARG BUILD_TIME=unknown
@@ -38,8 +38,10 @@ ENV PYTHONDONTWRITEBYTECODE=1 \
3838
PIP_NO_CACHE_DIR=1 \
3939
PIP_DISABLE_PIP_VERSION_CHECK=1
4040

41-
# Install build dependencies
42-
RUN apt-get update && apt-get install -y --no-install-recommends \
41+
# Install build dependencies and upgrade all system packages to fix CVEs
42+
RUN apt-get update && \
43+
apt-get upgrade -y && \
44+
apt-get install -y --no-install-recommends \
4345
git \
4446
&& rm -rf /var/lib/apt/lists/*
4547

@@ -68,14 +70,14 @@ FROM python:3.14-slim
6870
# =============================================================================
6971
LABEL org.opencontainers.image.title="TelemetryFlow Python SDK" \
7072
org.opencontainers.image.description="Python SDK and code generators for TelemetryFlow integration - Community Enterprise Observability Platform (CEOP)" \
71-
org.opencontainers.image.version="1.1.1" \
73+
org.opencontainers.image.version="1.2.0" \
7274
org.opencontainers.image.vendor="TelemetryFlow" \
7375
org.opencontainers.image.authors="Telemetri Data Indonesia <support@devopscorner.id>" \
7476
org.opencontainers.image.url="https://telemetryflow.id" \
7577
org.opencontainers.image.documentation="https://docs.telemetryflow.id" \
7678
org.opencontainers.image.source="https://github.com/telemetryflow/telemetryflow-python-sdk" \
7779
org.opencontainers.image.licenses="Apache-2.0" \
78-
org.opencontainers.image.base.name="python:3.12-slim" \
80+
org.opencontainers.image.base.name="python:3.14-slim" \
7981
# TelemetryFlow specific labels
8082
io.telemetryflow.product="TelemetryFlow Python SDK" \
8183
io.telemetryflow.component="telemetryflow-python-sdk" \
@@ -91,11 +93,25 @@ ENV PYTHONDONTWRITEBYTECODE=1 \
9193
TELEMETRYFLOW_ENDPOINT=api.telemetryflow.id:4317 \
9294
TELEMETRYFLOW_ENVIRONMENT=production
9395

94-
# Install runtime dependencies
95-
RUN apt-get update && apt-get install -y --no-install-recommends \
96+
# Install runtime dependencies and upgrade ALL system packages to patch CVEs:
97+
# - ncurses: buffer overflow (#80,#85,#93,#94)
98+
# - glibc: heap overflow, DNS crash, TSIG OOB write (#67-#74)
99+
# - util-linux: TOCTOU mount, hostname canonicalization (#75-#82,#87-#92)
100+
# - xz: buffer overflow in index decoding (#77)
101+
# - zlib: DoS via infinite loop in CRC32 (#106)
102+
# - tar: hidden file injection (#103)
103+
# - systemd: unintended terminal output (#84,#86)
104+
# - sqlite: info disclosure via crafted ZIP (#83)
105+
# - perl: heap overflow, Archive::Tar, IO::Compress (#95-#102)
106+
# - pip: arbitrary code execution, path traversal (#107-#109)
107+
RUN apt-get update && \
108+
apt-get upgrade -y && \
109+
apt-get install -y --no-install-recommends \
96110
ca-certificates \
97111
curl \
98-
&& rm -rf /var/lib/apt/lists/*
112+
&& apt-get remove -y --purge perl \
113+
&& apt-get autoremove -y --purge \
114+
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
99115

100116
# Create non-root user and group
101117
RUN groupadd -g 10001 telemetryflow && \
@@ -108,8 +124,9 @@ RUN mkdir -p /workspace && chown -R telemetryflow:telemetryflow /workspace
108124
COPY --from=builder /wheels /wheels
109125
COPY --from=builder /build/dist/*.whl /wheels/
110126

111-
# Install the SDK and dependencies
112-
RUN pip install --no-cache-dir /wheels/*.whl && \
127+
# Install the SDK and dependencies (upgrade pip to fix CVEs #107-#109)
128+
RUN pip install --upgrade pip && \
129+
pip install --no-cache-dir /wheels/*.whl && \
113130
rm -rf /wheels
114131

115132
# Verify installation
@@ -134,29 +151,29 @@ CMD ["--help"]
134151
# =============================================================================
135152
# Build with:
136153
# docker build \
137-
# --build-arg VERSION=1.1.1 \
154+
# --build-arg VERSION=1.2.0 \
138155
# --build-arg GIT_COMMIT=$(git rev-parse --short HEAD) \
139156
# --build-arg GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD) \
140157
# --build-arg BUILD_TIME=$(date -u '+%Y-%m-%dT%H:%M:%SZ') \
141-
# -t telemetryflow/telemetryflow-python-sdk:1.1.1 .
158+
# -t telemetryflow/telemetryflow-python-sdk:1.2.0 .
142159
#
143160
# Run with:
144161
# # SDK Generator (telemetryflow-gen) - Native Python integration
145-
# docker run --rm -v $(pwd):/workspace telemetryflow/telemetryflow-python-sdk:1.1.1 \
162+
# docker run --rm -v $(pwd):/workspace telemetryflow/telemetryflow-python-sdk:1.2.0 \
146163
# init -p my-project --output /workspace
147164
#
148165
# # RESTful API Generator (telemetryflow-restapi) - Flask + SQLAlchemy DDD project
149166
# docker run --rm -v $(pwd):/workspace --entrypoint telemetryflow-restapi \
150-
# telemetryflow/telemetryflow-python-sdk:1.1.1 \
167+
# telemetryflow/telemetryflow-python-sdk:1.2.0 \
151168
# new -n my-api --output /workspace
152169
#
153170
# # Add entity to RESTful API project
154171
# docker run --rm -v $(pwd)/my-api:/workspace --entrypoint telemetryflow-restapi \
155-
# telemetryflow/telemetryflow-python-sdk:1.1.1 \
172+
# telemetryflow/telemetryflow-python-sdk:1.2.0 \
156173
# entity -n User -f 'name:string,email:string' --output /workspace
157174
#
158175
# # Run Python example
159176
# docker run --rm -v $(pwd):/workspace --entrypoint python \
160-
# telemetryflow/telemetryflow-python-sdk:1.1.1 \
177+
# telemetryflow/telemetryflow-python-sdk:1.2.0 \
161178
# /workspace/example.py
162179
# =============================================================================

Dockerfile.dev

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ FROM python:3.14-slim
1717
# =============================================================================
1818
LABEL org.opencontainers.image.title="TelemetryFlow Python SDK - Development" \
1919
org.opencontainers.image.description="Development image for TelemetryFlow Python SDK" \
20-
org.opencontainers.image.version="1.1.1-dev" \
20+
org.opencontainers.image.version="1.2.0-dev" \
2121
org.opencontainers.image.vendor="TelemetryFlow" \
2222
org.opencontainers.image.authors="Telemetri Data Indonesia <support@devopscorner.id>" \
2323
org.opencontainers.image.licenses="Apache-2.0"
@@ -27,19 +27,26 @@ ENV PYTHONDONTWRITEBYTECODE=1 \
2727
PYTHONUNBUFFERED=1 \
2828
PIP_NO_CACHE_DIR=1 \
2929
PIP_DISABLE_PIP_VERSION_CHECK=1 \
30-
# Development settings
3130
PYTHONFAULTHANDLER=1 \
3231
PYTHONHASHSEED=random
3332

34-
# Install system dependencies
35-
RUN apt-get update && apt-get install -y --no-install-recommends \
33+
# Install system dependencies and upgrade ALL system packages to patch CVEs
34+
RUN apt-get update && \
35+
apt-get upgrade -y && \
36+
apt-get install -y --no-install-recommends \
3637
git \
3738
curl \
3839
wget \
3940
vim \
4041
ca-certificates \
4142
build-essential \
42-
&& rm -rf /var/lib/apt/lists/*
43+
&& apt-get remove -y --purge perl \
44+
&& apt-get autoremove -y --purge \
45+
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
46+
47+
# Create non-root user
48+
RUN groupadd -g 10001 telemetryflow && \
49+
useradd -u 10001 -g telemetryflow -d /home/telemetryflow -m telemetryflow
4350

4451
# Set working directory
4552
WORKDIR /app
@@ -48,7 +55,7 @@ WORKDIR /app
4855
COPY pyproject.toml README.md LICENSE ./
4956
COPY src/ ./src/
5057

51-
# Install the package with all development dependencies
58+
# Install the package with all development dependencies (upgrade pip to fix CVEs)
5259
RUN pip install --upgrade pip && \
5360
pip install -e ".[dev,http,grpc]"
5461

@@ -60,7 +67,10 @@ RUN pip install \
6067
httpx
6168

6269
# Create workspace directory
63-
RUN mkdir -p /workspace
70+
RUN mkdir -p /workspace && chown -R telemetryflow:telemetryflow /workspace /app
71+
72+
# Switch to non-root user
73+
USER telemetryflow
6474

6575
# Set default command
6676
CMD ["python", "-c", "from telemetryflow import TelemetryFlowBuilder; print('TelemetryFlow Python SDK - Development Environment Ready!')"]

docker-compose.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ services:
274274
environment:
275275
- TZ=${TZ:-UTC}
276276
- POSTGRES_USER=${POSTGRES_USERNAME:-tfo_admin}
277-
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-telemetryflow123}
277+
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD:?POSTGRES_PASSWORD must be set}
278278
- POSTGRES_DB=${POSTGRES_DB:-telemetryflow_db}
279279
- PGDATA=/var/lib/postgresql/data/pgdata
280280
volumes:
@@ -305,7 +305,7 @@ services:
305305
- TZ=${TZ:-UTC}
306306
- CLICKHOUSE_DB=${CLICKHOUSE_DB:-telemetryflow_db}
307307
- CLICKHOUSE_USER=${CLICKHOUSE_USER:-tfo_admin}
308-
- CLICKHOUSE_PASSWORD=${CLICKHOUSE_PASSWORD:-telemetryflow123}
308+
- CLICKHOUSE_PASSWORD=${CLICKHOUSE_PASSWORD:?CLICKHOUSE_PASSWORD must be set}
309309
volumes:
310310
- ${DATA_CLICKHOUSE:-${VOLUMES_BASE_PATH:-/opt/data/docker/telemetryflow-sdk}/clickhouse}/data:/var/lib/clickhouse
311311
- ${DATA_CLICKHOUSE:-${VOLUMES_BASE_PATH:-/opt/data/docker/telemetryflow-sdk}/clickhouse}/logs:/var/log/clickhouse-server
@@ -396,14 +396,14 @@ services:
396396
- POSTGRES_PORT=5432
397397
- POSTGRES_DB=${POSTGRES_DB:-telemetryflow_db}
398398
- POSTGRES_USERNAME=${POSTGRES_USERNAME:-tfo_admin}
399-
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-telemetryflow123}
399+
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD:?POSTGRES_PASSWORD must be set}
400400

401401
# ClickHouse
402402
- CLICKHOUSE_HOST=clickhouse
403403
- CLICKHOUSE_PORT=8123
404404
- CLICKHOUSE_DB=${CLICKHOUSE_DB:-telemetryflow_db}
405405
- CLICKHOUSE_USER=${CLICKHOUSE_USER:-tfo_admin}
406-
- CLICKHOUSE_PASSWORD=${CLICKHOUSE_PASSWORD:-telemetryflow123}
406+
- CLICKHOUSE_PASSWORD=${CLICKHOUSE_PASSWORD:?CLICKHOUSE_PASSWORD must be set}
407407

408408
# Redis
409409
- REDIS_HOST=redis
@@ -421,12 +421,12 @@ services:
421421
- ENABLE_BULLMQ=${ENABLE_BULLMQ:-true}
422422

423423
# JWT & Session
424-
- JWT_SECRET=${JWT_SECRET:-dev-secret-change-me-in-production}
424+
- JWT_SECRET=${JWT_SECRET:?JWT_SECRET must be set}
425425
- JWT_EXPIRES_IN=${JWT_EXPIRES_IN:-24h}
426-
- SESSION_SECRET=${SESSION_SECRET:-dev-session-secret-change-me}
426+
- SESSION_SECRET=${SESSION_SECRET:?SESSION_SECRET must be set}
427427

428428
# CORS
429-
- CORS_ORIGIN=${CORS_ORIGIN:-*}
429+
- CORS_ORIGIN=${CORS_ORIGIN:-http://localhost:8080}
430430

431431
# Logging
432432
- LOGGER_TYPE=${LOGGER_TYPE:-winston}

src/telemetryflow/builder.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from __future__ import annotations
2121

2222
import contextlib
23+
import logging
2324
import os
2425
from datetime import timedelta
2526
from typing import TYPE_CHECKING
@@ -31,6 +32,8 @@
3132
if TYPE_CHECKING:
3233
pass
3334

35+
logger = logging.getLogger(__name__)
36+
3437

3538
class BuilderError(Exception):
3639
"""Exception raised for builder configuration errors."""
@@ -325,6 +328,12 @@ def with_insecure(self, insecure: bool = True) -> TelemetryFlowBuilder:
325328
Self for method chaining
326329
"""
327330
self._insecure = insecure
331+
if insecure:
332+
logger.warning(
333+
"TLS verification is DISABLED (insecure=true). "
334+
"This should ONLY be used in development. "
335+
"Never use this in production environments."
336+
)
328337
return self
329338

330339
# Signal Configuration

0 commit comments

Comments
 (0)