dana-medical-site/deploy/firewall-1c-egress.sh

29 lines
1.3 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/sh
# firewall-1c-egress.sh — разрешить доступ к 1C MCP (10.240.70.70:6003)
# только контейнеру dana-1c-bridge (172.20.0.50), остальным контейнерам — DROP.
#
# Запускать на хосте от root (или через sudo). Идемпотентен.
# Для сохранения после перезагрузки см. systemd unit dana-1c-egress.service.
set -eu
BRIDGE_IP="172.20.0.50"
ONEC_HOST="10.240.70.70"
ONEC_PORT="6003"
if ! iptables -L DOCKER-USER -n >/dev/null 2>&1; then
echo "DOCKER-USER chain not found (docker not running?)" >&2
exit 1
fi
# Порядок важен: ACCEPT первым, затем DROP для всех остальных источников.
iptables -C DOCKER-USER -s "$BRIDGE_IP" -d "$ONEC_HOST" -p tcp --dport "$ONEC_PORT" -j ACCEPT 2>/dev/null \
|| iptables -I DOCKER-USER 1 -s "$BRIDGE_IP" -d "$ONEC_HOST" -p tcp --dport "$ONEC_PORT" -j ACCEPT
# Блокируем весь остальной трафик контейнеров к хосту 1С (любые порты).
iptables -C DOCKER-USER -d "$ONEC_HOST" -j DROP 2>/dev/null \
|| iptables -I DOCKER-USER 2 -d "$ONEC_HOST" -j DROP
echo "=== DOCKER-USER ==="
iptables -L DOCKER-USER -n --line-numbers
echo "OK: только $BRIDGE_IP (dana-1c-bridge) может ходить на $ONEC_HOST"