Skip to content

Commit 290b070

Browse files
committed
docs: [#28] add domain-specific HSTS behavior documentation
- Add comprehensive .dev vs .com domain behavior explanation - Document browser HSTS preload list impact on .dev domains - Update nginx README.md with domain-specific security considerations - Update Hetzner cloud setup guide with domain choice guidance - Add troubleshooting section for browser HTTPS redirect issues - Clarify that .dev domains require HTTPS certificates for browser access - Explain why curl works but browsers force HTTPS for .dev domains - Provide solutions: use .com domains, install SSL, or use curl for testing - Remove obsolete nginx template files and add Let's Encrypt template
1 parent 3b21a8e commit 290b070

File tree

7 files changed

+729
-221
lines changed

7 files changed

+729
-221
lines changed

application/scripts/configure-app.sh

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -208,16 +208,44 @@ process_templates() {
208208
log_warning "Tracker template not found: ${templates_dir}/tracker.toml.tpl"
209209
fi
210210

211-
# Process nginx configuration (choose appropriate template based on SSL settings)
211+
# Process nginx configuration (choose appropriate template based on environment and SSL settings)
212212
local nginx_template
213-
if [[ "${ENABLE_SSL:-false}" == "true" ]]; then
214-
if [[ "${SSL_GENERATION_METHOD:-self-signed}" == "self-signed" ]]; then
215-
nginx_template="${templates_dir}/nginx/nginx-https-selfsigned.conf.tpl"
216-
else
217-
nginx_template="${templates_dir}/nginx/nginx-https-letsencrypt.conf.tpl"
218-
fi
219-
else
213+
214+
# First check if SSL is completely disabled
215+
if [[ "${ENABLE_SSL:-true}" != "true" ]]; then
216+
# SSL disabled: Always use HTTP-only template regardless of environment
220217
nginx_template="${templates_dir}/nginx/nginx-http.conf.tpl"
218+
log_info "SSL disabled (ENABLE_SSL=${ENABLE_SSL:-false}), using HTTP-only template"
219+
else
220+
# SSL enabled: Choose template based on environment type and SSL configuration
221+
# Progressive SSL configuration:
222+
# - development, testing, e2e: Self-signed HTTPS (for testing HTTPS config)
223+
# - staging, production: Let's Encrypt HTTPS or HTTP-only fallback
224+
225+
case "${ENVIRONMENT_TYPE:-development}" in
226+
development|testing|e2e)
227+
# Development environments: Use self-signed HTTPS to test nginx HTTPS configuration
228+
nginx_template="${templates_dir}/nginx/nginx-https-selfsigned.conf.tpl"
229+
log_info "Using self-signed HTTPS template for ${ENVIRONMENT_TYPE:-development} environment"
230+
;;
231+
staging|production)
232+
# Production-like environments: Use Let's Encrypt if properly configured, otherwise HTTP-only
233+
if [[ "${SSL_GENERATION_METHOD:-}" == "letsencrypt" ]]; then
234+
# Let's Encrypt explicitly configured
235+
nginx_template="${templates_dir}/nginx/nginx-https-letsencrypt.conf.tpl"
236+
log_info "Using Let's Encrypt HTTPS template for ${ENVIRONMENT_TYPE:-production} environment"
237+
else
238+
# Default to HTTP-only for staging/production until proper SSL is configured
239+
nginx_template="${templates_dir}/nginx/nginx-http.conf.tpl"
240+
log_info "Using HTTP-only template for ${ENVIRONMENT_TYPE:-production} environment (Let's Encrypt not configured)"
241+
fi
242+
;;
243+
*)
244+
# Unknown environment: Default to HTTP-only for safety
245+
nginx_template="${templates_dir}/nginx/nginx-http.conf.tpl"
246+
log_warning "Unknown environment type '${ENVIRONMENT_TYPE}', defaulting to HTTP-only template"
247+
;;
248+
esac
221249
fi
222250

223251
if [[ -f "$nginx_template" ]]; then

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ NGINX_CONFIG_DIR="/var/lib/torrust/proxy/etc/nginx-conf"
4141
NGINX_CONFIG_FILE="${NGINX_CONFIG_DIR}/default.conf"
4242
TEMPLATES_DIR="${PROJECT_ROOT}/infrastructure/config/templates"
4343
HTTP_TEMPLATE="${TEMPLATES_DIR}/application/nginx/nginx-http.conf.tpl"
44-
HTTPS_EXTENSION_TEMPLATE="${TEMPLATES_DIR}/application/nginx/nginx-https-extension.conf.tpl"
44+
HTTPS_LETSENCRYPT_TEMPLATE="${TEMPLATES_DIR}/application/nginx/nginx-https-letsencrypt.conf.tpl"
4545

4646
# Check prerequisites
4747
check_prerequisites() {
@@ -60,9 +60,9 @@ check_prerequisites() {
6060
exit 1
6161
fi
6262

63-
if [[ ! -f "${HTTPS_EXTENSION_TEMPLATE}" ]]; then
64-
log_error "HTTPS extension template not found: ${HTTPS_EXTENSION_TEMPLATE}"
65-
log_error "Please create the HTTPS extension template first"
63+
if [[ ! -f "${HTTPS_LETSENCRYPT_TEMPLATE}" ]]; then
64+
log_error "HTTPS Let's Encrypt template not found: ${HTTPS_LETSENCRYPT_TEMPLATE}"
65+
log_error "Please create the HTTPS Let's Encrypt template first"
6666
exit 1
6767
fi
6868

@@ -126,8 +126,8 @@ generate_nginx_config() {
126126
# Process HTTP template
127127
process_template "${HTTP_TEMPLATE}" "${http_config}"
128128

129-
# Process HTTPS extension template
130-
process_template "${HTTPS_EXTENSION_TEMPLATE}" "${https_extension}"
129+
# Process HTTPS Let's Encrypt template
130+
process_template "${HTTPS_LETSENCRYPT_TEMPLATE}" "${https_extension}"
131131

132132
# Combine HTTP and HTTPS configurations
133133
log_info "Combining HTTP and HTTPS configurations..."

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

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,22 @@ This guide covers two deployment environments:
1313
Both environments use **floating IPs** for stable DNS configuration and leverage
1414
**Hetzner DNS** for complete zone management.
1515

16+
### Domain Choice Considerations
17+
18+
#### `.dev` Domains (HSTS Preload Required)
19+
20+
- **⚠️ Browser Behavior**: ALL browsers automatically redirect HTTP → HTTPS
21+
- **🔒 SSL Required**: HTTPS certificates mandatory for browser access
22+
- **✅ Security**: Enhanced security with forced encryption
23+
- **🧪 Testing**: Use curl for HTTP API testing during development
24+
25+
#### `.com` Domains (Standard HTTP/HTTPS)
26+
27+
- **🌐 Normal Behavior**: Browsers respect server HTTP/HTTPS configuration
28+
- **🔧 Flexibility**: Can start with HTTP and migrate to HTTPS when ready
29+
- **📈 Production**: Standard choice for production services
30+
- **🛠️ Development**: Easier for development and testing workflows
31+
1632
### Floating IP Architecture
1733

1834
The deployment uses dedicated floating IPs to maintain stable DNS records across
@@ -199,6 +215,10 @@ deployment target:
199215

200216
For testing and development using the staging domain:
201217

218+
⚠️ **Important**: `.dev` domains are on Chrome's HSTS preload list, meaning ALL browsers
219+
automatically redirect HTTP to HTTPS. For testing without SSL certificates, use curl
220+
commands or consider using a `.com` domain instead.
221+
202222
```bash
203223
# Create staging environment configuration
204224
make infra-config-staging PROVIDER=hetzner
@@ -716,7 +736,55 @@ by Hetzner. Use `hcloud server-type list` for current availability.
716736
- `infrastructure/config/providers/hetzner.env`
717737
- Environment variable: `export HETZNER_API_TOKEN=your_token_here`
718738

719-
#### 3. Provider Configuration Variable Collision
739+
#### 3. Browser HTTPS Redirect Issues with .dev Domains
740+
741+
**Problem**: Web browsers automatically redirect HTTP to HTTPS for `.dev` domains, even when server
742+
only serves HTTP.
743+
744+
**Root Cause**: `.dev` domains are on Chrome's HSTS preload list, which ALL browsers respect.
745+
746+
**Symptoms**:
747+
748+
```bash
749+
# These work fine with curl
750+
curl http://tracker.torrust-demo.dev/health # ✅ Works
751+
curl https://tracker.torrust-demo.dev/health # ❌ May fail if no SSL
752+
753+
# But browsers automatically redirect HTTP → HTTPS
754+
http://tracker.torrust-demo.dev → https://tracker.torrust-demo.dev (automatic)
755+
```
756+
757+
**Solutions**:
758+
759+
1. **Use .com domains for testing** (no HSTS preload):
760+
761+
```bash
762+
# .com domains work normally with HTTP in browsers
763+
http://tracker.example.com # Works in browsers if server serves HTTP
764+
```
765+
766+
2. **Install SSL certificates for .dev domains**:
767+
768+
```bash
769+
# Deploy with HTTPS support
770+
make app-deploy ENVIRONMENT_TYPE=staging ENVIRONMENT_FILE=staging-hetzner
771+
772+
# Access via HTTPS
773+
https://tracker.torrust-demo.dev
774+
```
775+
776+
3. **Use curl for HTTP testing with .dev domains**:
777+
778+
```bash
779+
# For API testing during development
780+
curl http://tracker.torrust-demo.dev/api/health_check
781+
curl "http://tracker.torrust-demo.dev/api/v1/stats?token=TOKEN"
782+
```
783+
784+
**Important**: This behavior is **specific to .dev domains only**. Regular .com domains
785+
do not have this HSTS preload requirement.
786+
787+
#### 4. Provider Configuration Variable Collision
720788

721789
**Problem**: Error "Configuration script not found" in provider directory.
722790

0 commit comments

Comments
 (0)