Skip to content

Conversation

@edmorley
Copy link
Member

@edmorley edmorley commented Jan 21, 2025

Using Django's SECURE_SSL_REDIRECT:
https://docs.djangoproject.com/en/5.1/ref/settings/#std-setting-SECURE_SSL_REDIRECT

Also configures gunicorn's forwarded_allow_ips setting to "*" so that gunicorn trusts the X-Forwarded-Proto header set by the Heroku Router during TLS termination, to ensure that HTTPS requests are correctly marked as secure in the WSGI metadata passed to the WSGI app (in this case, Django). See:
https://docs.gunicorn.org/en/stable/settings.html#forwarded-allow-ips
https://devcenter.heroku.com/articles/http-routing#heroku-headers

(Whilst the classic Python buildpack already configures this by setting the env var FORWARDED_ALLOW_IPS, the Python CNB doesn't yet do so, and it's clearer to have the config explicitly set in the app source.)

GUS-W-17482732.

Using Django's `SECURE_SSL_REDIRECT`:
https://docs.djangoproject.com/en/5.1/ref/settings/#std-setting-SECURE_SSL_REDIRECT

Also configures gunicorn's `forwarded_allow_ips` setting to `"*"` so that
gunicorn trusts the `X-Forwarded-Proto` header set by the Heroku Router during
TLS termination, to ensure that HTTPS requests are correctly marked as secure in
the WSGI metadata passed to the WSGI app (in this case, Django). See:
https://docs.gunicorn.org/en/stable/settings.html#forwarded-allow-ips
https://devcenter.heroku.com/articles/http-routing#heroku-headers

(Whilst the classic Python buildpack already configures this by setting the env
var `FORWARDED_ALLOW_IPS`, the Python CNB doesn't yet do so, and it's
clearer to have the config explicitly set in the app source.)

GUS-W-17482732.
@edmorley edmorley self-assigned this Jan 21, 2025
@edmorley edmorley requested a review from a team as a code owner January 21, 2025 22:59
@edmorley edmorley removed the request for review from a team January 21, 2025 22:59
@heroku heroku bot temporarily deployed to getting-star-edmorley-e-03q7hl January 21, 2025 22:59 Inactive
@edmorley edmorley merged commit a75e1c5 into main Jan 21, 2025
1 check passed
@edmorley edmorley deleted the edmorley/enable-https-redirection branch January 21, 2025 23:06
edmorley added a commit to heroku/cnb-builder-images that referenced this pull request Mar 21, 2025
Since this env var was added in #385 primarily for the Python
Getting Started Guide, but that guide:
- No longer requires that the env var be set in order to run in
  production mode, as of:
  heroku/python-getting-started#251
- Now redirects to HTTPS if `DYNO` is set (which is not what we
  want for these tests, since there is no TLS cert configured), as of:
  heroku/python-getting-started#253

Also, we're about to add Direwolf tests for CNBs/Fir, which will
test the guides in a true Heroku-like setting, so it makes more
sense for these smoke tests to more accurately test the local
`pack build` workflow instead - rather than a hybrid of both.

Lastly, I've added `-L` to the curl usages (which makes it follow
redirects), so that any issues with redirects are caught in CI.
(Such as the Python Getting Started Guide HTTP 301 redirecting
to an HTTPS URL with no cert, when the `DYNO` env var was
set.)

GUS-W-18093965.
edmorley added a commit to heroku/cnb-builder-images that referenced this pull request Mar 21, 2025
Since this env var was added in #385 primarily for the Python
Getting Started Guide, but that guide:
- No longer requires that the env var be set in order to run in
  production mode, as of:
  heroku/python-getting-started#251
- Now redirects to HTTPS if `DYNO` is set (which is not what we
  want for these tests, since there is no TLS cert configured), as of:
  heroku/python-getting-started#253

Also, we're about to add Direwolf tests for CNBs/Fir, which will
test the guides in a true Heroku-like setting, so it makes more
sense for these smoke tests to more accurately test the local
`pack build` workflow instead - rather than a hybrid of both.

Lastly, I've added `-L` to the curl usages (which makes it follow
redirects), so that any issues with redirects are caught in CI.
(Such as the Python Getting Started Guide HTTP 301 redirecting
to an HTTPS URL with no cert, when the `DYNO` env var was
set.)

GUS-W-18093965.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant