Skip to content

Commit c43643d

Browse files
authored
Merge pull request #508 from ansforge/chore/security/fix-cve-chatbot
chore/security : fix des vulnérabilités du chatbot
2 parents d0117ff + 10d20df commit c43643d

File tree

6 files changed

+209
-212
lines changed

6 files changed

+209
-212
lines changed

.github/config/build-matrices.yaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,6 @@ projects:
1919
tag: hub-healthcheck
2020
artifact-name: trivy-reports-healthcheck
2121

22-
chatbot:
23-
description: "AI chatbot service"
24-
include:
25-
- name: chatbot
26-
context: ./tools/chatbot
27-
tag: hub-chatbot
28-
artifact-name: trivy-reports-chatbot
29-
3022
openssl:
3123
description: "OpenSSL utilities"
3224
include:
@@ -50,3 +42,11 @@ projects:
5042
context: ./tools/annuaire
5143
tag: hub-annuaire
5244
artifact-name: trivy-reports-annuaire
45+
46+
chatbot:
47+
description: "AI chatbot assistant"
48+
include:
49+
- name: chatbot
50+
context: ./tools/chatbot
51+
tag: hub-chatbot
52+
artifact-name: trivy-reports-chatbot

.github/workflows/build-images.yml

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
name: Build images (landing, healthcheck, chatbot, openSSL, specs, annuaire)
1+
name: Build images (landing, healthcheck, openSSL, specs, annuaire, chatbot)
22

33
on:
44
workflow_dispatch:
55
push:
66
tags:
77
- 'landing-*'
88
- 'healthcheck-*'
9-
- 'chatbot-*'
109
- 'openssl-*'
1110
- 'specs-*'
1211
- 'annuaire-*'
12+
- 'chatbot-*'
1313

1414
permissions:
1515
contents: read
@@ -87,6 +87,13 @@ jobs:
8787
- name: Set up Docker Buildx
8888
uses: docker/setup-buildx-action@v3
8989

90+
- name: Login to Docker Hardened Images
91+
uses: docker/login-action@v3
92+
with:
93+
registry: dhi.io
94+
username: ${{ secrets.DHI_USERNAME }}
95+
password: ${{ secrets.DHI_PASSWORD }}
96+
9097
- name: Login to Container Registry
9198
uses: docker/login-action@v3
9299
with:
@@ -101,27 +108,23 @@ jobs:
101108
tags: ghcr.io/${{ github.repository_owner }}/${{ matrix.tag }}:${{ needs.extract-release-info.outputs.version }}
102109
context: ${{ matrix.context }}
103110

111+
- name: Check for trivyignore file
112+
id: check-trivyignore
113+
run: |
114+
if [ -f "${{ matrix.context }}/.trivyignore" ]; then
115+
echo "exists=true" >> $GITHUB_OUTPUT
116+
echo "path=${{ matrix.context }}/.trivyignore" >> $GITHUB_OUTPUT
117+
else
118+
echo "exists=false" >> $GITHUB_OUTPUT
119+
fi
120+
104121
- name: Scan Docker image
122+
id: trivy-scan
105123
continue-on-error: true
106124
uses: aquasecurity/trivy-action@0.33.1
107125
with:
108126
image-ref: ghcr.io/${{ github.repository_owner }}/${{ matrix.tag }}:${{ needs.extract-release-info.outputs.version }}
109-
format: 'sarif'
110-
output: 'trivy-${{ matrix.name }}-image.sarif'
127+
format: 'table'
111128
severity: 'HIGH,CRITICAL'
112129
exit-code: '1'
113-
114-
- name: Upload image scan results to GitHub Security tab
115-
if: always() && hashFiles('trivy-${{ matrix.name }}-image.sarif') != ''
116-
uses: github/codeql-action/upload-sarif@v3
117-
with:
118-
sarif_file: 'trivy-${{ matrix.name }}-image.sarif'
119-
category: 'trivy-${{ matrix.name }}-image'
120-
121-
- name: Upload image scan reports as artifacts
122-
if: always()
123-
uses: actions/upload-artifact@v4
124-
with:
125-
name: ${{ matrix.artifact-name }}
126-
path: '*.sarif'
127-
retention-days: 30
130+
trivyignores: ${{ steps.check-trivyignore.outputs.exists == 'true' && steps.check-trivyignore.outputs.path || '' }}

