Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address dynDNS mass registration problem #870

Merged
merged 11 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions api/api/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,7 @@
VALIDITY_PERIOD_VERIFICATION_SIGNATURE = timedelta(
hours=int(os.environ.get("DESECSTACK_API_AUTHACTION_VALIDITY", "0"))
)
REGISTER_LPS_ON_SIGNUP = bool(
int(os.environ.get("DESECSTACK_API_REGISTER_LPS_ON_SIGNUP", "1"))
)
REGISTER_LPS = bool(int(os.environ.get("DESECSTACK_API_REGISTER_LPS", "1")))

# CAPTCHA
CAPTCHA_VALIDITY_PERIOD = timedelta(hours=24)
Expand Down
18 changes: 14 additions & 4 deletions api/desecapi/serializers/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,24 @@ def validate_domain(self, value):
serializer.default_error_messages["name_unavailable"],
code="name_unavailable",
)
return value

def validate(self, attrs):
if (
not settings.REGISTER_LPS_ON_SIGNUP
and DomainSerializer.Meta.model(name=value).is_locally_registrable
not settings.REGISTER_LPS
and attrs.get("captcha") is not None
and attrs.get("domain") is not None
and DomainSerializer.Meta.model(name=attrs["domain"]).is_locally_registrable
):
raise serializers.ValidationError(
"Registration during sign-up disabled; please create account without a domain name.",
{
"domain": [
DomainSerializer.default_error_messages["name_unavailable"]
]
},
code="name_unavailable",
)
return value
return super().validate(attrs)

def create(self, validated_data):
validated_data.pop("domain", None)
Expand Down
8 changes: 8 additions & 0 deletions api/desecapi/tests/test_domains.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.conf import settings
from django.core import mail
from django.core.exceptions import ValidationError
from django.test import override_settings
from rest_framework import status

from desecapi.models import Domain
Expand Down Expand Up @@ -714,6 +715,13 @@ def test_create_public_suffixes(self):
self.assertStatus(response, status.HTTP_400_BAD_REQUEST)
self.assertEqual(response.data["name"][0].code, "name_unavailable")

@override_settings(REGISTER_LPS=False)
def test_create_local_public_suffixes_lps_disabled(self):
domain = "foo." + next(iter(self.AUTO_DELEGATION_DOMAINS))
response = self.client.post(self.reverse("v1:domain-list"), {"name": domain})
self.assertStatus(response, status.HTTP_400_BAD_REQUEST)
self.assertEqual(response.data["name"][0].code, "name_unavailable")

def test_create_domain_under_public_suffix_with_private_parent(self):
name = "amazonaws.com"
with self.assertRequests(
Expand Down
28 changes: 28 additions & 0 deletions api/desecapi/tests/test_user_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from django.conf import settings
from django.core import mail
from django.core.management import call_command
from django.test import override_settings
from django.urls import resolve
from django.utils import timezone
from rest_framework import status
Expand Down Expand Up @@ -610,6 +611,19 @@ def test_registration_with_domain(self):
domain=self.random_domain_name(suffix=local_public_suffix)
)

@override_settings(REGISTER_LPS=False)
def test_registration_with_domain_lps_disabled(self):
PublicSuffixMockMixin.setUpMockPatch(self)
with self.get_psl_context_manager("."):
_, _, domain = self._test_registration_with_domain()

local_public_suffix = random.sample(list(self.AUTO_DELEGATION_DOMAINS), 1)[0]
with self.get_psl_context_manager(local_public_suffix):
self._test_registration_with_domain(
domain=self.random_domain_name(suffix=local_public_suffix),
expect_failure_response=self.assertRegistrationFailureDomainUnavailableResponse,
)

def test_registration_without_domain_and_password(self):
email, password = self._test_registration(self.random_username(), None)
confirmation_link = self.assertResetPasswordEmail(email)
Expand Down Expand Up @@ -693,6 +707,20 @@ def test_registration_wrong_captcha(self):
def test_registration_late_captcha(self):
self._test_registration(password=self.random_password(), late_captcha=True)

PublicSuffixMockMixin.setUpMockPatch(self)
local_public_suffix = random.sample(list(self.AUTO_DELEGATION_DOMAINS), 1)[0]
# Late captcha sign-up allows domain registration (Nextcloud VM workflow)
for register_lps in [True, False]:
domain = self.random_domain_name(suffix=local_public_suffix)
with (
override_settings(REGISTER_LPS=register_lps),
self.get_psl_context_manager(local_public_suffix),
self.assertRequests(
self.requests_desec_domain_creation_auto_delegation(domain)
),
):
self._test_registration(domain=domain, late_captcha=True)


