Skip to content

Commit 5fb9dba

Browse files
Update HTTPS config and documentation
1 parent 3013232 commit 5fb9dba

File tree

9 files changed

+358
-268
lines changed

9 files changed

+358
-268
lines changed

docs/local-forward-headers-testing.md

Lines changed: 54 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ Only accept forwarded headers from specific IP addresses.
207207

208208
```cmd
209209
set SERVICECONTROL_FORWARDEDHEADERS_ENABLED=true
210+
set SERVICECONTROL_FORWARDEDHEADERS_TRUSTALLPROXIES=
210211
set SERVICECONTROL_FORWARDEDHEADERS_KNOWNPROXIES=127.0.0.1,::1
211212
set SERVICECONTROL_FORWARDEDHEADERS_KNOWNNETWORKS=
212213
@@ -254,8 +255,9 @@ Trust all proxies within a network range.
254255

255256
```cmd
256257
set SERVICECONTROL_FORWARDEDHEADERS_ENABLED=true
257-
set SERVICECONTROL_FORWARDEDHEADERS_KNOWNNETWORKS=127.0.0.0/8,::1/128
258+
set SERVICECONTROL_FORWARDEDHEADERS_TRUSTALLPROXIES=
258259
set SERVICECONTROL_FORWARDEDHEADERS_KNOWNPROXIES=
260+
set SERVICECONTROL_FORWARDEDHEADERS_KNOWNNETWORKS=127.0.0.0/8,::1/128
259261
260262
dotnet run
261263
```
@@ -459,7 +461,7 @@ curl -H "X-Forwarded-Proto: https" -H "X-Forwarded-Host: example.com" -H "X-Forw
459461
"processed": {
460462
"scheme": "https",
461463
"host": "example.com",
462-
"remoteIpAddress": "192.168.1.1"
464+
"remoteIpAddress": "203.0.113.50"
463465
},
464466
"rawHeaders": {
465467
"xForwardedFor": "",
@@ -475,9 +477,55 @@ curl -H "X-Forwarded-Proto: https" -H "X-Forwarded-Host: example.com" -H "X-Forw
475477
}
476478
```
477479

478-
The `X-Forwarded-For` header contains multiple IPs representing the proxy chain. By default, ASP.NET Core's `ForwardLimit` is `1`, so only the last proxy IP is used.
480+
The `X-Forwarded-For` header contains multiple IPs representing the proxy chain. When `TrustAllProxies` is `true`, `ForwardLimit` is set to `null` (no limit), so the middleware processes all IPs and returns the original client IP (`203.0.113.50`).
481+
482+
### Scenario 9: Proxy Chain with Known Proxies (ForwardLimit = 1)
483+
484+
Test how ServiceControl handles multiple proxies when `TrustAllProxies` is `false`. In this case, `ForwardLimit` remains at its default of `1`, so only the last proxy IP is processed.
485+
486+
**Cleanup and start ServiceControl:**
487+
488+
```cmd
489+
set SERVICECONTROL_FORWARDEDHEADERS_ENABLED=true
490+
set SERVICECONTROL_FORWARDEDHEADERS_TRUSTALLPROXIES=
491+
set SERVICECONTROL_FORWARDEDHEADERS_KNOWNPROXIES=127.0.0.1,::1
492+
set SERVICECONTROL_FORWARDEDHEADERS_KNOWNNETWORKS=
493+
494+
dotnet run
495+
```
496+
497+
**Test with curl (simulating a proxy chain):**
498+
499+
```cmd
500+
curl -H "X-Forwarded-Proto: https" -H "X-Forwarded-Host: example.com" -H "X-Forwarded-For: 203.0.113.50, 10.0.0.1, 192.168.1.1" http://localhost:33333/debug/request-info | json
501+
```
479502

