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.
This commit is contained in:
104
infra/nginx/AUTH_SETUP.md
Normal file
104
infra/nginx/AUTH_SETUP.md
Normal file
@@ -0,0 +1,104 @@
|
||||
# Настройка авторизации для мониторинга
|
||||
|
||||
## Обзор
|
||||
|
||||
Добавлена HTTP Basic Authentication для следующих сервисов:
|
||||
- **Prometheus** (`/prometheus/`) - метрики и мониторинг
|
||||
- **Alertmanager** (`/alerts/` и `/api/v1/`) - управление алертами
|
||||
|
||||
## Управление паролями
|
||||
|
||||
### Автоматическая настройка через Ansible
|
||||
|
||||
При развертывании через Ansible пароли настраиваются автоматически:
|
||||
|
||||
```bash
|
||||
# Использовать пароли по умолчанию
|
||||
ansible-playbook -i inventory.ini playbook.yml
|
||||
|
||||
# Задать свои пароли
|
||||
ansible-playbook -i inventory.ini playbook.yml \
|
||||
-e monitoring_username=myuser \
|
||||
-e monitoring_password=mypassword
|
||||
```
|
||||
|
||||
### Ручная настройка
|
||||
|
||||
1. **Создать файл паролей:**
|
||||
```bash
|
||||
sudo mkdir -p /etc/nginx/passwords
|
||||
sudo htpasswd -c /etc/nginx/passwords/monitoring.htpasswd admin
|
||||
```
|
||||
|
||||
2. **Добавить дополнительных пользователей:**
|
||||
```bash
|
||||
sudo htpasswd /etc/nginx/passwords/monitoring.htpasswd username
|
||||
```
|
||||
|
||||
3. **Установить правильные права:**
|
||||
```bash
|
||||
sudo chown root:www-data /etc/nginx/passwords/monitoring.htpasswd
|
||||
sudo chmod 640 /etc/nginx/passwords/monitoring.htpasswd
|
||||
```
|
||||
|
||||
4. **Перезапустить nginx:**
|
||||
```bash
|
||||
sudo systemctl reload nginx
|
||||
```
|
||||
|
||||
### Использование скрипта генерации
|
||||
|
||||
```bash
|
||||
# Сгенерировать пароль для пользователя admin
|
||||
sudo /usr/local/bin/generate_auth_passwords.sh admin
|
||||
|
||||
# Сгенерировать пароль для другого пользователя
|
||||
sudo /usr/local/bin/generate_auth_passwords.sh myuser
|
||||
```
|
||||
|
||||
## Доступ к сервисам
|
||||
|
||||
После настройки авторизации доступ к сервисам:
|
||||
|
||||
- **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
|
||||
|
||||
## Безопасность
|
||||
|
||||
- Пароли хранятся в зашифрованном виде в файле `/etc/nginx/passwords/monitoring.htpasswd`
|
||||
- Файл доступен только для чтения пользователю root и группе www-data
|
||||
- Используется HTTPS для всех соединений
|
||||
- Настроена защита от брутфорса через fail2ban
|
||||
|
||||
## Устранение проблем
|
||||
|
||||
### Проверка конфигурации nginx
|
||||
```bash
|
||||
sudo nginx -t
|
||||
```
|
||||
|
||||
### Проверка файла паролей
|
||||
```bash
|
||||
sudo cat /etc/nginx/passwords/monitoring.htpasswd
|
||||
```
|
||||
|
||||
### Проверка логов nginx
|
||||
```bash
|
||||
sudo tail -f /var/log/nginx/error.log
|
||||
sudo tail -f /var/log/nginx/access.log
|
||||
```
|
||||
|
||||
### Сброс пароля
|
||||
```bash
|
||||
sudo htpasswd /etc/nginx/passwords/monitoring.htpasswd admin
|
||||
```
|
||||
@@ -1,8 +1,12 @@
|
||||
# Alertmanager Nginx Configuration
|
||||
# Proxies requests to Alertmanager
|
||||
|
||||
# Alertmanager location
|
||||
# Alertmanager location with authentication
|
||||
location /alerts/ {
|
||||
# HTTP Basic Authentication
|
||||
auth_basic "Alertmanager Monitoring";
|
||||
auth_basic_user_file /etc/nginx/passwords/monitoring.htpasswd;
|
||||
|
||||
# Rate limiting
|
||||
limit_req zone=api burst=10 nodelay;
|
||||
|
||||
@@ -31,8 +35,12 @@ location /alerts/ {
|
||||
add_header X-Content-Type-Options "nosniff" always;
|
||||
}
|
||||
|
||||
# Alertmanager API
|
||||
# Alertmanager API with authentication
|
||||
location /api/v1/ {
|
||||
# HTTP Basic Authentication
|
||||
auth_basic "Alertmanager API";
|
||||
auth_basic_user_file /etc/nginx/passwords/monitoring.htpasswd;
|
||||
|
||||
# Rate limiting
|
||||
limit_req zone=api burst=20 nodelay;
|
||||
|
||||
|
||||
@@ -1,7 +1,14 @@
|
||||
# Prometheus proxy configuration
|
||||
# Prometheus proxy configuration with authentication
|
||||
location /prometheus/ {
|
||||
proxy_pass http://prometheus_backend/;
|
||||
proxy_redirect / /prometheus/;
|
||||
# HTTP Basic Authentication
|
||||
auth_basic "Prometheus Monitoring";
|
||||
auth_basic_user_file /etc/nginx/passwords/monitoring.htpasswd;
|
||||
|
||||
# Rate limiting
|
||||
limit_req zone=api burst=10 nodelay;
|
||||
|
||||
proxy_pass http://prometheus_backend/prometheus/;
|
||||
proxy_redirect /prometheus/ /prometheus/;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
@@ -23,7 +30,7 @@ location /prometheus/ {
|
||||
|
||||
# Health check endpoint
|
||||
location /prometheus/-/healthy {
|
||||
proxy_pass http://prometheus_backend/-/healthy;
|
||||
proxy_pass http://prometheus_backend/prometheus/-/healthy;
|
||||
proxy_set_header Host $host;
|
||||
access_log off;
|
||||
}
|
||||
Reference in New Issue
Block a user