tools/chatbot/.trivyignore

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Vulnérabilités HIGH sans correctif disponible
2+
# Dernière révision: 27 janvier 2026
3+
4+
# CVE-2026-0994 - protobuf (Python package)
5+
# DoS via nested google.protobuf.Any messages
6+
# Status: No fix available
7+
# Justification: Dépendance transitive de chromadb, impact faible (pas de parsing JSON externe malveillant)
8+
CVE-2026-0994
9+
10+
# CVE-2026-0861 - glibc/libc6 (Debian system package)
11+
# Integer overflow in memalign leads to heap corruption
12+
# Status: No fix available
13+
# Justification: Exploitation nécessite contrôle des paramètres memalign (peu probable dans notre contexte)
14+
CVE-2026-0861
15+
16+
# DS026 - HEALTHCHECK instruction missing
17+
# Justification: Utilisation de Kubernetes avec livenessProbe/readinessProbe
18+
# Le HEALTHCHECK Docker est ignoré par Kubernetes
19+
DS026

tools/chatbot/Dockerfile

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,42 @@
1-
# Use an official Python runtime as a parent image
2-
FROM python:3.13-slim
1+
# Builder stage - use Debian Python image for building (onnxruntime needs glibc/manylinux)
2+
FROM dhi.io/python:3.13-dev AS builder
3+
4+
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
35

46
# Set environment variables
57
ENV PYTHONDONTWRITEBYTECODE=1 \
68
PYTHONUNBUFFERED=1 \
7-
UV_CACHE_DIR=/opt/uv-cache \
9+
UV_CACHE_DIR=/tmp/uv-cache \
810
UV_LINK_MODE=copy
911

10-
# Install system dependencies and uv
11-
RUN apt-get update && apt-get install -y \
12-
curl \
13-
ca-certificates \
14-
&& rm -rf /var/lib/apt/lists/* \
15-
&& curl -LsSf https://astral.sh/uv/install.sh | sh \
16-
&& mv /root/.local/bin/uv /usr/local/bin/uv \
17-
&& mv /root/.local/bin/uvx /usr/local/bin/uvx
12+
# Set the working directory
13+
WORKDIR /app
1814

19-
# Create a non-root user and group
20-
RUN groupadd -r -g 1000 chatbot && useradd -r -u 1000 -g chatbot chatbot
15+
# Copy dependency files
16+
COPY pyproject.toml uv.lock ./
2117

22-
# Set the working directory in the container
23-
WORKDIR /app
18+
# Install dependencies
19+
RUN uv sync --frozen --no-dev
2420

25-
# Create UV cache directory with proper permissions and set ownership of working directory
26-
RUN mkdir -p $UV_CACHE_DIR && \
27-
chown -R chatbot:chatbot $UV_CACHE_DIR && \
28-
chown -R chatbot:chatbot /app
21+
# Final stage - use standard Debian slim (DHI too minimal for venv)
22+
FROM dhi.io/python:3.13
2923

30-
# Switch to the non-root user
31-
USER chatbot
24+
# Set environment variables
25+
ENV PYTHONDONTWRITEBYTECODE=1 \
26+
PYTHONUNBUFFERED=1 \
27+
PATH="/app/.venv/bin:$PATH"
3228

33-
# Copy the current directory contents into the container at /app
34-
COPY --chown=chatbot:chatbot . .
29+
# Set the working directory
30+
WORKDIR /app
3531

36-
# Install dependencies and project in one step
37-
RUN uv sync --frozen --no-dev
32+
# Copy virtual environment from builder
33+
COPY --from=builder --chown=1000:1000 /app/.venv /app/.venv
34+
35+
# Copy application code
36+
COPY chatbot.py chatbot.py
37+
38+
# Explicit non-root user (already set by base image)
39+
USER 1000
3840

39-
# Run the application (--no-sync prevents any dependency downloads at runtime)
40-
CMD ["uv", "run", "--no-sync", "python", "chatbot.py"]
41+
# Run the application
42+
CMD ["python", "chatbot.py"]

tools/chatbot/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ dependencies = [
77
"slack-bolt~=1.26.0",
88
"langchain-openai~=1.0.1",
99
"langchain-community~=0.4.1",
10-
"langchain-core~=1.0.2",
10+
"langchain-core>=1.2.5",
1111
"langchain-chroma~=1.0.0",
1212
"chromadb~=1.3.0",
1313
"openai~=2.6.1",

0 commit comments

Comments
 (0)