Skip to content

Commit 269c9b1

Browse files
committed
Adds docker-compose dev options to force HTTPS settings and DEBUG mode through environment
1 parent a7926d1 commit 269c9b1

File tree

6 files changed

+38
-11
lines changed

6 files changed

+38
-11
lines changed

dockerfiles/settings/proxito.py

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import os
2+
13
from readthedocs.settings.proxito.base import CommunityProxitoSettingsMixin
24

35
from .docker_compose import DockerBaseSettings
@@ -19,5 +21,8 @@ def DEBUG_TOOLBAR_CONFIG(self):
1921
'SHOW_TOOLBAR_CALLBACK': lambda request: False,
2022
}
2123

24+
if os.environ.get("RTD_FORCE_HTTPS"):
25+
PROXITO_DEV_DISABLE_SUSPICIOUS_HOST_CHECK = True
26+
2227

2328
ProxitoDevSettings.load_settings(__name__)

readthedocs/core/unresolver.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -471,11 +471,12 @@ def unresolve_domain(self, domain):
471471
log.info("Invalid format of external versions domain.", domain=domain)
472472
raise InvalidExternalDomainError(domain=domain)
473473

474-
if public_domain in domain or external_domain in domain:
475-
# NOTE: This can catch some possibly valid domains (docs.readthedocs.io.com)
476-
# for example, but these might be phishing, so let's block them for now.
477-
log.warning("Weird variation of our domain.", domain=domain)
478-
raise SuspiciousHostnameError(domain=domain)
474+
if not getattr(settings, "PROXITO_DEV_DISABLE_SUSPICIOUS_HOST_CHECK", False):
475+
if public_domain in domain or external_domain in domain:
476+
# NOTE: This can catch some possibly valid domains (docs.readthedocs.io.com)
477+
# for example, but these might be phishing, so let's block them for now.
478+
log.warning("Weird variation of our domain.", domain=domain)
479+
raise SuspiciousHostnameError(domain=domain)
479480

480481
# Custom domain.
481482
domain_object = (

readthedocs/settings/base.py

+2
Original file line numberDiff line numberDiff line change
@@ -1051,6 +1051,8 @@ def DOCKER_LIMITS(self):
10511051
RTD_SPAM_THRESHOLD_DELETE_PROJECT = 1000
10521052
RTD_SPAM_MAX_SCORE = 9999
10531053

1054+
PROXITO_DEV_DISABLE_SUSPICIOUS_HOST_CHECK = False
1055+
10541056
CACHEOPS_ENABLED = False
10551057
CACHEOPS_TIMEOUT = 60 * 60 # seconds
10561058
CACHEOPS_OPS = {'get', 'fetch'}

readthedocs/settings/docker_compose.py

+10
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ class DockerBaseSettings(CommunityBaseSettings):
88

99
"""Settings for local development with Docker"""
1010

11+
DEBUG = bool(os.environ.get('RTD_DJANGO_DEBUG', True))
12+
1113
DOCKER_ENABLE = True
1214
RTD_DOCKER_COMPOSE = True
1315
RTD_DOCKER_COMPOSE_VOLUME = 'community_build-user-builds'
@@ -30,6 +32,10 @@ class DockerBaseSettings(CommunityBaseSettings):
3032
# In the local docker environment, nginx should be trusted to set the host correctly
3133
USE_X_FORWARDED_HOST = True
3234

35+
# Assume running on forwarded https
36+
if os.environ.get("RTD_FORCE_HTTPS"):
37+
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
38+
3339
MULTIPLE_BUILD_SERVERS = ['build']
3440

3541
# https://docs.docker.com/engine/reference/commandline/run/#add-entries-to-container-hosts-file---add-host
@@ -149,6 +155,8 @@ def DATABASES(self): # noqa
149155
}
150156

151157
ACCOUNT_EMAIL_VERIFICATION = "none"
158+
if os.environ.get("RTD_FORCE_HTTPS"):
159+
ACCOUNT_DEFAULT_HTTP_PROTOCOL = "https"
152160
SESSION_COOKIE_DOMAIN = None
153161
CACHES = {
154162
'default': {
@@ -192,6 +200,8 @@ def DATABASES(self): # noqa
192200
AWS_S3_USE_SSL = False
193201
AWS_S3_ENDPOINT_URL = 'http://storage:9000/'
194202
AWS_QUERYSTRING_AUTH = False
203+
if os.environ.get("RTD_FORCE_HTTPS"):
204+
S3_STATIC_STORAGE_OVERRIDE_PROTOCOL = "https"
195205

196206
RTD_SAVE_BUILD_COMMANDS_TO_STORAGE = True
197207
RTD_BUILD_COMMANDS_STORAGE = 'readthedocs.storage.s3_storage.S3BuildCommandsStorage'

readthedocs/storage/mixins.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,29 @@
66
class OverrideHostnameMixin:
77

88
"""
9-
Override the hostname when outputting URLs.
9+
Override the hostname or protocol when outputting URLs.
1010
1111
This is useful for use with a CDN or when proxying outside of Blob Storage
1212
1313
See: https://github.com/jschneier/django-storages/pull/658
1414
"""
1515

16-
override_hostname = None # Just the hostname without scheme (eg. 'assets.readthedocs.org')
16+
override_hostname = (
17+
None # use the hostname without scheme (eg. 'assets.readthedocs.org')
18+
)
19+
override_protocol = (
20+
None # set to "http" or "https". None = inherit automatic setting.
21+
)
1722

1823
def url(self, *args, **kwargs):
1924
url = super().url(*args, **kwargs)
2025

21-
if self.override_hostname:
26+
if self.override_hostname or self.override_protocol:
2227
parts = list(urlsplit(url))
23-
parts[1] = self.override_hostname
28+
if self.override_protocol:
29+
parts[0] = self.override_protocol
30+
if self.override_hostname:
31+
parts[1] = self.override_hostname
2432
url = urlunsplit(parts)
2533

2634
return url

readthedocs/storage/s3_storage.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,9 @@ def __init__(self, *args, **kwargs):
7777

7878
class S3StaticStorageMixin:
7979

80-
bucket_name = getattr(settings, 'S3_STATIC_STORAGE_BUCKET', None)
81-
override_hostname = getattr(settings, 'S3_STATIC_STORAGE_OVERRIDE_HOSTNAME', None)
80+
bucket_name = getattr(settings, "S3_STATIC_STORAGE_BUCKET", None)
81+
override_hostname = getattr(settings, "S3_STATIC_STORAGE_OVERRIDE_HOSTNAME", None)
82+
override_protocol = getattr(settings, "S3_STATIC_STORAGE_OVERRIDE_PROTOCOL", None)
8283

8384
def __init__(self, *args, **kwargs):
8485
super().__init__(*args, **kwargs)

0 commit comments

Comments
 (0)