class OtherUserAccountTestCase(UserManagementTestCase):
def setUp(self):
Expand Down
11 changes: 10 additions & 1 deletion api/desecapi/views/domains.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from rest_framework.decorators import action
from rest_framework.permissions import IsAuthenticated, SAFE_METHODS
from rest_framework.response import Response
from rest_framework.serializers import ValidationError
from rest_framework.settings import api_settings
from rest_framework.views import APIView

Expand Down Expand Up @@ -83,6 +84,14 @@ def get_serializer(self, *args, **kwargs):
return super().get_serializer(*args, include_keys=include_keys, **kwargs)

def perform_create(self, serializer):
if (
not settings.REGISTER_LPS
and Domain(name=serializer.validated_data["name"]).is_locally_registrable
):
raise ValidationError(
{"name": [DomainSerializer.default_error_messages["name_unavailable"]]},
code="name_unavailable",
)
with PDNSChangeTracker():
domain = serializer.save(owner=self.request.user)

Expand Down Expand Up @@ -121,5 +130,5 @@ def get(self, request, *args, **kwargs):
serials = cache.get(key)
if serials is None:
serials = get_serials()
cache.get_or_set(key, serials, timeout=15)
cache.get_or_set(key, serials, timeout=60)
return Response(serials)
6 changes: 3 additions & 3 deletions api/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
captcha~=0.5.0
celery~=5.3.6
coverage~=7.4.0
cryptography~=41.0.7
coverage~=7.4.1
cryptography~=42.0.1
Django~=5.0.1
django-cors-headers~=4.3.1
djangorestframework~=3.14.0
django-celery-email~=3.0.0
django-netfields~=1.3.2
django-pgtrigger~=4.11.0
django-prometheus~=2.3.1
dnspython~=2.4.2
dnspython~=2.5.0
httpretty~=1.0.5 # 1.1 breaks tests. Does not run in production, so stick to it.
pyotp~=2.9.0
psycopg~=3.1.17
Expand Down
3 changes: 3 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ services:
- DESECSTACK_API_PCH_API
- DESECSTACK_API_PCH_API_TOKEN
- DESECSTACK_API_AUTHACTION_VALIDITY
- DESECSTACK_API_REGISTER_LPS
- DESECSTACK_API_LIMIT_USER_DOMAIN_COUNT_DEFAULT
- DESECSTACK_DBAPI_PASSWORD_desec
- DESECSTACK_IPV4_REAR_PREFIX16
- DESECSTACK_IPV6_SUBNET
Expand Down Expand Up @@ -284,6 +286,7 @@ services:
user: memcache:memcache
networks:
- rearapi_celery
command: ["memcached", "-I", "2m"]
logging:
driver: "syslog"
options:
Expand Down
2 changes: 1 addition & 1 deletion test/e2e2/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ pytest
pytest-schema
pytest-xdist
requests
dnspython~=2.4.2
dnspython~=2.5.0
2 changes: 1 addition & 1 deletion www/webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"dependencies": {
"@fontsource/roboto": "^5.0.3",
"@mdi/js": "~7.3.67",
"@mdi/js": "~7.4.47",
"axios": "^1.4.0",
"date-fns": "^3.3.1",
"pinia": "^2.0.30",
Expand Down
2 changes: 1 addition & 1 deletion www/webapp/src/views/HomePage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
@change="$router.push({query: {domainType: domainType}})"
>
<v-radio class="pb-2" label="Managed DNS account" value="custom"></v-radio>
<v-radio class="pb-2" label="dynDNS account" value="dynDNS"></v-radio>
<v-radio class="pb-2" disabled="disabled" label="dynDNS account" value="dynDNS"></v-radio>
</v-radio-group>
</div>
<v-text-field
Expand Down
9 changes: 7 additions & 2 deletions www/webapp/src/views/SignUp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,13 @@
persistent-hint
:prepend-icon="mdiDns"
>
<v-radio label="Configure your own domain (Managed DNS or dynDNS)." value="custom" tabindex="2"></v-radio>
<v-radio :label="`Register a new domain under ${LOCAL_PUBLIC_SUFFIXES[0]} (dynDNS).`" value="dynDNS" tabindex="2"></v-radio>
<v-alert type="info">
dynDNS registrations are suspended at this time.
<strong>We do <i>not</i> process requests for exceptions.</strong><br/>
<small>Please do not contact support about this. You will have to register a domain elsewhere.</small>
</v-alert>
<v-radio label="Configure your own domain (Managed DNS)." value="custom" tabindex="2"></v-radio>
<v-radio :label="`Register a new domain under ${LOCAL_PUBLIC_SUFFIXES[0]} (dynDNS).`" disabled="disabled" value="dynDNS" tabindex="2"></v-radio>
<v-radio label="No, I'll add one later." value="none" tabindex="2"></v-radio>
</v-radio-group>

Expand Down
Loading