uWSGI and Upstream HTTPS: Certificate Validation and DNS Resolution
0 reputation · 11 Mar 2024, 18:59 UTC
0 reputation · 11 Mar 2024, 18:59 UTC
When utilizing the --https-to router option in uWSGI to proxy requests to upstream HTTPS servers, the application must manage both TLS handshake security and hostname resolution. By default, uWSGI does not validate upstream certificates, requiring the explicit use of --https-to-verify and --https-to-ca to ensure authenticity against a trusted CA store.
A significant constraint exists regarding how uWSGI handles the resolution of these upstream hostnames. In environments where upstream IP addresses change frequently—such as those using cloud load balancers or dynamic service discovery—the initial DNS resolution performed at startup may become stale, as uWSGI does not natively re-resolve hostnames based on TTL expiry.
Given these behaviors in current versions of uWSGI:
--https-to-verify flag impact the performance overhead of the proxying process significantly?34775 reputation · 12 Mar 2024, 06:38 UTC
1. Performance impact of --https-to-verify
verify call costs <1 ms, which is negligible compared to the baseline TLS handshake (~5–10 ms) and application logic.2. Native DNS re‑resolution for upstream hosts
--https-to hostname once at process start and caches the IP.SIGHUP to trigger a reload (which re‑reads the config and re‑resolves).--https-to value and then send SIGHUP.uWSGI prioritises deterministic routing and avoids the cost of repeated DNS lookups for every request. The router is designed to be lightweight and predictable, so it deliberately caches the resolution until a process reload.
Measure overhead:
# run with and without --https-to-verify
$ ab -n 1000 -c 50 http://localhost:8080/ > output.txt
# compare average latency
Confirm DNS caching:
# change upstream DNS record
$ nslookup upstream.example.com
# check uWSGI log for IP
$ grep upstream /var/log/uwsgi/uwsgi.log
# change DNS again and restart uWSGI to see new IP
Check TLS session reuse:
# capture traffic
$ tcpdump -i eth0 host upstream.example.com -w capture.pcap
# analyze with Wireshark; look for repeated ClientHello with same Session ID
To refine the recommendation, please let us know whether TLS session reuse is currently enabled in your uWSGI build. If it is disabled, the --https-to-verify flag may introduce a measurable latency penalty that could influence your deployment strategy.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.