Skip to content

Commit af4e580

Browse files
committed
fix: [#28] resolve infra-status command and validate SSL certificate generation
- Fix infra-status Makefile target by removing check-infra-params dependency - Update infra-status to use simple 'Infrastructure status:' message - Resolve SSL certificate generation to use correct domain names - Implement intelligent domain detection in ssl-generate-test-certs.sh - Complete domain variable refactoring across configuration templates - Update nginx templates to use full domain names consistently - Validate all fixes through comprehensive e2e test (13/13 health checks passed) - Document SSL automation and deployment workflow improvements Key improvements: - SSL certificates now generated with correct names (tracker.test.local.crt vs tracker.tracker.test.local.crt) - infra-status command works without requiring ENVIRONMENT_TYPE parameter - All HTTPS endpoints functional with proper SSL certificate handling - Complete twelve-factor deployment workflow validated end-to-end
1 parent 0ee2416 commit af4e580

27 files changed

+165
-109
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ infra-destroy: check-infra-params ## Destroy infrastructure
107107
@echo "Destroying infrastructure with environment file: $(ENVIRONMENT_FILE)"
108108
ENVIRONMENT_TYPE=$(ENVIRONMENT_TYPE) ENVIRONMENT_FILE=$(ENVIRONMENT_FILE) $(SCRIPTS_DIR)/provision-infrastructure.sh destroy
109109

110-
infra-status: check-infra-params ## Show infrastructure status
111-
@echo "Infrastructure status for $(ENVIRONMENT) on $(PROVIDER):"
110+
infra-status: ## Show infrastructure status
111+
@echo "Infrastructure status:"
112112
@cd $(TERRAFORM_DIR) && tofu show -no-color | grep -E "(vm_ip|vm_status)" || echo "No infrastructure found"
113113

114114
infra-refresh-state: check-infra-params ## Refresh Terraform state to detect IP changes

application/share/bin/ssl-configure-nginx.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ process_template() {
105105
log_info "Processing template: $(basename "${template_file}")"
106106

107107
# Use envsubst to substitute domain name, then convert ${DOLLAR} back to $
108-
if ! DOMAIN_NAME="${DOMAIN}" envsubst "\${DOMAIN_NAME}" < "${template_file}" | sed "s/\${DOLLAR}/\$/g" > "${output_file}"; then
108+
if ! TRACKER_DOMAIN="${DOMAIN}" envsubst "\${TRACKER_DOMAIN}" < "${template_file}" | sed "s/\${DOLLAR}/\$/g" > "${output_file}"; then
109109
log_error "Failed to process template: $(basename "${template_file}")"
110110
exit 1
111111
fi

application/share/bin/ssl-generate-test-certs.sh

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -230,28 +230,41 @@ main() {
230230
sudo chmod 700 "${private_dir}"
231231
fi
232232

233-
# Generate certificates for required subdomains
234-
local subdomains=("tracker.${DOMAIN}" "grafana.${DOMAIN}")
233+
# Generate certificates for required domains
234+
# Use domain directly if it already contains "tracker." (new format)
235+
# Otherwise construct subdomain (legacy format)
236+
local domains=()
237+
if [[ "${DOMAIN}" == tracker.* ]]; then
238+
# Domain is already a full tracker domain, use as-is
239+
domains+=("${DOMAIN}")
240+
# Extract base domain and add grafana subdomain
241+
local base_domain="${DOMAIN#tracker.}"
242+
domains+=("grafana.${base_domain}")
243+
else
244+
# Legacy behavior: construct subdomains
245+
domains+=("tracker.${DOMAIN}" "grafana.${DOMAIN}")
246+
fi
247+
235248
local generation_failed=false
236249

237-
for subdomain in "${subdomains[@]}"; do
238-
if ! generate_certificate "${subdomain}"; then
250+
for domain in "${domains[@]}"; do
251+
if ! generate_certificate "${domain}"; then
239252
generation_failed=true
240253
fi
241254
done
242255

243256
# Check if any certificate generation failed
244257
if [[ "${generation_failed}" == "true" ]]; then
245-
log_error "Certificate generation failed for one or more subdomains"
258+
log_error "Certificate generation failed for one or more domains"
246259
log_error "Please check the error messages above and resolve any issues"
247260
exit 1
248261
fi
249262

250263
# Show certificate information
251264
log_info ""
252265
log_info "Certificate generation completed successfully!"
253-
for subdomain in "${subdomains[@]}"; do
254-
show_certificate_info "${subdomain}"
266+
for domain in "${domains[@]}"; do
267+
show_certificate_info "${domain}"
255268
done
256269

257270
# Show next steps

docs/adr/004-configuration-approach-files-vs-environment-variables.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ GF_SECURITY_ADMIN_PASSWORD=secure_password
102102
```bash
103103
# Network configuration that varies by deployment
104104
EXTERNAL_IP=192.168.1.100
105-
DOMAIN_NAME=tracker.example.com
105+
TRACKER_DOMAIN=tracker.example.com
106106

107107
# Infrastructure differences
108108
ON_REVERSE_PROXY=true
@@ -121,7 +121,7 @@ MYSQL_DATABASE=torrust_tracker
121121

122122
```bash
123123
# SSL certificate automation
124-
DOMAIN_NAME=tracker.example.com
124+
TRACKER_DOMAIN=tracker.example.com
125125
CERTBOT_EMAIL=admin@example.com
126126
ENABLE_SSL=true
127127

@@ -199,7 +199,7 @@ GF_SECURITY_ADMIN_USER=admin
199199
GF_SECURITY_ADMIN_PASSWORD=admin_password
200200

201201
# Deployment automation
202-
DOMAIN_NAME=tracker.example.com
202+
TRACKER_DOMAIN=tracker.example.com
203203
CERTBOT_EMAIL=admin@example.com
204204
ENABLE_SSL=true
205205
ENABLE_DB_BACKUPS=true
@@ -277,7 +277,7 @@ deployment process are stored as environment variables, even though they are not
277277
278278
```bash
279279
# SSL certificate automation
280-
DOMAIN_NAME=tracker.example.com
280+
TRACKER_DOMAIN=tracker.example.com
281281
CERTBOT_EMAIL=admin@example.com
282282
ENABLE_SSL=true
283283

docs/guides/deployment-guide.md

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -807,29 +807,31 @@ echo "Updated $SUBDOMAIN.$DOMAIN A record to $NEW_IP"
807807

808808
### Domain Configuration Behavior
809809

810-
**Important**: The current system automatically adds subdomain prefixes to the main domain
811-
configured in `DOMAIN_NAME`.
810+
**Important**: The system now uses explicit full domain names for each service instead of
811+
automatic subdomain concatenation. Configure each service domain separately.
812812

813813
#### Current Behavior
814814

815815
When you configure:
816816

817817
```bash
818-
DOMAIN_NAME=torrust-demo.dev
818+
TRACKER_DOMAIN=tracker.torrust-demo.dev
819+
GRAFANA_DOMAIN=grafana.torrust-demo.dev
819820
```
820821

821-
The system automatically creates:
822+
The system uses these exact domain names:
822823

823-
- **Tracker service**: `tracker.torrust-demo.dev`
824-
- **Grafana service**: `grafana.torrust-demo.dev`
824+
- **Tracker service**: Uses `TRACKER_DOMAIN` value directly
825+
- **Grafana service**: Uses `GRAFANA_DOMAIN` value directly
825826

826827
#### Required Domain Configuration
827828

828-
- **Staging**: `DOMAIN_NAME=torrust-demo.dev`
829-
- **Production**: `DOMAIN_NAME=torrust-demo.com`
830-
831-
> **Note**: Future improvements will allow declaring full domain names for each service
832-
> independently, but this is the current implementation that must be followed.
829+
- **Staging**:
830+
- `TRACKER_DOMAIN=tracker.torrust-demo.dev`
831+
- `GRAFANA_DOMAIN=grafana.torrust-demo.dev`
832+
- **Production**:
833+
- `TRACKER_DOMAIN=tracker.torrust-demo.com`
834+
- `GRAFANA_DOMAIN=grafana.torrust-demo.com`
833835

834836
### Development Environment Configuration
835837

@@ -853,7 +855,7 @@ VM_VCPUS=4
853855
VM_DISK_SIZE=30
854856

855857
# Network Configuration
856-
DOMAIN_NAME=test.local
858+
TRACKER_DOMAIN=tracker.test.local
857859
GRAFANA_DOMAIN=grafana.test.local
858860

859861
# SSL Configuration
@@ -965,7 +967,7 @@ VM_LOCATION=nbg1 # Nuremberg
965967
VM_IMAGE=ubuntu-24.04
966968

967969
# === DOMAIN CONFIGURATION ===
968-
DOMAIN_NAME=torrust-demo.dev
970+
TRACKER_DOMAIN=tracker.torrust-demo.dev
969971
GRAFANA_DOMAIN=grafana.torrust-demo.dev
970972

971973
# === SSL CONFIGURATION ===
@@ -1012,7 +1014,7 @@ VM_LOCATION=nbg1 # Nuremberg
10121014
VM_IMAGE=ubuntu-24.04
10131015

10141016
# === DOMAIN CONFIGURATION ===
1015-
DOMAIN_NAME=torrust-demo.com
1017+
TRACKER_DOMAIN=tracker.torrust-demo.com
10161018
GRAFANA_DOMAIN=grafana.torrust-demo.com
10171019

10181020
# === SSL CONFIGURATION ===

docs/guides/dns-setup-for-testing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ cd infrastructure/terraform
4040
tofu output vm_ip
4141

4242
# Or check from your environment
43-
grep DOMAIN_NAME infrastructure/config/environments/production-hetzner.env
43+
grep TRACKER_DOMAIN infrastructure/config/environments/production-hetzner.env
4444
```
4545

4646
#### Step 2: Create DNS A Records

docs/guides/providers/hetzner/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,8 @@ PROVIDER=hetzner
208208
# Token file paths (for reference)
209209
HETZNER_API_TOKEN_CONFIG=infrastructure/config/providers/hetzner.env
210210
HETZNER_DNS_TOKEN_CONFIG=infrastructure/config/providers/hetzner.env
211-
DOMAIN_NAME=your-domain.com
211+
TRACKER_DOMAIN=tracker.example.com
212+
GRAFANA_DOMAIN=grafana.example.com
212213
TRACKER_SUBDOMAIN=tracker.your-domain.com
213214
GRAFANA_SUBDOMAIN=grafana.your-domain.com
214215
```

docs/guides/providers/hetzner/hetzner-cloud-setup-guide.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,8 @@ Key staging settings:
216216

217217
```bash
218218
# Domain Configuration
219-
DOMAIN_NAME=tracker.torrust-demo.dev
219+
TRACKER_DOMAIN=tracker.torrust-demo.dev
220+
GRAFANA_DOMAIN=grafana.torrust-demo.dev
220221
GRAFANA_DOMAIN=grafana.torrust-demo.dev
221222
CERTBOT_EMAIL=admin@torrust-demo.dev
222223

@@ -252,7 +253,8 @@ Key production settings:
252253

253254
```bash
254255
# Domain Configuration
255-
DOMAIN_NAME=tracker.torrust-demo.com
256+
TRACKER_DOMAIN=tracker.torrust-demo.com
257+
GRAFANA_DOMAIN=grafana.torrust-demo.com
256258
GRAFANA_DOMAIN=grafana.torrust-demo.com
257259
CERTBOT_EMAIL=admin@torrust-demo.com
258260

docs/guides/ssl-testing-guide.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -402,10 +402,10 @@ cd /home/torrust/github/torrust/torrust-tracker-demo
402402
```bash
403403
# Check environment file exists and is readable
404404
ls -la infrastructure/config/environments/local.env
405-
cat infrastructure/config/environments/local.env | grep DOMAIN_NAME
405+
cat infrastructure/config/environments/local.env | grep TRACKER_DOMAIN
406406

407407
# Verify variables are exported
408-
echo "DOMAIN_NAME: ${DOMAIN_NAME:-not_set}"
408+
echo "TRACKER_DOMAIN: ${TRACKER_DOMAIN:-not_set}"
409409
echo "DOLLAR: ${DOLLAR:-not_set}"
410410
```
411411

@@ -682,7 +682,7 @@ environment variables.
682682

683683
**Key Findings**:
684684

685-
- ✅ HTTP template processes correctly with `DOMAIN_NAME=test.local`
685+
- ✅ HTTP template processes correctly with `TRACKER_DOMAIN=tracker.test.local`
686686
- ✅ Nginx variables are properly preserved with `DOLLAR='$'` export
687687
- ✅ Domain substitution works for `tracker.test.local` and `grafana.test.local`
688688
- ✅ Template processing is automated in `deploy-app.sh`

docs/issues/21-complete-application-installation-automation.md

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,8 @@ Based on current implementation status, these areas need extension or still requ
278278

279279
2. **Environment Configuration**: (one-time, deployment-specific)
280280

281-
-**Cannot automate**: Configure `DOMAIN_NAME` and `CERTBOT_EMAIL` (deployment-specific values)
281+
-**Cannot automate**: Configure `TRACKER_DOMAIN`, `GRAFANA_DOMAIN` and `CERTBOT_EMAIL`
282+
(deployment-specific values)
282283
- ⏱️ **Time required**: ~2 minutes
283284
- 📋 **Guidance**: Template with clear placeholders and validation
284285

@@ -467,8 +468,9 @@ Variables already added:
467468

468469
```bash
469470
# === SSL CERTIFICATE CONFIGURATION ===
470-
# Domain name for SSL certificates (required for production)
471-
DOMAIN_NAME=REPLACE_WITH_YOUR_DOMAIN
471+
# Domain names for SSL certificates (required for production)
472+
TRACKER_DOMAIN=REPLACE_WITH_YOUR_TRACKER_DOMAIN
473+
GRAFANA_DOMAIN=REPLACE_WITH_YOUR_GRAFANA_DOMAIN
472474
# Email for Let's Encrypt certificate registration (required for production)
473475
CERTBOT_EMAIL=REPLACE_WITH_YOUR_EMAIL
474476
# Enable SSL certificates (true for production, false for testing)
@@ -487,8 +489,9 @@ Variables already added:
487489

488490
```bash
489491
# === SSL CERTIFICATE CONFIGURATION ===
490-
# Domain name for SSL certificates (local testing with fake domains)
491-
DOMAIN_NAME=test.local
492+
# Domain names for SSL certificates (local testing with fake domains)
493+
TRACKER_DOMAIN=tracker.test.local
494+
GRAFANA_DOMAIN=grafana.test.local
492495
# Email for certificate registration (test email for local)
493496
CERTBOT_EMAIL=test@test.local
494497
# Enable SSL certificates (true for production, false for testing)
@@ -532,7 +535,7 @@ validate_environment() {
532535

533536
**REQUIRED**: Extend this function to validate SSL variables:
534537

535-
- `DOMAIN_NAME` (should not be placeholder value)
538+
- `TRACKER_DOMAIN` and `GRAFANA_DOMAIN` (should not be placeholder values)
536539
- `CERTBOT_EMAIL` (should not be placeholder value)
537540
- `ENABLE_SSL` (should be true/false)
538541
- `ENABLE_DB_BACKUPS` (should be true/false)
@@ -699,7 +702,8 @@ The recommended workflow follows the [Torrust production deployment guide](https
699702
```bash
700703
# Step 1: Deploy with HTTP-only nginx configuration
701704
cp ../infrastructure/config/templates/application/nginx/nginx-http.conf.tpl /var/lib/torrust/proxy/etc/nginx-conf/default.conf
702-
sed -i "s/\${DOMAIN_NAME}/torrust-demo.com/g" /var/lib/torrust/proxy/etc/nginx-conf/default.conf
705+
sed -i "s/\${TRACKER_DOMAIN}/tracker.torrust-demo.com/g" /var/lib/torrust/proxy/etc/nginx-conf/default.conf
706+
sed -i "s/\${GRAFANA_DOMAIN}/grafana.torrust-demo.com/g" /var/lib/torrust/proxy/etc/nginx-conf/default.conf
703707
docker compose up -d
704708
```
705709

@@ -745,7 +749,8 @@ docker compose -f compose.test.yaml up -d pebble pebble-challtestsrv
745749

746750
# Step 2: Set up test nginx configuration
747751
cp ../infrastructure/config/templates/application/nginx/nginx-http.conf.tpl /var/lib/torrust/proxy/etc/nginx-conf/default.conf
748-
sed -i "s/\${DOMAIN_NAME}/test.local/g" /var/lib/torrust/proxy/etc/nginx-conf/default.conf
752+
sed -i "s/\${TRACKER_DOMAIN}/tracker.test.local/g" /var/lib/torrust/proxy/etc/nginx-conf/default.conf
753+
sed -i "s/\${GRAFANA_DOMAIN}/grafana.test.local/g" /var/lib/torrust/proxy/etc/nginx-conf/default.conf
749754

750755
# Step 3: Start application services
751756
docker compose -f compose.test.yaml up -d
@@ -1165,7 +1170,8 @@ twelve-factor deployment scripts.
11651170
```bash
11661171
# Add these new variables to existing template
11671172
# === SSL CERTIFICATE CONFIGURATION ===
1168-
DOMAIN_NAME=REPLACE_WITH_YOUR_DOMAIN
1173+
TRACKER_DOMAIN=REPLACE_WITH_YOUR_TRACKER_DOMAIN
1174+
GRAFANA_DOMAIN=REPLACE_WITH_YOUR_GRAFANA_DOMAIN
11691175
CERTBOT_EMAIL=REPLACE_WITH_YOUR_EMAIL
11701176
ENABLE_SSL=true
11711177
@@ -1179,7 +1185,8 @@ BACKUP_RETENTION_DAYS=7
11791185
```bash
11801186
# Add these new variables to existing template
11811187
# === SSL CERTIFICATE CONFIGURATION ===
1182-
DOMAIN_NAME=test.local
1188+
TRACKER_DOMAIN=tracker.test.local
1189+
GRAFANA_DOMAIN=grafana.test.local
11831190
CERTBOT_EMAIL=test@test.local
11841191
ENABLE_SSL=false
11851192
@@ -1218,15 +1225,15 @@ setup_ssl_automation() {
12181225
log_info "Setting up SSL certificates (Let's Encrypt)..."
12191226
12201227
# Validate environment variables
1221-
if [[ -z "${DOMAIN_NAME:-}" || -z "${CERTBOT_EMAIL:-}" ]]; then
1222-
log_error "SSL requires DOMAIN_NAME and CERTBOT_EMAIL in environment config"
1228+
if [[ -z "${TRACKER_DOMAIN:-}" || -z "${GRAFANA_DOMAIN:-}" || -z "${CERTBOT_EMAIL:-}" ]]; then
1229+
log_error "SSL requires TRACKER_DOMAIN, GRAFANA_DOMAIN and CERTBOT_EMAIL in environment config"
12231230
exit 1
12241231
fi
12251232
12261233
# DNS validation and certificate generation
12271234
vm_exec "${vm_ip}" "
12281235
cd /home/torrust/github/torrust/torrust-tracker-demo/application
1229-
./share/bin/ssl_setup.sh '${DOMAIN_NAME}' '${CERTBOT_EMAIL}'
1236+
./share/bin/ssl_setup.sh '${TRACKER_DOMAIN}' '${GRAFANA_DOMAIN}' '${CERTBOT_EMAIL}'
12301237
" "SSL certificate setup"
12311238
12321239
# Add SSL renewal crontab using template
@@ -1461,7 +1468,7 @@ This approach ensures **backward compatibility** while adding new automation fea
14611468
**Manual Steps That Will Still Be Required**:
14621469

14631470
- **DNS Configuration**: Point domain A records to server IP (one-time setup)
1464-
- **Environment Variables**: Configure `DOMAIN_NAME` and `CERTBOT_EMAIL` in production.env
1471+
- **Environment Variables**: Configure `TRACKER_DOMAIN`, `GRAFANA_DOMAIN` and `CERTBOT_EMAIL` in production.env
14651472
(one-time setup)
14661473
- **SSL Certificate Generation**: Run guided SSL setup script after DNS configuration (one-time setup)
14671474
- **Grafana Initial Setup**: Configure dashboards and data sources (optional, post-deployment)
@@ -1586,7 +1593,7 @@ optionally enable HTTPS functionality using the standalone SSL setup scripts.
15861593
- `grafana.yourdomain.com` → Server IP
15871594

15881595
3. **Environment Configuration**:
1589-
- `DOMAIN_NAME` set to your actual domain in `.env`
1596+
- `TRACKER_DOMAIN` and `GRAFANA_DOMAIN` set to your actual domains in `.env`
15901597
- `CERTBOT_EMAIL` set to your email address
15911598

15921599
### SSL Setup Workflow

0 commit comments

Comments
 (0)