diff --git a/Dockerfile b/Dockerfile index 6866121..03693f2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,6 +11,7 @@ ENV PYTHON_EGG_CACHE=/home/syncano/.python-eggs \ GEOS_LIBRARY_PATH=/usr/lib/libgeos_c.so.1 RUN set -ex \ + && pip install --upgrade pip \ && adduser -D -s /bin/bash syncano \ && apk add --no-cache \ bash \ diff --git a/apps/core/mixins/views.py b/apps/core/mixins/views.py index bd0edfd..25df75d 100644 --- a/apps/core/mixins/views.py +++ b/apps/core/mixins/views.py @@ -156,7 +156,7 @@ def initial(self, request, *args, **kwargs): obj = Cached(model, kwargs=lookup_kwargs).get() else: obj = model.objects.get(**lookup_kwargs) - except (ValidationError, ObjectDoesNotExist): + except (ValidationError, ObjectDoesNotExist, ValueError): # If value is not valid for a field or model not found - raise an error raise ModelNotFound(model) else: diff --git a/apps/hosting/middleware.py b/apps/hosting/middleware.py index 419fee7..af15a29 100644 --- a/apps/hosting/middleware.py +++ b/apps/hosting/middleware.py @@ -25,7 +25,7 @@ def __call__(self, request): except Instance.DoesNotExist: raise Http404() else: - instance = host.split(settings.HOSTING_DOMAIN)[0] + instance = host.split('.')[0] # Check if we're dealing with: -- domain_data = instance.rsplit('--', 1) if len(domain_data) == 2: diff --git a/apps/hosting/tasks.py b/apps/hosting/tasks.py index cd39487..d6096f9 100644 --- a/apps/hosting/tasks.py +++ b/apps/hosting/tasks.py @@ -52,23 +52,31 @@ def validate_domain(self, domain): answers = resolver.query(domain, 'CNAME') except DNSException: # If domain has no CNAME and it's a root domain, check if CNAME flattening is used - try: - r = requests.get('http://{}/2a1b7ceb-2b7c-4bd2-a40f-8b021278f5ea/'.format(domain), - timeout=(1.0, 3.0), allow_redirects=False) - if r.status_code == requests.codes.ok and r.content == b'OK': - return - except requests.RequestException: - pass + if domain.count('.') == 1: + try: + r = requests.get('http://{}/2a1b7ceb-2b7c-4bd2-a40f-8b021278f5ea/'.format(domain), + timeout=(1.0, 3.0), allow_redirects=False) + if r.status_code == requests.codes.ok and r.content.decode() == settings.LOCATION: + return + except requests.RequestException: + pass raise CNameNotSet() - # Check expected CNAME value - expected_cname = '{}{}.'.format(self.instance.name, settings.HOSTING_DOMAIN) if len(answers) != 1: raise WrongCName() cname = answers[0].target.to_unicode() - if cname != expected_cname and not re.match(r'^[a-z0-9-]+--%s$' % expected_cname, cname): - raise WrongCName() + self.validate_cname(cname) + + def validate_cname(self, cname): + # Check expected CNAME value + expected_cnames = ['{}.{}{}.'.format(self.instance.name, settings.LOCATION, settings.HOSTING_DOMAIN)] + if settings.MAIN_LOCATION: + expected_cnames.append('{}{}.'.format(self.instance.name, settings.HOSTING_DOMAIN)) + for expected_cname in expected_cnames: + if cname == expected_cname or re.match(r'^[a-z0-9-]+--%s$' % expected_cname, cname): + return + raise WrongCName() def run(self, hosting_pk, domain, **kwargs): hosting_qs = Hosting.objects.filter(pk=hosting_pk) diff --git a/deploy/env/eu1.env b/deploy/env/eu1.env index c353925..27bcc3b 100644 --- a/deploy/env/eu1.env +++ b/deploy/env/eu1.env @@ -11,7 +11,7 @@ DB_INSTANCES_NAME=syncano-instances DJANGO_SETTINGS_MODULE=settings.production GOOGLE_APPLICATION_CREDENTIALS=/secrets/storage/credentials.json GUI_ROOT_URL=https://dashboard.syncano.io -HOSTING_DOMAIN=.eu1.syncano.site +HOSTING_DOMAIN=.syncano.site INVITATION_SITE_URL=https://dashboard.syncano.io LEGACY_CODEBOX_ENABLED=false LOCATION=eu1