480-
### Scenario 9: Combined Known Proxies and Networks
503+
**Expected output:**
504+
505+
```json
506+
{
507+
"processed": {
508+
"scheme": "https",
509+
"host": "example.com",
510+
"remoteIpAddress": "192.168.1.1"
511+
},
512+
"rawHeaders": {
513+
"xForwardedFor": "203.0.113.50, 10.0.0.1",
514+
"xForwardedProto": "",
515+
"xForwardedHost": ""
516+
},
517+
"configuration": {
518+
"enabled": true,
519+
"trustAllProxies": false,
520+
"knownProxies": ["127.0.0.1", "::1"],
521+
"knownNetworks": []
522+
}
523+
}
524+
```
525+
526+
When `TrustAllProxies` is `false`, `ForwardLimit` remains at its default of `1`. The middleware only processes the rightmost IP from the chain (`192.168.1.1`). The remaining IPs (`203.0.113.50, 10.0.0.1`) stay in the `X-Forwarded-For` header. Compare this to Scenario 8 where `TrustAllProxies = true` returns the original client IP.
527+
528+
### Scenario 10: Combined Known Proxies and Networks
481529

482530
Test using both `KnownProxies` and `KnownNetworks` together.
483531

@@ -523,7 +571,7 @@ curl -H "X-Forwarded-Proto: https" -H "X-Forwarded-Host: example.com" -H "X-Forw
523571

524572
Headers are applied because the request comes from localhost (`::1`), which falls within the `::1/128` network even though it's not in the `knownProxies` list.
525573

526-
### Scenario 10: Partial Headers (Proto Only)
574+
### Scenario 11: Partial Headers (Proto Only)
527575

528576
Test that each forwarded header is processed independently. Only sending `X-Forwarded-Proto` should update the scheme while leaving host and remoteIpAddress unchanged.
529577

@@ -569,7 +617,7 @@ curl -H "X-Forwarded-Proto: https" http://localhost:33333/debug/request-info | j
569617

570618
Only the `scheme` changed to `https`. The `host` remains `localhost:33333` and `remoteIpAddress` remains `::1` because those headers weren't sent. Each header is processed independently.
571619

572-
### Scenario 11: IPv4/IPv6 Mismatch
620+
### Scenario 12: IPv4/IPv6 Mismatch
573621

574622
Demonstrates a common misconfiguration where only IPv4 localhost is configured but curl uses IPv6. This scenario shows why you should include both `127.0.0.1` and `::1` in your configuration.
575623

