Files
prod/MONITORING_AUTH.md
Andrey f7b08ae9e8 feat: enhance Ansible playbook and Nginx configuration with authentication and logrotate setup
- Added environment variables for project configuration in env.template.
- Updated Ansible playbook to use environment variables for project settings and added tasks for monitoring authentication setup.
- Enhanced Nginx configuration for Alertmanager and Prometheus with HTTP Basic Authentication.
- Introduced logrotate configuration for managing log files and set up cron for daily execution.
- Removed obsolete Uptime Kuma docker-compose file.
2025-09-19 12:09:05 +03:00

128 lines
3.9 KiB
Markdown
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.
# 🔐 Авторизация для мониторинга
## Что было добавлено
Добавлена HTTP Basic Authentication для следующих сервисов мониторинга:
- **Prometheus** (`/prometheus/`) - метрики и мониторинг
- **Alertmanager** (`/alerts/` и `/api/v1/`) - управление алертами
## Быстрый старт
### 1. Автоматическая настройка через Ansible
```bash
# Развертывание с паролями по умолчанию
ansible-playbook -i infra/ansible/inventory.ini infra/ansible/playbook.yml
# Развертывание с кастомными паролями
ansible-playbook -i infra/ansible/inventory.ini infra/ansible/playbook.yml \
-e monitoring_username=myuser \
-e monitoring_password=mypassword
```
### 2. Ручная настройка
```bash
# Настроить авторизацию
make auth-setup
# Добавить пользователя
make auth-add-user USER=admin
# Добавить еще одного пользователя
make auth-add-user USER=operator
```
## Управление пользователями
### Добавление пользователя
```bash
make auth-add-user USER=username
```
### Сброс пароля
```bash
make auth-reset USER=username
```
### Просмотр пользователей
```bash
make auth-list
```
## Доступ к сервисам
После настройки авторизации:
- **Prometheus**: `https://your-server/prometheus/`
- **Alertmanager**: `https://your-server/alerts/`
- **Alertmanager API**: `https://your-server/api/v1/`
При первом обращении браузер запросит логин и пароль.
## Health Check endpoints
Следующие endpoints остаются доступными без авторизации:
- `https://your-server/prometheus/-/healthy` - проверка состояния Prometheus
- `https://your-server/nginx-health` - проверка состояния nginx
## Файлы конфигурации
### Nginx конфигурации
- `infra/nginx/conf.d/prometheus.conf` - авторизация для Prometheus
- `infra/nginx/conf.d/alertmanager.conf` - авторизация для Alertmanager
### Ansible
- `infra/ansible/playbook.yml` - автоматическая настройка авторизации
- `infra/ansible/group_vars/all.yml` - переменные по умолчанию
### Скрипты
- `scripts/generate_auth_passwords.sh` - генерация паролей
- `infra/nginx/AUTH_SETUP.md` - подробная документация
## Безопасность
- Пароли хранятся в зашифрованном виде в `/etc/nginx/passwords/monitoring.htpasswd`
- Файл доступен только для чтения пользователю root и группе www-data
- Используется HTTPS для всех соединений
- Настроена защита от брутфорса через fail2ban
## Устранение проблем
### Проверка конфигурации nginx
```bash
sudo nginx -t
```
### Проверка файла паролей
```bash
make auth-list
```
### Проверка логов
```bash
sudo tail -f /var/log/nginx/error.log
sudo tail -f /var/log/nginx/access.log
```
### Перезапуск nginx
```bash
sudo systemctl reload nginx
```
## Переменные Ansible
В файле `infra/ansible/group_vars/all.yml`:
```yaml
monitoring_username: "admin" # Имя пользователя по умолчанию
monitoring_password: "admin123" # Пароль по умолчанию
```
Можно переопределить через:
- Переменные окружения
- `--extra-vars` в ansible-playbook
- Vault файлы для безопасного хранения паролей