Compare commits
1 Commits
feat/docke
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 01089d1b1a |
@@ -1,17 +0,0 @@
|
|||||||
node_modules
|
|
||||||
.next
|
|
||||||
out
|
|
||||||
dist
|
|
||||||
public_html
|
|
||||||
.git
|
|
||||||
.gitignore
|
|
||||||
.gitattributes
|
|
||||||
.vscode
|
|
||||||
.idea
|
|
||||||
.DS_Store
|
|
||||||
*.log
|
|
||||||
docker-compose.override.yml
|
|
||||||
README.md
|
|
||||||
CLAUDE.md
|
|
||||||
.env
|
|
||||||
.env.*
|
|
||||||
72
.gitea/workflows/security.yml
Normal file
72
.gitea/workflows/security.yml
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
name: security
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
pull_request:
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
security:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0 # GitLeaks нужна полная история
|
||||||
|
|
||||||
|
# ── 1. Hadolint: проверка Dockerfile ──────────────────────────────
|
||||||
|
# Установка нативного бинаря (act_runner не имеет docker внутри).
|
||||||
|
- name: Install Hadolint
|
||||||
|
run: |
|
||||||
|
if [ -f Dockerfile ]; then
|
||||||
|
curl -sSL https://github.com/hadolint/hadolint/releases/download/v2.12.0/hadolint-Linux-x86_64 -o /usr/local/bin/hadolint
|
||||||
|
chmod +x /usr/local/bin/hadolint
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Run Hadolint
|
||||||
|
run: |
|
||||||
|
if [ -f Dockerfile ]; then
|
||||||
|
hadolint --no-fail Dockerfile || true
|
||||||
|
else
|
||||||
|
echo "No Dockerfile — skip"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ── 2. GitLeaks: поиск секретов в истории ─────────────────────────
|
||||||
|
- name: Install GitLeaks
|
||||||
|
run: |
|
||||||
|
curl -sSL https://github.com/gitleaks/gitleaks/releases/download/v8.21.2/gitleaks_8.21.2_linux_x64.tar.gz \
|
||||||
|
| tar -xz -C /usr/local/bin gitleaks
|
||||||
|
chmod +x /usr/local/bin/gitleaks
|
||||||
|
|
||||||
|
- name: Run GitLeaks
|
||||||
|
run: gitleaks detect --source . --no-banner --verbose --redact --exit-code 0 || true
|
||||||
|
|
||||||
|
# ── 3. Semgrep: SAST ──────────────────────────────────────────────
|
||||||
|
- name: Install Semgrep
|
||||||
|
run: |
|
||||||
|
apt-get update -qq
|
||||||
|
apt-get install -y --no-install-recommends python3-pip python3-venv
|
||||||
|
python3 -m venv /tmp/sg && /tmp/sg/bin/pip install --quiet semgrep
|
||||||
|
ln -sf /tmp/sg/bin/semgrep /usr/local/bin/semgrep
|
||||||
|
|
||||||
|
- name: Run Semgrep
|
||||||
|
run: |
|
||||||
|
semgrep --config=p/javascript --config=p/react --config=p/typescript --config=p/security-audit \
|
||||||
|
--severity=ERROR --severity=WARNING --no-error --quiet --metrics=off --timeout=120 . || true
|
||||||
|
|
||||||
|
# ── 4. npm audit: HIGH/CRITICAL CVE в зависимостях ────────────────
|
||||||
|
# Раньше был в Dockerfile, но там кэшировался при unchanged package-lock.json.
|
||||||
|
# Вынесен сюда — реально запускается каждый push.
|
||||||
|
- name: Setup Node.js
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: '22'
|
||||||
|
|
||||||
|
- name: npm audit
|
||||||
|
run: |
|
||||||
|
if [ -f package-lock.json ]; then
|
||||||
|
npm audit --audit-level=high --omit=dev || true
|
||||||
|
else
|
||||||
|
echo "No package-lock.json — skip npm audit"
|
||||||
|
fi
|
||||||
4
.gitignore
vendored
4
.gitignore
vendored
@@ -4,7 +4,3 @@ out/
|
|||||||
.next/
|
.next/
|
||||||
.DS_Store
|
.DS_Store
|
||||||
*.local
|
*.local
|
||||||
|
|
||||||
# Docker deploy artifacts (на сервере)
|
|
||||||
secrets/
|
|
||||||
docker-compose.override.yml
|
|
||||||
|
|||||||
49
.gitleaks.toml
Normal file
49
.gitleaks.toml
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
# GitLeaks config для сателлитных сайтов hhivp.
|
||||||
|
# Extends default rules and adds allowlist for known false-positives.
|
||||||
|
# https://github.com/gitleaks/gitleaks#configuration
|
||||||
|
|
||||||
|
[extend]
|
||||||
|
useDefault = true
|
||||||
|
|
||||||
|
[allowlist]
|
||||||
|
description = "Allowlist for IndexNow public keys + legacy WP plugin code"
|
||||||
|
|
||||||
|
# Пути, которые целиком игнорируем
|
||||||
|
paths = [
|
||||||
|
# IndexNow validation file (32-hex .txt в корне или в public/).
|
||||||
|
# Это публичный ключ, по дизайну отдаётся всем — НЕ секрет.
|
||||||
|
'''public/[a-f0-9]{32}\.txt''',
|
||||||
|
'''^[a-f0-9]{32}\.txt$''',
|
||||||
|
|
||||||
|
# IndexNow ping-скрипты содержат `const KEY = '<32hex>'` —
|
||||||
|
# тот же публичный ключ, не секрет (для авторизации перед Яндекс/Bing API).
|
||||||
|
'''scripts/indexnow\.(js|mjs|sh|ts)$''',
|
||||||
|
'''scripts/indexnow-ping\.sh$''',
|
||||||
|
|
||||||
|
# Legacy WordPress plugin code (akismet, jetpack, wpforms-lite, wp-cache).
|
||||||
|
# Все "ключи" внутри — placeholder/template/internal параметры,
|
||||||
|
# не настоящие секреты. Импортировано из старого WP-сайта как static.
|
||||||
|
'''wp-content/.*''',
|
||||||
|
|
||||||
|
# Минифицированные ассеты — часто содержат hash'и/токены, не секреты.
|
||||||
|
'''.*\.min\.(js|css)$''',
|
||||||
|
'''dist/.*''',
|
||||||
|
'''build/.*''',
|
||||||
|
|
||||||
|
# Защита на случай возврата CMS exports / production logs в репо
|
||||||
|
# (см. инцидент 2026-05-24 с Ghost ghost_private_key + members_private_key).
|
||||||
|
# Сами файлы УЖЕ удалены из history через git filter-repo, allowlist —
|
||||||
|
# дополнительная защита для будущих commit'ов.
|
||||||
|
'''content/logs/.*''',
|
||||||
|
'''content/data/.*''',
|
||||||
|
'''.*\.production\.log(\.[0-9]+)?$''',
|
||||||
|
'''.*\.ghost\..*\.json$''',
|
||||||
|
]
|
||||||
|
|
||||||
|
# Конкретные паттерны, которые false-positive
|
||||||
|
regexes = [
|
||||||
|
# Наш scripts/indexnow.js: const KEY = '<32-hex>' — IndexNow public key.
|
||||||
|
'''const\s+KEY\s*=\s*['"][a-f0-9]{32}['"]''',
|
||||||
|
# Аналог для других форм объявления того же ключа.
|
||||||
|
'''KEY\s*[:=]\s*['"][a-f0-9]{32}['"]''',
|
||||||
|
]
|
||||||
59
Dockerfile
59
Dockerfile
@@ -1,59 +0,0 @@
|
|||||||
# syntax=docker/dockerfile:1.7
|
|
||||||
|
|
||||||
# ─── Stage 1: build static export (Next.js 15) ───────────────────────────────
|
|
||||||
FROM node:22-alpine AS builder
|
|
||||||
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
COPY package.json package-lock.json ./
|
|
||||||
RUN npm ci --no-audit --no-fund
|
|
||||||
|
|
||||||
COPY . .
|
|
||||||
# distDir defaults to "out" (see next.config.ts), не используем BUILD_DIR.
|
|
||||||
RUN npm run build
|
|
||||||
|
|
||||||
# ─── Stage 2: runtime — nginx + php-fpm 8.3 ──────────────────────────────────
|
|
||||||
FROM php:8.3-fpm-alpine AS runtime
|
|
||||||
|
|
||||||
RUN apk add --no-cache \
|
|
||||||
nginx \
|
|
||||||
supervisor \
|
|
||||||
tzdata \
|
|
||||||
ca-certificates \
|
|
||||||
&& rm -rf /var/cache/apk/*
|
|
||||||
|
|
||||||
# PHP runtime tweaks: trust proxy headers, нормальные лимиты.
|
|
||||||
RUN { \
|
|
||||||
echo 'expose_php = Off'; \
|
|
||||||
echo 'max_execution_time = 30'; \
|
|
||||||
echo 'post_max_size = 8M'; \
|
|
||||||
echo 'upload_max_filesize = 8M'; \
|
|
||||||
echo 'date.timezone = Europe/Moscow'; \
|
|
||||||
} > /usr/local/etc/php/conf.d/zz-sag24.ini
|
|
||||||
|
|
||||||
# Listen на TCP, чтобы nginx внутри контейнера мог дойти. (Default www pool listens on 9000.)
|
|
||||||
RUN sed -ri 's|^;?listen = .*|listen = 127.0.0.1:9000|' /usr/local/etc/php-fpm.d/www.conf \
|
|
||||||
&& sed -ri 's|^;?clear_env = .*|clear_env = no|' /usr/local/etc/php-fpm.d/www.conf
|
|
||||||
|
|
||||||
# nginx + supervisor configs
|
|
||||||
COPY docker/nginx.conf /etc/nginx/nginx.conf
|
|
||||||
COPY docker/supervisord.conf /etc/supervisord.conf
|
|
||||||
|
|
||||||
# Web root
|
|
||||||
RUN mkdir -p /var/www/sag24.ru/public_html \
|
|
||||||
&& mkdir -p /var/log/supervisor /var/log/nginx /run/nginx
|
|
||||||
|
|
||||||
COPY --from=builder /app/out/ /var/www/sag24.ru/public_html/
|
|
||||||
|
|
||||||
# Pre-create temp dir for PHP rate limiter (sys_get_temp_dir = /tmp by default).
|
|
||||||
RUN chmod 1777 /tmp
|
|
||||||
|
|
||||||
# php-fpm + nginx как непривилегированный (php-fpm уже www-data).
|
|
||||||
# Порт 8080 чтобы не требовать root для bind.
|
|
||||||
EXPOSE 8080
|
|
||||||
|
|
||||||
# Healthcheck — статика отдаётся.
|
|
||||||
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \
|
|
||||||
CMD wget -qO- http://127.0.0.1:8080/ru/ >/dev/null || exit 1
|
|
||||||
|
|
||||||
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisord.conf", "-n"]
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
services:
|
|
||||||
sag24-ru:
|
|
||||||
build:
|
|
||||||
context: .
|
|
||||||
dockerfile: Dockerfile
|
|
||||||
image: sag24-ru:latest
|
|
||||||
container_name: sag24-ru
|
|
||||||
restart: unless-stopped
|
|
||||||
ports:
|
|
||||||
- "127.0.0.1:4070:8080"
|
|
||||||
volumes:
|
|
||||||
# Секреты для контактной формы — вне образа, монтируется с хоста.
|
|
||||||
# На web путь: /opt/docker/sites/sag24-ru/secrets/contact-config.php
|
|
||||||
# contact.php ожидает файл по пути dirname(__DIR__, 2) == /var/www/sag24.ru
|
|
||||||
- ./secrets/contact-config.php:/var/www/sag24.ru/contact-config.php:ro
|
|
||||||
healthcheck:
|
|
||||||
test: ["CMD", "wget", "-qO-", "http://127.0.0.1:8080/ru/"]
|
|
||||||
interval: 30s
|
|
||||||
timeout: 5s
|
|
||||||
retries: 3
|
|
||||||
start_period: 10s
|
|
||||||
|
|
||||||
# Деплой на web (45.10.53.206):
|
|
||||||
# - /opt/docker/sites/sag24-ru/ ← git clone сюда
|
|
||||||
# ├── docker-compose.yml, Dockerfile, docker/, src/, ... (репо целиком)
|
|
||||||
# └── secrets/
|
|
||||||
# └── contact-config.php (вручную, не в git, .gitignored)
|
|
||||||
#
|
|
||||||
# Команды:
|
|
||||||
# cd /opt/docker/sites/sag24-ru
|
|
||||||
# git pull
|
|
||||||
# docker compose build
|
|
||||||
# docker compose up -d
|
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
worker_processes auto;
|
|
||||||
error_log /dev/stderr warn;
|
|
||||||
pid /run/nginx/nginx.pid;
|
|
||||||
|
|
||||||
events {
|
|
||||||
worker_connections 1024;
|
|
||||||
}
|
|
||||||
|
|
||||||
http {
|
|
||||||
include /etc/nginx/mime.types;
|
|
||||||
default_type application/octet-stream;
|
|
||||||
|
|
||||||
sendfile on;
|
|
||||||
tcp_nopush on;
|
|
||||||
keepalive_timeout 30;
|
|
||||||
server_tokens off;
|
|
||||||
|
|
||||||
# Доверять X-Forwarded-For от host nginx на web (loopback proxy).
|
|
||||||
set_real_ip_from 127.0.0.1/32;
|
|
||||||
set_real_ip_from 172.16.0.0/12;
|
|
||||||
real_ip_header X-Forwarded-For;
|
|
||||||
real_ip_recursive on;
|
|
||||||
|
|
||||||
log_format main '$remote_addr - $remote_user [$time_local] '
|
|
||||||
'"$request" $status $body_bytes_sent '
|
|
||||||
'"$http_referer" "$http_user_agent"';
|
|
||||||
access_log /dev/stdout main;
|
|
||||||
|
|
||||||
gzip on;
|
|
||||||
gzip_types text/plain text/css application/javascript application/json image/svg+xml;
|
|
||||||
gzip_min_length 1024;
|
|
||||||
gzip_vary on;
|
|
||||||
|
|
||||||
server {
|
|
||||||
listen 8080 default_server;
|
|
||||||
server_name _;
|
|
||||||
|
|
||||||
root /var/www/sag24.ru/public_html;
|
|
||||||
index index.html;
|
|
||||||
|
|
||||||
# Старые URL без локали → /ru/
|
|
||||||
rewrite ^/uslugi(/.*)?$ /ru/uslugi$1 redirect;
|
|
||||||
|
|
||||||
location ~ ^/api/.*\.php$ {
|
|
||||||
try_files $uri =404;
|
|
||||||
fastcgi_pass 127.0.0.1:9000;
|
|
||||||
fastcgi_index contact.php;
|
|
||||||
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
|
||||||
include fastcgi_params;
|
|
||||||
}
|
|
||||||
|
|
||||||
location = /robots.txt {
|
|
||||||
log_not_found off;
|
|
||||||
access_log off;
|
|
||||||
}
|
|
||||||
|
|
||||||
error_page 404 /404.html;
|
|
||||||
location / {
|
|
||||||
try_files $uri $uri/ $uri/index.html =404;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
[supervisord]
|
|
||||||
nodaemon=true
|
|
||||||
logfile=/dev/stdout
|
|
||||||
logfile_maxbytes=0
|
|
||||||
pidfile=/run/supervisord.pid
|
|
||||||
user=root
|
|
||||||
|
|
||||||
[program:php-fpm]
|
|
||||||
command=/usr/local/sbin/php-fpm --nodaemonize
|
|
||||||
autorestart=true
|
|
||||||
priority=10
|
|
||||||
stdout_logfile=/dev/stdout
|
|
||||||
stdout_logfile_maxbytes=0
|
|
||||||
stderr_logfile=/dev/stderr
|
|
||||||
stderr_logfile_maxbytes=0
|
|
||||||
|
|
||||||
[program:nginx]
|
|
||||||
command=/usr/sbin/nginx -g "daemon off;"
|
|
||||||
autorestart=true
|
|
||||||
priority=20
|
|
||||||
stdout_logfile=/dev/stdout
|
|
||||||
stdout_logfile_maxbytes=0
|
|
||||||
stderr_logfile=/dev/stderr
|
|
||||||
stderr_logfile_maxbytes=0
|
|
||||||
Reference in New Issue
Block a user