@@ -685,15 +733,6 @@ $env:SERVICECONTROL_FORWARDEDHEADERS_KNOWNPROXIES = $null
685733
$env:SERVICECONTROL_FORWARDEDHEADERS_KNOWNNETWORKS = $null
686734
```
687735

688-
**Bash (Git Bash, WSL, Linux, macOS):**
689-
690-
```bash
691-
unset SERVICECONTROL_FORWARDEDHEADERS_ENABLED
692-
unset SERVICECONTROL_FORWARDEDHEADERS_TRUSTALLPROXIES
693-
unset SERVICECONTROL_FORWARDEDHEADERS_KNOWNPROXIES
694-
unset SERVICECONTROL_FORWARDEDHEADERS_KNOWNNETWORKS
695-
```
696-
697736
## Quick Reference: Testing Other Instances
698737

699738
### ServiceControl.Audit

docs/local-https-testing.md

Lines changed: 14 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ Verify that HTTPS is working with a valid certificate.
9595
set SERVICECONTROL_HTTPS_ENABLED=true
9696
set SERVICECONTROL_HTTPS_CERTIFICATEPATH=C:\path\to\ServiceControl\.local\certs\localhost.pfx
9797
set SERVICECONTROL_HTTPS_CERTIFICATEPASSWORD=changeit
98+
set SERVICECONTROL_HTTPS_REDIRECTHTTPTOHTTPS=
99+
set SERVICECONTROL_HTTPS_PORT=
100+
set SERVICECONTROL_HTTPS_ENABLEHSTS=
98101
set SERVICECONTROL_FORWARDEDHEADERS_ENABLED=false
99102
100103
dotnet run
@@ -127,6 +130,9 @@ Verify that HTTP requests fail when only HTTPS is enabled.
127130
set SERVICECONTROL_HTTPS_ENABLED=true
128131
set SERVICECONTROL_HTTPS_CERTIFICATEPATH=C:\path\to\ServiceControl\.local\certs\localhost.pfx
129132
set SERVICECONTROL_HTTPS_CERTIFICATEPASSWORD=changeit
133+
set SERVICECONTROL_HTTPS_REDIRECTHTTPTOHTTPS=
134+
set SERVICECONTROL_HTTPS_PORT=
135+
set SERVICECONTROL_HTTPS_ENABLEHSTS=
130136
set SERVICECONTROL_FORWARDEDHEADERS_ENABLED=false
131137
132138
dotnet run
@@ -164,39 +170,16 @@ HTTP requests fail because Kestrel is listening for HTTPS but receives plaintext
164170
165171
## Testing Other Instances
166172

167-
The same scenarios can be run against ServiceControl.Audit and ServiceControl.Monitoring by:
168-
169-
1. Using the appropriate environment variable prefix
170-
2. Running from the correct project directory
171-
3. Using the correct port
173+
The scenarios above use ServiceControl (Primary). To test ServiceControl.Audit or ServiceControl.Monitoring:
172174

173-
**ServiceControl.Audit:**
175+
1. Use the appropriate environment variable prefix (see Instance Reference above)
176+
2. Use the corresponding project directory and port
174177

175-
```cmd
176-
set SERVICECONTROL_AUDIT_HTTPS_ENABLED=true
177-
set SERVICECONTROL_AUDIT_HTTPS_CERTIFICATEPATH=C:\path\to\ServiceControl\.local\certs\localhost.pfx
178-
set SERVICECONTROL_AUDIT_HTTPS_CERTIFICATEPASSWORD=changeit
179-
180-
dotnet run --project src/ServiceControl.Audit/ServiceControl.Audit.csproj
181-
```
182-
183-
```cmd
184-
curl --ssl-no-revoke https://localhost:44444/api
185-
```
186-
187-
**ServiceControl.Monitoring:**
188-
189-
```cmd
190-
set MONITORING_HTTPS_ENABLED=true
191-
set MONITORING_HTTPS_CERTIFICATEPATH=C:\path\to\ServiceControl\.local\certs\localhost.pfx
192-
set MONITORING_HTTPS_CERTIFICATEPASSWORD=changeit
193-
194-
dotnet run --project src/ServiceControl.Monitoring/ServiceControl.Monitoring.csproj
195-
```
196-
197-
```cmd
198-
curl --ssl-no-revoke https://localhost:33633/api
199-
```
178+
| Instance | Project Directory | Port | Env Var Prefix |
179+
|----------|-------------------|------|----------------|
180+
| ServiceControl (Primary) | `src\ServiceControl` | 33333 | `SERVICECONTROL_` |
181+
| ServiceControl.Audit | `src\ServiceControl.Audit` | 44444 | `SERVICECONTROL_AUDIT_` |
182+
| ServiceControl.Monitoring | `src\ServiceControl.Monitoring` | 33633 | `MONITORING_` |
200183

201184
## Troubleshooting
202185

@@ -253,18 +236,6 @@ $env:SERVICECONTROL_HTTPS_HSTSINCLUDESUBDOMAINS = $null
253236
$env:SERVICECONTROL_FORWARDEDHEADERS_ENABLED = $null
254237
```
255238

256-
**Bash (Git Bash, WSL, Linux, macOS):**
257-
258-
```bash
259-
unset SERVICECONTROL_HTTPS_ENABLED
260-
unset SERVICECONTROL_HTTPS_CERTIFICATEPATH
261-
unset SERVICECONTROL_HTTPS_CERTIFICATEPASSWORD
262-
unset SERVICECONTROL_HTTPS_ENABLEHSTS
263-
unset SERVICECONTROL_HTTPS_HSTSMAXAGESECONDS
264-
unset SERVICECONTROL_HTTPS_HSTSINCLUDESUBDOMAINS
265-
unset SERVICECONTROL_FORWARDEDHEADERS_ENABLED
266-
```
267-
268239
## See Also
269240

270241
- [Hosting Guide](hosting-guide.md) - Detailed configuration reference for all deployment scenarios

0 commit comments

Comments
 (0)