Skip to content
This repository was archived by the owner on Oct 10, 2025. It is now read-only.

Commit 70b8286

Browse files
committed
feat: [#28] implement comprehensive DNS infrastructure with health check fixes
- Add Hetzner DNS setup guide with complete API automation - Create DNS management script with zone and record operations - Implement Grafana subdomain configuration guide - Add DNS testing setup documentation - Fix health check script to use environment-specific admin tokens - Update project dictionary with new DNS-related terms Infrastructure improvements: - health-check.sh now loads environment variables properly - Dynamic admin token resolution from environment files - Better error reporting for API endpoint testing - Fallback to default token with clear user guidance Documentation additions: - Complete Hetzner DNS API integration guide (600+ lines) - Automated DNS record management with error handling - Grafana subdomain setup with nginx proxy configuration - DNS propagation testing and troubleshooting guides Scripts added: - manage-hetzner-dns.sh: Full DNS automation with REST API - Colored output, error handling, and validation - Zone creation, record management, and bulk operations All changes pass infrastructure CI tests (infra-test-ci)
1 parent a0b8483 commit 70b8286

File tree

6 files changed

+1644
-1
lines changed

6 files changed

+1644
-1
lines changed
Lines changed: 357 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,357 @@
1+
# DNS Setup Guide for Domain-Based Testing
2+
3+
This guide explains how to configure DNS to use your domain for manual testing
4+
of the Torrust Tracker with real URLs instead of IP addresses.
5+
6+
## 🎯 Overview
7+
8+
When you deploy to Hetzner Cloud, you get an IP address (e.g., `138.199.166.49`),
9+
but for proper testing you want to use your configured domain
10+
(e.g., `tracker.torrust-demo.dev`) to:
11+
12+
- Test REST API endpoints with proper URLs
13+
- Perform UDP/HTTP tracker announces with domain names
14+
- Access web interfaces (Grafana) with friendly URLs
15+
- Validate SSL certificate functionality
16+
17+
### Subdomain Architecture
18+
19+
The infrastructure implements a **professional subdomain-based architecture**
20+
with separate domains for different services:
21+
22+
- `tracker.yourdomain.com` - Main tracker API and HTTP tracker endpoints
23+
- `grafana.yourdomain.com` - Grafana monitoring dashboard
24+
25+
This provides proper service isolation and follows professional deployment
26+
patterns. nginx acts as a reverse proxy routing traffic to the appropriate
27+
containerized services based on the subdomain.
28+
29+
## 🌐 DNS Configuration Methods
30+
31+
### Method 1: Real DNS Setup (Recommended)
32+
33+
If you control the domain, set up proper DNS records:
34+
35+
#### Step 1: Get Your Server IP
36+
37+
```bash
38+
# Get the current server IP from Terraform
39+
cd infrastructure/terraform
40+
tofu output vm_ip
41+
42+
# Or check from your environment
43+
grep DOMAIN_NAME infrastructure/config/environments/production-hetzner.env
44+
```
45+
46+
#### Step 2: Create DNS A Records
47+
48+
Access your DNS provider (cdmon.com, Cloudflare, Route53, etc.) and create:
49+
50+
```text
51+
# Main tracker subdomain
52+
Type: A
53+
Name: tracker
54+
Value: <your_server_ip>
55+
TTL: 300 (5 minutes for testing)
56+
57+
# Grafana monitoring subdomain (recommended)
58+
Type: A
59+
Name: grafana
60+
Value: <your_server_ip>
61+
TTL: 300 (5 minutes for testing)
62+
```
63+
64+
#### Step 3: Verify DNS Propagation
65+
66+
```bash
67+
# Test DNS resolution for both subdomains
68+
nslookup tracker.torrust-demo.dev
69+
nslookup grafana.torrust-demo.dev
70+
dig tracker.torrust-demo.dev
71+
dig grafana.torrust-demo.dev
72+
73+
# Test connectivity
74+
ping tracker.torrust-demo.dev
75+
ping grafana.torrust-demo.dev
76+
```
77+
78+
### Method 2: Local DNS Override (Quick Testing)
79+
80+
For immediate testing without DNS changes:
81+
82+
```bash
83+
# Get your server IP
84+
SERVER_IP=$(cd infrastructure/terraform && tofu output -raw vm_ip)
85+
86+
# Add to /etc/hosts
87+
echo "$SERVER_IP tracker.torrust-demo.dev" | sudo tee -a /etc/hosts
88+
echo "$SERVER_IP grafana.torrust-demo.dev" | sudo tee -a /etc/hosts
89+
90+
# Verify the entries
91+
grep torrust-demo.dev /etc/hosts
92+
93+
# Test resolution
94+
ping tracker.torrust-demo.dev
95+
ping grafana.torrust-demo.dev
96+
```
97+
98+
**Note**: This only affects your local machine. Other users won't be able to access the domain.
99+
100+
## 🧪 Manual Testing Examples
101+
102+
### 1. REST API Testing
103+
104+
Once DNS is configured, test API endpoints:
105+
106+
```bash
107+
# Health check
108+
curl -s https://tracker.torrust-demo.dev/api/health_check | jq
109+
110+
# Get admin token from server
111+
ADMIN_TOKEN=$(ssh [email protected] \
112+
"grep TRACKER_ADMIN_TOKEN /var/lib/torrust/compose/.env | cut -d'=' -f2 | tr -d '\"'")
113+
114+
# Statistics endpoint
115+
curl -s "https://tracker.torrust-demo.dev/api/v1/stats?token=$ADMIN_TOKEN" | jq
116+
117+
# Metrics endpoint (Prometheus format)
118+
curl -s https://tracker.torrust-demo.dev/metrics | head -20
119+
```
120+
121+
### 2. UDP Tracker Testing
122+
123+
Use the Torrust Tracker client tools with your domain:
124+
125+
```bash
126+
# Clone tracker repository for client tools
127+
git clone https://github.com/torrust/torrust-tracker
128+
cd torrust-tracker
129+
130+
# Test UDP tracker port 6868
131+
cargo run -p torrust-tracker-client --bin udp_tracker_client announce \
132+
udp://tracker.torrust-demo.dev:6868/announce \
133+
9c38422213e30bff212b30c360d26f9a02136422 | jq
134+
135+
# Test UDP tracker port 6969
136+
cargo run -p torrust-tracker-client --bin udp_tracker_client announce \
137+
udp://tracker.torrust-demo.dev:6969/announce \
138+
9c38422213e30bff212b30c360d26f9a02136422 | jq
139+
```
140+
141+
### 3. HTTP Tracker Testing
142+
143+
```bash
144+
# Test HTTP tracker through nginx proxy
145+
cargo run -p torrust-tracker-client --bin http_tracker_client announce \
146+
https://tracker.torrust-demo.dev \
147+
9c38422213e30bff212b30c360d26f9a02136422 | jq
148+
149+
# Test HTTP tracker scrape
150+
cargo run -p torrust-tracker-client --bin http_tracker_client scrape \
151+
https://tracker.torrust-demo.dev \
152+
9c38422213e30bff212b30c360d26f9a02136422 | jq
153+
```
154+
155+
### 4. Web Interface Access
156+
157+
```bash
158+
# Get Grafana credentials
159+
160+
"grep GF_SECURITY_ADMIN /var/lib/torrust/compose/.env"
161+
162+
# Access Grafana with subdomain (requires nginx configuration)
163+
open https://grafana.torrust-demo.dev
164+
165+
# Alternative: Access via port (current setup)
166+
open https://tracker.torrust-demo.dev:3000
167+
```
168+
169+
## 🔒 SSL Certificate Handling
170+
171+
### Current Setup: Self-Signed Certificates
172+
173+
Your deployment uses self-signed certificates, which means:
174+
175+
- ✅ HTTPS encryption works
176+
- ⚠️ Browsers show security warnings
177+
- ⚠️ Need to bypass certificate verification for testing
178+
179+
### Testing with Self-Signed Certificates
180+
181+
```bash
182+
# Bypass certificate verification
183+
curl -k -s https://tracker.torrust-demo.dev/api/health_check | jq
184+
185+
# Accept certificate in browser:
186+
# Chrome: "Advanced" → "Proceed to tracker.torrust-demo.dev (unsafe)"
187+
# Firefox: "Advanced" → "Accept the Risk and Continue"
188+
```
189+
190+
### Upgrade to Let's Encrypt (Optional)
191+
192+
For real SSL certificates, you can implement Let's Encrypt automation:
193+
194+
```bash
195+
# Example: Add Let's Encrypt support
196+
# This would require implementing certbot automation in the deployment scripts
197+
# Currently not automated - manual setup required
198+
```
199+
200+
## 🎯 Complete Testing Workflow
201+
202+
Here's a complete testing workflow using your domain:
203+
204+
### Step 1: Verify DNS and Connectivity
205+
206+
```bash
207+
# Test DNS resolution
208+
nslookup tracker.torrust-demo.dev
209+
210+
# Test basic connectivity
211+
curl -k -I https://tracker.torrust-demo.dev
212+
```
213+
214+
### Step 2: Test All Endpoints
215+
216+
```bash
217+
# Health check
218+
curl -k -s https://tracker.torrust-demo.dev/api/health_check
219+
220+
# Get admin token
221+
ADMIN_TOKEN=$(ssh [email protected] \
222+
"grep TRACKER_ADMIN_TOKEN /var/lib/torrust/compose/.env | cut -d'=' -f2 | tr -d '\"'")
223+
224+
# Statistics
225+
curl -k -s "https://tracker.torrust-demo.dev/api/v1/stats?token=$ADMIN_TOKEN"
226+
227+
# Test UDP tracker
228+
cd torrust-tracker
229+
cargo run -p torrust-tracker-client --bin udp_tracker_client announce \
230+
udp://tracker.torrust-demo.dev:6868/announce \
231+
9c38422213e30bff212b30c360d26f9a02136422
232+
233+
# Test HTTP tracker
234+
cargo run -p torrust-tracker-client --bin http_tracker_client announce \
235+
https://tracker.torrust-demo.dev \
236+
9c38422213e30bff212b30c360d26f9a02136422
237+
```
238+
239+
### Step 3: Monitor and Debug
240+
241+
```bash
242+
# Check service status
243+
244+
"cd /home/torrust/github/torrust/torrust-tracker-demo/application && \
245+
docker compose --env-file /var/lib/torrust/compose/.env ps"
246+
247+
# Check logs
248+
249+
"cd /home/torrust/github/torrust/torrust-tracker-demo/application && \
250+
docker compose --env-file /var/lib/torrust/compose/.env logs tracker"
251+
252+
# Access Grafana for monitoring
253+
open https://tracker.torrust-demo.dev:3000
254+
```
255+
256+
## 🔧 Troubleshooting
257+
258+
### DNS Issues
259+
260+
```bash
261+
# Check if DNS is working
262+
dig tracker.torrust-demo.dev
263+
nslookup tracker.torrust-demo.dev
264+
265+
# Clear DNS cache (if needed)
266+
sudo systemctl flush-dns # Linux
267+
sudo dscacheutil -flushcache # macOS
268+
```
269+
270+
### Certificate Issues
271+
272+
```bash
273+
# Test certificate details
274+
openssl s_client -connect tracker.torrust-demo.dev:443 -servername tracker.torrust-demo.dev
275+
276+
# Check certificate on server
277+
278+
"openssl x509 -in /var/lib/torrust/proxy/certs/server.crt -text -noout"
279+
```
280+
281+
### Service Issues
282+
283+
```bash
284+
# Check if services are running
285+
286+
"cd /home/torrust/github/torrust/torrust-tracker-demo/application && \
287+
docker compose --env-file /var/lib/torrust/compose/.env ps"
288+
289+
# Check firewall rules
290+
ssh [email protected] "sudo ufw status verbose"
291+
292+
# Test ports directly
293+
nc -zv tracker.torrust-demo.dev 6868 # UDP tracker
294+
nc -zv tracker.torrust-demo.dev 6969 # UDP tracker
295+
nc -zv tracker.torrust-demo.dev 7070 # HTTP tracker
296+
nc -zv tracker.torrust-demo.dev 1212 # API port
297+
nc -zv tracker.torrust-demo.dev 3000 # Grafana
298+
```
299+
300+
## 📋 Quick Reference
301+
302+
### Essential URLs
303+
304+
- **Health Check**: `https://tracker.torrust-demo.dev/api/health_check`
305+
- **Statistics**: `https://tracker.torrust-demo.dev/api/v1/stats?token=TOKEN`
306+
- **Metrics**: `https://tracker.torrust-demo.dev/metrics`
307+
- **Grafana**: `https://grafana.torrust-demo.dev` (subdomain configured)
308+
309+
### UDP Tracker URLs
310+
311+
- **Port 6868**: `udp://tracker.torrust-demo.dev:6868/announce`
312+
- **Port 6969**: `udp://tracker.torrust-demo.dev:6969/announce`
313+
314+
## 📊 Accessing Grafana Dashboard
315+
316+
The Grafana monitoring dashboard is available at the dedicated subdomain:
317+
318+
### Access URL
319+
320+
```bash
321+
# Open Grafana in your browser
322+
https://grafana.torrust-demo.dev
323+
```
324+
325+
### Default Credentials
326+
327+
- **Username**: `admin`
328+
- **Password**: Check your `.env` file for `GF_SECURITY_ADMIN_PASSWORD`
329+
330+
### Browser Certificate Warning
331+
332+
Since the deployment uses self-signed certificates, your browser will show
333+
a security warning. This is expected for testing environments.
334+
335+
**To proceed:**
336+
337+
1. Click "Advanced" or "Show Details"
338+
2. Click "Proceed to grafana.torrust-demo.dev (unsafe)" or equivalent
339+
3. Accept the certificate for the current session
340+
341+
### Grafana Features
342+
343+
- **Torrust Tracker Metrics**: Pre-configured dashboards for tracker performance
344+
- **System Monitoring**: Server resource usage and health metrics
345+
- **Real-time Updates**: Live data from Prometheus scraping
346+
- **Historical Data**: Trend analysis and performance over time
347+
348+
### HTTP Tracker URLs
349+
350+
- **Announce**: `https://tracker.torrust-demo.dev/announce`
351+
- **Scrape**: `https://tracker.torrust-demo.dev/scrape`
352+
353+
### Common Test Infohash
354+
355+
- **Test Hash**: `9c38422213e30bff212b30c360d26f9a02136422`
356+
357+
This completes the DNS setup guide for domain-based testing of your Torrust Tracker deployment!

0 commit comments

Comments
 (0)