Fix bug which allowed for implicit library namespace access via the V1 registry protocol when the feature flag was off

Now we raise a 400 as expected
This commit is contained in:
Joseph Schorr 2018-05-01 13:26:24 +03:00
parent 178c8e7cb0
commit 77adf9dd77
2 changed files with 20 additions and 5 deletions

View file

@ -14,6 +14,13 @@ TAG_REGEX = re.compile(FULL_TAG_PATTERN)
TAG_ERROR = ('Invalid tag: must match [A-Za-z0-9_.-], NOT start with "." or "-", '
'and can contain 1-128 characters')
class ImplicitLibraryNamespaceNotAllowed(Exception):
""" Exception raised if the implicit library namespace was specified but is
not allowed. """
pass
def escape_tag(tag, default='latest'):
""" Escapes a Docker tag, ensuring it matches the tag regular expression. """
if not tag:
@ -24,13 +31,16 @@ def escape_tag(tag, default='latest'):
return tag[0:127]
def parse_namespace_repository(repository, library_namespace, include_tag=False):
def parse_namespace_repository(repository, library_namespace, include_tag=False,
allow_library=True):
repository = repository.encode('unidecode', 'ignore')
parts = repository.rstrip('/').split('/', 1)
if len(parts) < 2:
namespace = library_namespace
repository = parts[0]
if not allow_library:
raise ImplicitLibraryNamespaceNotAllowed()
else:
(namespace, repository) = parts