From 463dc98a421226972f6640199f3a66b32bf71c29 Mon Sep 17 00:00:00 2001 From: Jimmy Zelinskie Date: Tue, 9 Feb 2016 14:16:39 -0500 Subject: [PATCH] return an error when writing manifest v2 schema2 --- endpoints/v2/errors.py | 5 +++-- endpoints/v2/manifest.py | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/endpoints/v2/errors.py b/endpoints/v2/errors.py index f24905f68..0f33b92e3 100644 --- a/endpoints/v2/errors.py +++ b/endpoints/v2/errors.py @@ -52,10 +52,11 @@ class ManifestBlobUnknown(V2RegistryException): class ManifestInvalid(V2RegistryException): - def __init__(self, detail=None): + def __init__(self, detail=None, http_status_code=400): super(ManifestInvalid, self).__init__('MANIFEST_INVALID', 'manifest invalid', - detail) + detail, + http_status_code) class ManifestUnknown(V2RegistryException): diff --git a/endpoints/v2/manifest.py b/endpoints/v2/manifest.py index 7e8f13a2f..b7d4a7bc7 100644 --- a/endpoints/v2/manifest.py +++ b/endpoints/v2/manifest.py @@ -8,6 +8,7 @@ from flask import make_response, request, url_for from collections import namedtuple, OrderedDict from jwkest.jws import SIGNER_ALGS, keyrep from datetime import datetime +from functools import wraps from app import docker_v2_signing_key, app from auth.registry_jwt_auth import process_registry_jwt_auth @@ -33,6 +34,8 @@ MANIFEST_TAGNAME_ROUTE = BASE_MANIFEST_ROUTE.format(VALID_TAG_PATTERN) # From: https://github.com/docker/distribution/blob/47a064d4195a9b56133891bbb13620c3ac83a827/manifest/schema1/manifest.go#L18 MANIFEST_CONTENT_TYPE = 'application/vnd.docker.distribution.manifest.v1+prettyjws' +MANIFEST2_SCHEMA2_CONTENT_TYPES = ['application/vnd.docker.distribution.manifest.v2+json', + 'application/vnd.docker.distribution.manifest.list.v2+json'] ISO_DATETIME_FORMAT_ZULU = '%Y-%m-%dT%H:%M:%SZ' JWS_ALGORITHM = 'RS256' @@ -279,11 +282,22 @@ def fetch_manifest_by_digest(namespace, repo_name, manifest_ref): return response +def _reject_manifest2_schema2(func): + @wraps(func) + def wrapped(*args, **kwargs): + if request.content_type in MANIFEST2_SCHEMA2_CONTENT_TYPES: + raise ManifestInvalid(detail={'message': 'manifest schema version not supported'}, + http_status_code=415) + return func(*args, **kwargs) + return wrapped + + @v2_bp.route(MANIFEST_TAGNAME_ROUTE, methods=['PUT']) @process_registry_jwt_auth @parse_repository_name @require_repo_write @anon_protect +@_reject_manifest2_schema2 def write_manifest_by_tagname(namespace, repo_name, manifest_ref): try: manifest = SignedManifest(request.data) @@ -301,6 +315,7 @@ def write_manifest_by_tagname(namespace, repo_name, manifest_ref): @parse_repository_name @require_repo_write @anon_protect +@_reject_manifest2_schema2 def write_manifest_by_digest(namespace, repo_name, manifest_ref): try: manifest = SignedManifest(request.data)