fix(build): enforce secure TLS registry and binary verification

This commit is contained in:
devops committed 2026-10-25 08:19:30 +00:00
1 parent cc0358bb12
commit fd14c05f3a
6 files changed
+64 -14

No files matched your search

+7 -9
View File
@@ -1,4 +1,4 @@
FROM node:20-alpine AS app-builder
FROM node:22-alpine AS app-builder
USER root
WORKDIR /app
ENV NEXT_TELEMETRY_DISABLED=1
@@ -7,18 +7,17 @@ ENV NEXT_PUBLIC_API_URL=https://api.canina.ir/api
# Optional: Use Nexus as npm registry
ARG NPM_REGISTRY=
RUN if [ -n "$NPM_REGISTRY" ]; then \
npm config set registry "$NPM_REGISTRY" && \
npm config set strict-ssl false; \
npm config set registry "$NPM_REGISTRY"; \
fi
COPY frontend/application/package*.json ./
RUN npm ci --include=dev --prefer-offline --no-audit
RUN npm ci --include=dev --prefer-offline --no-audit && test -x node_modules/.bin/next
COPY frontend/application ./
ARG NEXT_PUBLIC_API_URL
ENV NEXT_PUBLIC_API_URL=$NEXT_PUBLIC_API_URL
RUN npm run build
FROM node:20-alpine AS admin-builder
FROM node:22-alpine AS admin-builder
USER root
WORKDIR /app
ENV VITE_API_URL=https://api.canina.ir/api
@@ -26,18 +25,17 @@ ENV VITE_API_URL=https://api.canina.ir/api
# Optional: Use Nexus as npm registry (inherits build-arg)
ARG NPM_REGISTRY=
RUN if [ -n "$NPM_REGISTRY" ]; then \
npm config set registry "$NPM_REGISTRY" && \
npm config set strict-ssl false; \
npm config set registry "$NPM_REGISTRY"; \
fi
COPY frontend/admin-panel/package*.json ./
RUN npm ci --include=dev --prefer-offline --no-audit
RUN npm ci --include=dev --prefer-offline --no-audit && test -x node_modules/.bin/vite
COPY frontend/admin-panel ./
ARG VITE_API_URL
ENV VITE_API_URL=$VITE_API_URL
RUN npm run build
FROM node:20-alpine
FROM node:22-alpine
USER root
RUN addgroup -S nginx 2>/dev/null || true && adduser -S nginx -G nginx 2>/dev/null || true
RUN mkdir -p /var/log/nginx /var/cache/nginx /run/nginx /etc/nginx/conf.d /etc/nginx/http.d
-1
View File
@@ -12,7 +12,6 @@ ENV npm_config_cache=/tmp/npm-cache
ARG NPM_REGISTRY=
RUN if [ -n "$NPM_REGISTRY" ]; then \
npm config set registry "$NPM_REGISTRY" && \
npm config set strict-ssl false && \
echo "Using npm registry: $NPM_REGISTRY"; \
fi
+2 -2
View File
@@ -24,7 +24,7 @@ services:
context: ./backend
dockerfile: Dockerfile
args:
NPM_REGISTRY: ${NPM_REGISTRY:-}
NPM_REGISTRY: ${NPM_REGISTRY:-https://registry.parsaaghayi.ir/repository/npm/}
container_name: canino_backend_stage
restart: always
env_file:
@@ -66,7 +66,7 @@ services:
context: .
dockerfile: Dockerfile
args:
NPM_REGISTRY: ${NPM_REGISTRY:-}
NPM_REGISTRY: ${NPM_REGISTRY:-https://registry.parsaaghayi.ir/repository/npm/}
NEXT_PUBLIC_API_URL: "https://stageapi.canina.ir/api"
VITE_API_URL: "https://stageapi.canina.ir"
container_name: canino_frontend_stage
+1 -1
View File
@@ -14,7 +14,7 @@ ALLOWED = {'nginx.conf', 'Dockerfile', 'backend/Dockerfile', '.dockerignore',
'scripts/compose.stage.yml', 'scripts/rollout-stage.sh', 'scripts/revalidation-runtime.py',
'scripts/provision-revalidation-env.py', 'scripts/tests/test_revalidation_runtime.py',
'scripts/tests/test_ci_host_boundary.py', 'scripts/tests/test_stage_provision_wiring.py',
'scripts/tests/test_stage_rollout.py',
'scripts/tests/test_stage_rollout.py', 'scripts/tests/test_secure_build_install.py',
# CI1285 verified-payload upgrade repair; no model, cron or payload wildcard.
'infra/hermes-editorial/installer.py',
'infra/hermes-editorial/tests/test_installer.py',
+2 -1
View File
@@ -28,7 +28,8 @@ class ProductionGuards(unittest.TestCase):
def test_exact_editorial_installer_repair_paths_allowed_only(self):
paths = ['infra/hermes-editorial/installer.py',
'infra/hermes-editorial/tests/test_installer.py']
'infra/hermes-editorial/tests/test_installer.py',
'scripts/tests/test_secure_build_install.py']
r = self.receipt(); r['paths'] = paths
m.validate_receipt(r, 'a'*40, 'b'*40, paths)
for path in ['infra/hermes-editorial/model-policy.json',
@@ -0,0 +1,52 @@
"""Regression gates for CI1286: trusted routing and fail-closed frontend installs."""
from pathlib import Path
import os
import re
import subprocess
import tempfile
import unittest
ROOT = Path(__file__).resolve().parents[2]
REGISTRY = 'https://registry.parsaaghayi.ir/repository/npm/'
class SecureBuildInstallTests(unittest.TestCase):
def test_stage_supplies_operational_tls_registry(self):
compose = (ROOT / 'scripts/compose.stage.yml').read_text()
self.assertEqual(compose.count('NPM_REGISTRY: ${NPM_REGISTRY:-' + REGISTRY + '}'), 2)
def test_frontend_uses_supported_node_lts_in_all_stages(self):
images = re.findall(r'^FROM node:(\S+)', (ROOT / 'Dockerfile').read_text(), re.M)
self.assertEqual(images, ['22-alpine'] * 3)
def test_registry_configuration_never_disables_tls(self):
for name in ['Dockerfile', 'backend/Dockerfile']:
self.assertNotIn('strict-ssl false', (ROOT / name).read_text())
def test_false_successful_incomplete_install_aborts_layer(self):
dockerfile = (ROOT / 'Dockerfile').read_text().replace('\\\n', '')
commands = re.findall(r'^RUN (npm ci[^\n]+)', dockerfile, re.M)
self.assertEqual(len(commands), 2)
for command, binary in zip(commands, ['next', 'vite']):
with self.subTest(binary=binary), tempfile.TemporaryDirectory() as d:
root = Path(d)
npm = root / 'npm'
# Reproduce npm's observed zero exit with no complete node_modules.
npm.write_text('#!/bin/sh\nexit 0\n')
npm.chmod(0o755)
result = subprocess.run(['sh', '-c', command], cwd=d,
env={**os.environ, 'PATH': d + ':' + os.environ['PATH']},
capture_output=True)
self.assertNotEqual(result.returncode, 0, 'incomplete install was accepted')
target = root / 'node_modules/.bin' / binary
target.parent.mkdir(parents=True)
target.write_text('#!/bin/sh\nexit 0\n')
target.chmod(0o755)
result = subprocess.run(['sh', '-c', command], cwd=d,
env={**os.environ, 'PATH': d + ':' + os.environ['PATH']},
capture_output=True)
self.assertEqual(result.returncode, 0, result.stderr)
if __name__ == '__main__':
unittest.main()