I have a django application running in Google cloud run (in a Kube cluster), via Docker served by uwsgi (but I've tried manage.py runserver and it's the same). By default cloud run accepts connections on both http and https.
I would like to redirect the user to the https version but cloud run does not seen to be setting the headers correctly.
I have a handler that returns the headers via: json.dumps(request.headers.__dict__['_store'])
And the relevant headers returned are:
"x-forwarded-proto": ["X-Forwarded-Proto", "http"]
But the value http never changes even when I visit the https version of the site.
How should django correctly detect http requests on cloud run? I am unable to use
SECURE_PROXY_SSL_HEADER
to detect and redirect http requests to https as they all appear to be http requests, so you end up in a redirect loop.
However if I follow the links in this post: https://www.jhanley.com/google-cloud-run-https-part-2/
to their "show me the headers" link the value does indeed change from http to https. Is it a django thing? Or a "cloud run on kube" thing?
Hosting the app in question on pure cloud run and visiting the http version does an internal redirect to the HTTPS version and gives the reason: Non-Authoritative-Reason: HSTS
Which is exactly what I'm trying to achieve. It seems the headers I am getting are from the internal routing, not the original request itself when running in Anthos mode.