Adding a boot image sync URL with an unqualified hostname fails

Bug #1439473 reported by Mike Pontillo
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
MAAS
Won't Fix
Medium
Unassigned
python-django (Ubuntu)
Triaged
Low
Unassigned

Bug Description

I saw the following exception when trying to set my boot image sync URL to a URL in the format:

http://host/maas/images/ephemeral-v2/releases/

Where 'host' was a valid hostname which would be resolved using the DNS search path (or hosts file).

When attempting to press "Save" on the settings screen, an internal server error was displayed, giving me no indication about what the problem was. The following exception was seen in the logs:

2015-04-01 18:35:58 [HTTPChannel,3,127.0.0.1] 500 Error - /MAAS/settings/

Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/django/core/handlers/wsgi.py", line 206, in __call__
    response = self.get_response(request)
  File "/usr/lib/python2.7/dist-packages/maasserver/utils/views.py", line 166, in get_response
    response = get_response(request)
  File "/usr/lib/python2.7/dist-packages/maasserver/utils/views.py", line 140, in get_response
    return django_get_response(request)
  File "/usr/lib/python2.7/dist-packages/django/core/handlers/base.py", line 194, in get_response
    response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
--- <exception caught here> ---
  File "/usr/lib/python2.7/dist-packages/django/core/handlers/base.py", line 112, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/usr/lib/python2.7/dist-packages/django/contrib/auth/decorators.py", line 22, in _wrapped_view
    return view_func(request, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/maasserver/views/settings.py", line 205, in settings
    'boot_source', "Configuration updated.")
  File "/usr/lib/python2.7/dist-packages/maasserver/views/__init__.py", line 219, in process_form
    form.save()
  File "/usr/lib/python2.7/dist-packages/maasserver/forms.py", line 1408, in save
    boot_source.save()
  File "/usr/lib/python2.7/dist-packages/maasserver/models/cleansave.py", line 37, in save
    self.full_clean()
  File "/usr/lib/python2.7/dist-packages/django/db/models/base.py", line 950, in full_clean
    raise ValidationError(errors)
django.core.exceptions.ValidationError: {'url': [u'Enter a valid URL.']}

Revision history for this message
Mike Pontillo (mpontillo) wrote :

It appears that, this being a Django URLField, the default validator is overly strict:

class URLValidator(RegexValidator):
    regex = re.compile(
        r'^(?:http|ftp)s?://' # http:// or https://
        r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|' # domain...
        r'localhost|' # localhost...
        r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}|' # ...or ipv4
        r'\[?[A-F0-9]*:[A-F0-9:]+\]?)' # ...or ipv6
        r'(?::\d+)?' # optional port
        r'(?:/?|[/?]\S+)$', re.IGNORECASE)
    message = _('Enter a valid URL.')

Changed in maas:
status: New → Triaged
description: updated
Revision history for this message
Andres Rodriguez (andreserl) wrote :

** This is an automated message **

We believe this is no longer an issue on the latest MAAS releases. As such, we are marking this bug report as invalid. If you believe this is still an issue, please re-open the bug report and provide any relevant information.

Thanks.

Changed in maas:
status: Triaged → Invalid
Revision history for this message
Mike Pontillo (mpontillo) wrote :

I just re-tested this on 2.5; it's still a problem.

Rather than Invalid, we can consider this a Won't Fix. I don't think it's a priority.

Changed in maas:
status: Invalid → Triaged
status: Triaged → Won't Fix
Revision history for this message
Mike Pontillo (mpontillo) wrote :

Adding python-django since this is actually a bug in Django, not in MAAS.

Revision history for this message
Andreas Hasenack (ahasenack) wrote :

Confirmed still a problem in cosmic:
ubuntu@cosmic-django:~$ python3
Python 3.6.6+ (default, Sep 1 2018, 01:05:25)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from django.core.validators import URLValidator
>>> validator = URLValidator()
>>> validator("http://foo/bar")
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/django/core/validators.py", line 124, in __call__
    super(URLValidator, self).__call__(value)
  File "/usr/lib/python3/dist-packages/django/core/validators.py", line 62, in __call__
    raise ValidationError(self.message, code=self.code)
django.core.exceptions.ValidationError: <exception str() failed>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/django/core/validators.py", line 137, in __call__
    super(URLValidator, self).__call__(url)
  File "/usr/lib/python3/dist-packages/django/core/validators.py", line 62, in __call__
    raise ValidationError(self.message, code=self.code)
django.core.exceptions.ValidationError: <exception str() failed>
>>> validator("http://foo.com/bar")
>>>

python3-django 1:1.11.15-1ubuntu1

Upstream is at 2.1, but we are following debian and 2.1 is only in debian experimental.

Changed in python-django (Ubuntu):
status: New → Triaged
importance: Undecided → Low
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.