You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by as...@apache.org on 2020/02/25 19:12:29 UTC

[mesos] branch 1.9.x updated (f37ae68 -> 94749a9)

This is an automated email from the ASF dual-hosted git repository.

asekretenko pushed a change to branch 1.9.x
in repository https://gitbox.apache.org/repos/asf/mesos.git.


    from f37ae68  Changed termination logic of the default executor.
     new d30c749  Factored out common code for building URIs on a registry host.
     new 2dd47f5  Factored out getting authorization service URI.
     new cee9957  Added workaround for Docker repositories not providing scope/service.
     new 94749a9  Added test for fetch from repositories not providing scope/service.

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/tests/uri_fetcher_tests.cpp |  55 ++++++++
 src/uri/fetchers/docker.cpp     | 301 ++++++++++++++++++++++++++--------------
 src/uri/fetchers/docker.hpp     |   9 +-
 3 files changed, 257 insertions(+), 108 deletions(-)


[mesos] 02/04: Factored out getting authorization service URI.

Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

asekretenko pushed a commit to branch 1.9.x
in repository https://gitbox.apache.org/repos/asf/mesos.git

commit 2dd47f5694b620dc141ffdf4b64c2af7a92d3d58
Author: Andrei Sekretenko <as...@mesosphere.com>
AuthorDate: Thu Jan 30 13:02:45 2020 +0100

    Factored out getting authorization service URI.
    
    Review: https://reviews.apache.org/r/72078
---
 src/uri/fetchers/docker.cpp | 173 ++++++++++++++++++++++++--------------------
 1 file changed, 93 insertions(+), 80 deletions(-)

diff --git a/src/uri/fetchers/docker.cpp b/src/uri/fetchers/docker.cpp
index 0424ce1..42b8b39 100644
--- a/src/uri/fetchers/docker.cpp
+++ b/src/uri/fetchers/docker.cpp
@@ -467,6 +467,59 @@ static URI getBlobUri(const URI& imageUri)
 }
 
 
+// Obtains URI of the V2 authorization service based on the
+// initial "401 unauthorized" response of the Docker V2 registry.
+static Future<string> getAuthServiceUri(const http::Response& initialResponse)
+{
+  Result<http::header::WWWAuthenticate> header =
+    initialResponse.headers.get<http::header::WWWAuthenticate>();
+
+  if (header.isError()) {
+    return Failure("Failed to get WWW-Authenticate header: " + header.error());
+  } else if (header.isNone()) {
+    return Failure("Unexpected empty WWW-Authenticate header");
+  }
+
+  // According to RFC, auth scheme should be case insensitive.
+  const string authScheme = strings::upper(header->authScheme());
+
+  if (authScheme == "BASIC") {
+    return Failure(
+        "Unexpected BASIC Authorization response status: " +
+        initialResponse.status);
+  }
+
+  if (authScheme != "BEARER") {
+    return Failure("Unsupported auth-scheme: " + authScheme);
+  }
+
+  hashmap<string, string> authParam = header->authParam();
+
+  // `authParam` is supposed to contain the 'realm', 'service'
+  // and 'scope' information for bearer authentication.
+  //
+  // TODO(asekretenko): Fall back to querying repository root and
+  // constructing scope if one of these is missing (see MESOS-10092).
+  if (!authParam.contains("realm")) {
+    return Failure("Missing 'realm' in WWW-Authenticate header");
+  }
+
+  if (!authParam.contains("service")) {
+    return Failure("Missing 'service' in WWW-Authenticate header");
+  }
+
+  if (!authParam.contains("scope")) {
+    return Failure("Missing 'scope' in WWW-Authenticate header");
+  }
+
+  // TODO(jieyu): Currently, we don't expect the auth server to return
+  // a service or a scope that needs encoding.
+  return authParam.at("realm") + "?" +
+    "service=" + authParam.at("service") + "&" +
+    "scope=" + authParam.at("scope");
+}
+
+
 //-------------------------------------------------------------------
 // DockerFetcherPlugin implementation.
 //-------------------------------------------------------------------
@@ -1069,91 +1122,51 @@ Future<Nothing> DockerFetcherPluginProcess::_urlFetchBlob(
 #endif
 
 
+// If a '401 Unauthorized' response is received and the auth-scheme
+// is 'Bearer', we expect a header 'Www-Authenticate' containing the
+// auth server information. We extract the auth server information
+// from the auth-param, and then contacts the auth server to get the
+// token. The token will then be placed in the subsequent HTTP
+// requests as a header.
+//
+// See details here:
+// https://docs.docker.com/registry/spec/auth/token/
 Future<http::Headers> DockerFetcherPluginProcess::getAuthHeader(
     const URI& uri,
     const http::Headers& basicAuthHeaders,
     const http::Response& response)
 {
-  Result<http::header::WWWAuthenticate> header =
-    response.headers.get<http::header::WWWAuthenticate>();
-
-  if (header.isError()) {
-    return Failure(
-        "Failed to get WWW-Authenticate header: " + header.error());
-  } else if (header.isNone()) {
-    return Failure("Unexpected empty WWW-Authenticate header");
-  }
-
-  // According to RFC, auth scheme should be case insensitive.
-  const string authScheme = strings::upper(header->authScheme());
-
-  // If a '401 Unauthorized' response is received and the auth-scheme
-  // is 'Bearer', we expect a header 'Www-Authenticate' containing the
-  // auth server information. We extract the auth server information
-  // from the auth-param, and then contacts the auth server to get the
-  // token. The token will then be placed in the subsequent HTTP
-  // requests as a header.
-  //
-  // See details here:
-  // https://docs.docker.com/registry/spec/auth/token/
-  if (authScheme == "BEARER") {
-    hashmap<string, string> authParam = header->authParam();
-
-    // `authParam` is supposed to contain the 'realm', 'service'
-    // and 'scope' information for bearer authentication.
-    if (!authParam.contains("realm")) {
-      return Failure("Missing 'realm' in WWW-Authenticate header");
-    }
-
-    if (!authParam.contains("service")) {
-      return Failure("Missing 'service' in WWW-Authenticate header");
-    }
-
-    if (!authParam.contains("scope")) {
-      return Failure("Missing 'scope' in WWW-Authenticate header");
-    }
-
-    // TODO(jieyu): Currently, we don't expect the auth server to return
-    // a service or a scope that needs encoding.
-    string authServerUri =
-      authParam.at("realm") + "?" +
-      "service=" + authParam.at("service") + "&" +
-      "scope=" + authParam.at("scope");
-
-    return curl(authServerUri, basicAuthHeaders, stallTimeout)
-      .then([authServerUri](
-          const http::Response& response) -> Future<http::Headers> {
-        if (response.code != http::Status::OK) {
-          return Failure(
-            "Unexpected HTTP response '" + response.status + "' "
-            "when trying to GET '" + authServerUri + "'");
-        }
-
-        CHECK_EQ(response.type, http::Response::BODY);
-
-        Try<JSON::Object> object = JSON::parse<JSON::Object>(response.body);
-        if (object.isError()) {
-          return Failure("Parsing the JSON object failed: " + object.error());
-        }
-
-        Result<JSON::String> token = object->find<JSON::String>("token");
-        if (token.isError()) {
-          return Failure(
-              "Finding token in JSON object failed: " + token.error());
-        } else if (token.isNone()) {
-          return Failure("Failed to find token in JSON object");
-        }
-
-        return getAuthHeaderBearer(token->value);
-      });
-  }
-
-  if (authScheme == "BASIC"){
-    return Failure(
-        "Unexpected BASIC Authorization response status: " + response.status);
-  }
-
-  return Failure("Unsupported auth-scheme: " + authScheme);
+  const auto stallTimeout = this->stallTimeout;
+
+  return getAuthServiceUri(response)
+    .then([basicAuthHeaders, stallTimeout](const string& authServiceUri) {
+      return curl(authServiceUri, basicAuthHeaders, stallTimeout)
+        .then([authServiceUri](const http::Response& response)
+        -> Future<http::Headers> {
+          if (response.code != http::Status::OK) {
+            return Failure(
+                "Unexpected HTTP response '" + response.status + "' "
+                "when trying to GET '" + authServiceUri + "'");
+          }
+
+          CHECK_EQ(response.type, http::Response::BODY);
+
+          Try<JSON::Object> object = JSON::parse<JSON::Object>(response.body);
+          if (object.isError()) {
+            return Failure("Parsing the JSON object failed: " + object.error());
+          }
+
+          Result<JSON::String> token = object->find<JSON::String>("token");
+          if (token.isError()) {
+            return Failure(
+                "Finding token in JSON object failed: " + token.error());
+          } else if (token.isNone()) {
+            return Failure("Failed to find token in JSON object");
+          }
+
+          return getAuthHeaderBearer(token->value);
+        });
+    });
 }
 
 


[mesos] 01/04: Factored out common code for building URIs on a registry host.

Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

asekretenko pushed a commit to branch 1.9.x
in repository https://gitbox.apache.org/repos/asf/mesos.git

commit d30c74964e3e2d024a7b71bf3431d9cb6499ad75
Author: Andrei Sekretenko <as...@mesosphere.com>
AuthorDate: Thu Jan 30 12:39:31 2020 +0100

    Factored out common code for building URIs on a registry host.
    
    This is a prerequisite for adding fallback authorization server URI
    generation (see MESOS-10092) in the next patches, which will need one
    more URI extractor similar to `getManifestUri()`/`getBlobUri()`.
    
    Review: https://reviews.apache.org/r/72077
---
 src/uri/fetchers/docker.cpp | 61 +++++++++++++++++++++------------------------
 1 file changed, 29 insertions(+), 32 deletions(-)

diff --git a/src/uri/fetchers/docker.cpp b/src/uri/fetchers/docker.cpp
index 1aa3def..0424ce1 100644
--- a/src/uri/fetchers/docker.cpp
+++ b/src/uri/fetchers/docker.cpp
@@ -438,6 +438,35 @@ static http::Headers getAuthHeaderBearer(
   return headers;
 }
 
+
+static URI constructRegistryUri(const URI& imageUri, string&& path)
+{
+  const string scheme = imageUri.has_fragment() ? imageUri.fragment() : "https";
+  return uri::construct(
+      scheme,
+      std::move(path),
+      imageUri.host(),
+      (imageUri.has_port() ? Option<int>(imageUri.port()) : None()));
+}
+
+
+static URI getManifestUri(const URI& imageUri)
+{
+  return constructRegistryUri(
+      imageUri,
+      strings::join(
+          "/", "/v2", imageUri.path(), "manifests", imageUri.query()));
+}
+
+
+static URI getBlobUri(const URI& imageUri)
+{
+  return constructRegistryUri(
+      imageUri,
+      strings::join("/", "/v2", imageUri.path(), "blobs", imageUri.query()));
+}
+
+
 //-------------------------------------------------------------------
 // DockerFetcherPlugin implementation.
 //-------------------------------------------------------------------
@@ -510,9 +539,6 @@ private:
       const http::Headers& basicAuthHeaders,
       const http::Response& response);
 
-  URI getManifestUri(const URI& uri);
-  URI getBlobUri(const URI& uri);
-
   // This is a lookup table for credentials in docker config file,
   // keyed by registry URL.
   // For example, "https://index.docker.io/v1/" -> spec::Config::Auth
@@ -1131,34 +1157,5 @@ Future<http::Headers> DockerFetcherPluginProcess::getAuthHeader(
 }
 
 
-URI DockerFetcherPluginProcess::getManifestUri(const URI& uri)
-{
-  string scheme = "https";
-  if (uri.has_fragment()) {
-    scheme = uri.fragment();
-  }
-
-  return uri::construct(
-      scheme,
-      strings::join("/", "/v2", uri.path(), "manifests", uri.query()),
-      uri.host(),
-      (uri.has_port() ? Option<int>(uri.port()) : None()));
-}
-
-
-URI DockerFetcherPluginProcess::getBlobUri(const URI& uri)
-{
-  string scheme = "https";
-  if (uri.has_fragment()) {
-    scheme = uri.fragment();
-  }
-
-  return uri::construct(
-      scheme,
-      strings::join("/", "/v2", uri.path(), "blobs", uri.query()),
-      uri.host(),
-      (uri.has_port() ? Option<int>(uri.port()) : None()));
-}
-
 } // namespace uri {
 } // namespace mesos {


[mesos] 04/04: Added test for fetch from repositories not providing scope/service.

Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

asekretenko pushed a commit to branch 1.9.x
in repository https://gitbox.apache.org/repos/asf/mesos.git

commit 94749a9f56a22d49c6bcf12142ad6eec3546363b
Author: Andrei Sekretenko <as...@mesosphere.com>
AuthorDate: Thu Jan 23 12:42:33 2020 +0100

    Added test for fetch from repositories not providing scope/service.
    
    Review: https://reviews.apache.org/r/72080
---
 src/tests/uri_fetcher_tests.cpp | 55 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 55 insertions(+)

diff --git a/src/tests/uri_fetcher_tests.cpp b/src/tests/uri_fetcher_tests.cpp
index 92f8062..0b4d96c 100644
--- a/src/tests/uri_fetcher_tests.cpp
+++ b/src/tests/uri_fetcher_tests.cpp
@@ -394,6 +394,61 @@ TEST_F(DockerFetcherPluginTest, DISABLED_INTERNET_CURL_FetchImage)
 }
 
 
+// Fetches an image from a registry for which fetcher falls back to generating
+// repository scope (see MESOS-10092). This test uses 'nvcr.io' as a registry
+// that does not provide scope on its own.
+//
+// TODO(asekretenko): Set up a mock registry and use it in this test.
+TEST_F(DockerFetcherPluginTest, INTERNET_CURL_GeneratedRepositoryScope)
+{
+  // Using `nvidia/k8s/cuda-sample:nbody` as it seems to be the smallest one
+  // on nvcr.io
+  const URI uri =
+    uri::docker::image("nvidia/k8s/cuda-sample", "nbody", "nvcr.io");
+
+  const string dir = path::join(os::getcwd(), "dir");
+
+  // First, we create a docker fetcher plugin with fallback disabled
+  // to make sure that nvcr.io is still suitable for the purpose of this test.
+  Try<process::Owned<uri::Fetcher::Plugin>> fetcherWithDisabledFallback =
+    DockerFetcherPlugin::create(DockerFetcherPlugin::Flags(), false);
+
+  ASSERT_SOME(fetcherWithDisabledFallback);
+  Future<Nothing> NoFallbackFetch =
+    fetcherWithDisabledFallback.get()->fetch(uri, dir);
+
+  AWAIT_FAILED_FOR(NoFallbackFetch, Seconds(120));
+
+  ASSERT_TRUE(strings::contains(
+      NoFallbackFetch.failure(),
+      "Missing 'realm', 'service' or 'scope' in header WWW-Authenticate"));
+
+  // Now, we can proceed with testing the fallback.
+  Try<Owned<uri::Fetcher>> fetcher = uri::fetcher::create();
+  ASSERT_SOME(fetcher);
+
+  AWAIT_READY_FOR(fetcher.get()->fetch(uri, dir), Seconds(120));
+
+  Try<string> _manifest = os::read(path::join(dir, "manifest"));
+  ASSERT_SOME(_manifest);
+
+  Try<docker::spec::v2_2::ImageManifest> manifest =
+    docker::spec::v2_2::parse(_manifest.get());
+
+  ASSERT_SOME(manifest);
+  EXPECT_EQ(2u, manifest->schemaversion());
+  EXPECT_EQ("application/vnd.docker.distribution.manifest.v2+json",
+            manifest->mediatype());
+
+  EXPECT_TRUE(os::exists(path::join(dir, manifest->config().digest())));
+
+  for (int i = 0; i < manifest->layers_size(); i++) {
+    EXPECT_TRUE(os::exists(
+        DockerFetcherPlugin::getBlobPath(dir, manifest->layers(i).digest())));
+  }
+}
+
+
 // This test verifies invoking 'fetch' by plugin name.
 TEST_F(DockerFetcherPluginTest, DISABLED_INTERNET_CURL_InvokeFetchByName)
 {


[mesos] 03/04: Added workaround for Docker repositories not providing scope/service.

Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

asekretenko pushed a commit to branch 1.9.x
in repository https://gitbox.apache.org/repos/asf/mesos.git

commit cee9957702bdf7cf59991299e9720ef0314275fd
Author: Andrei Sekretenko <as...@mesosphere.com>
AuthorDate: Thu Jan 30 14:26:38 2020 +0100

    Added workaround for Docker repositories not providing scope/service.
    
    This patch adds a fallback Docker authorization server URI generation
    mechanism (see MESOS-10092) for repository servers that provide no
    "scope"/"service" params in the "WWW-Authenticate" header of the initial
    "401 Unathorized" response.
    
    Review: https://reviews.apache.org/r/72079
---
 src/uri/fetchers/docker.cpp | 163 ++++++++++++++++++++++++++++++++------------
 src/uri/fetchers/docker.hpp |   9 ++-
 2 files changed, 128 insertions(+), 44 deletions(-)

diff --git a/src/uri/fetchers/docker.cpp b/src/uri/fetchers/docker.cpp
index 42b8b39..7e11079 100644
--- a/src/uri/fetchers/docker.cpp
+++ b/src/uri/fetchers/docker.cpp
@@ -450,6 +450,12 @@ static URI constructRegistryUri(const URI& imageUri, string&& path)
 }
 
 
+static URI getRegistryRootUri(const URI& imageUri)
+{
+  return constructRegistryUri(imageUri, "/v2");
+}
+
+
 static URI getManifestUri(const URI& imageUri)
 {
   return constructRegistryUri(
@@ -467,56 +473,40 @@ static URI getBlobUri(const URI& imageUri)
 }
 
 
-// Obtains URI of the V2 authorization service based on the
-// initial "401 unauthorized" response of the Docker V2 registry.
-static Future<string> getAuthServiceUri(const http::Response& initialResponse)
+// Validates that the response contains WWW-Authenticate header with
+// a scheme BEARER and, if so, extracts parameters from the header.
+// Otherwise, returns Error.
+static Try<hashmap<string, string>> getBearerAuthParam(
+    const URI& uri,
+    const http::Response& response)
 {
   Result<http::header::WWWAuthenticate> header =
-    initialResponse.headers.get<http::header::WWWAuthenticate>();
+    response.headers.get<http::header::WWWAuthenticate>();
 
   if (header.isError()) {
-    return Failure("Failed to get WWW-Authenticate header: " + header.error());
+    return Error(
+        "Failed to get WWW-Authenticate header from " + stringify(uri) +
+        ": " + header.error());
   } else if (header.isNone()) {
-    return Failure("Unexpected empty WWW-Authenticate header");
+    return Error(
+        "Got unexpected empty WWW-Authenticate header from " + stringify(uri));
   }
 
   // According to RFC, auth scheme should be case insensitive.
   const string authScheme = strings::upper(header->authScheme());
-
-  if (authScheme == "BASIC") {
-    return Failure(
-        "Unexpected BASIC Authorization response status: " +
-        initialResponse.status);
+  if (authScheme == "BASIC"){
+    return Error(
+        "Got unexpected BASIC Authorization response status: " +
+        response.status + " from " + stringify(uri));
   }
 
   if (authScheme != "BEARER") {
-    return Failure("Unsupported auth-scheme: " + authScheme);
+    return Error(
+        "Got unsupported auth-scheme: " + authScheme +
+        " from " + stringify(uri));
   }
 
-  hashmap<string, string> authParam = header->authParam();
-
-  // `authParam` is supposed to contain the 'realm', 'service'
-  // and 'scope' information for bearer authentication.
-  //
-  // TODO(asekretenko): Fall back to querying repository root and
-  // constructing scope if one of these is missing (see MESOS-10092).
-  if (!authParam.contains("realm")) {
-    return Failure("Missing 'realm' in WWW-Authenticate header");
-  }
-
-  if (!authParam.contains("service")) {
-    return Failure("Missing 'service' in WWW-Authenticate header");
-  }
-
-  if (!authParam.contains("scope")) {
-    return Failure("Missing 'scope' in WWW-Authenticate header");
-  }
-
-  // TODO(jieyu): Currently, we don't expect the auth server to return
-  // a service or a scope that needs encoding.
-  return authParam.at("realm") + "?" +
-    "service=" + authParam.at("service") + "&" +
-    "scope=" + authParam.at("scope");
+  return header->authParam();
 }
 
 
@@ -529,10 +519,12 @@ class DockerFetcherPluginProcess : public Process<DockerFetcherPluginProcess>
 public:
   DockerFetcherPluginProcess(
       const hashmap<string, spec::Config::Auth>& _auths,
-      const Option<Duration>& _stallTimeout)
+      const Option<Duration>& _stallTimeout,
+      bool _enableAuthServiceUriFallback)
     : ProcessBase(process::ID::generate("docker-fetcher-plugin")),
       auths(_auths),
-      stallTimeout(_stallTimeout) {}
+      stallTimeout(_stallTimeout),
+      enableAuthServiceUriFallback(_enableAuthServiceUriFallback) {}
 
   Future<Nothing> fetch(
       const URI& uri,
@@ -585,9 +577,16 @@ private:
       vector<string> urls);
 #endif
 
+  Future<string> getAuthServiceUri(
+      const string& repository,
+      const URI& initialUri,
+      const http::Response& initialResponse,
+      const http::Headers& basicAuthHeaders) const;
+
   // Returns a token-based authorization header. Basic authorization
   // header may be required to get a proper authorization token.
   Future<http::Headers> getAuthHeader(
+      const string& repository,
       const URI& uri,
       const http::Headers& basicAuthHeaders,
       const http::Response& response);
@@ -599,6 +598,10 @@ private:
 
   // Timeout for curl to wait when a net download stalls.
   const Option<Duration> stallTimeout;
+
+  // Disables auth server URI generation (see MESOS-10092).
+  // Used for tests only.
+  const bool enableAuthServiceUriFallback;
 };
 
 
@@ -619,7 +622,9 @@ DockerFetcherPlugin::Flags::Flags()
 const char DockerFetcherPlugin::NAME[] = "docker";
 
 
-Try<Owned<Fetcher::Plugin>> DockerFetcherPlugin::create(const Flags& flags)
+Try<Owned<Fetcher::Plugin>> DockerFetcherPlugin::create(
+    const Flags& flags,
+    bool enableAuthServiceUriFallback)
 {
   // TODO(jieyu): Make sure curl is available.
 
@@ -637,7 +642,8 @@ Try<Owned<Fetcher::Plugin>> DockerFetcherPlugin::create(const Flags& flags)
 
   Owned<DockerFetcherPluginProcess> process(new DockerFetcherPluginProcess(
       hashmap<string, spec::Config::Auth>(auths),
-      flags.docker_stall_timeout));
+      flags.docker_stall_timeout,
+      enableAuthServiceUriFallback));
 
   return Owned<Fetcher::Plugin>(new DockerFetcherPlugin(process));
 }
@@ -802,7 +808,7 @@ Future<Nothing> DockerFetcherPluginProcess::_fetch(
 {
   if (response.code == http::Status::UNAUTHORIZED) {
     // Use the 'Basic' credential to request an auth token by default.
-    return getAuthHeader(manifestUri, basicAuthHeaders, response)
+    return getAuthHeader(uri.path(), manifestUri, basicAuthHeaders, response)
       .then(defer(self(), [=](
           const http::Headers& authHeaders) -> Future<Nothing> {
         return curl(manifestUri, manifestHeaders + authHeaders, stallTimeout)
@@ -1021,7 +1027,7 @@ Future<Nothing> DockerFetcherPluginProcess::_fetchBlob(
           "but get '" + response.status + "' instead");
       }
 
-      return getAuthHeader(blobUri, basicAuthHeaders, response)
+      return getAuthHeader(uri.path(), blobUri, basicAuthHeaders, response)
         .then(defer(self(), [=](
             const http::Headers& authHeaders) -> Future<Nothing> {
           return download(
@@ -1121,6 +1127,76 @@ Future<Nothing> DockerFetcherPluginProcess::_urlFetchBlob(
 }
 #endif
 
+// Tries to obtain URI of the V2 authorization service based on the
+// "realm", "scope" and "service" auth params from the
+// initial "401 unauthorized" response of the Docker V2 registry
+// (see details in https://docs.docker.com/registry/spec/auth/token).
+//
+// If any of the params are missing from the "WWW-Authenticate" header, this
+// function falls back to the scheme implemented in Docker image puller (see
+// MESOS-10092): it queries the registry root URI (as opposed to manifest/blob
+// URI) to get the "WWW-Authenticate" header with "realm", and composes the
+// repository scope on its own. Scope grammar and semantics are documented in
+// https://docs.docker.com/registry/spec/auth/scope .
+Future<string> DockerFetcherPluginProcess::getAuthServiceUri(
+    const string& repository,
+    const URI& initialUri,
+    const http::Response& initialResponse,
+    const http::Headers& basicAuthHeaders) const
+{
+  const Try<hashmap<string, string>> authParam =
+    getBearerAuthParam(initialUri, initialResponse);
+
+  if (authParam.isError()) {
+    LOG(WARNING) << authParam.error();
+    return Failure(authParam.error());
+  }
+
+  // `authParam` is supposed to contain the 'realm', 'service'
+  // and 'scope' information for bearer authentication.
+  if (authParam->contains("realm") &&
+      authParam->contains("service") &&
+      authParam->contains("scope")) {
+    // TODO(jieyu): Currently, we don't expect the auth server to return
+    // a service or a scope that needs encoding.
+    return authParam->at("realm") + "?" +
+      "service=" + authParam->at("service") + "&" +
+      "scope=" + authParam->at("scope");
+  }
+
+  const string msg =
+    "Missing 'realm', 'service' or 'scope' in header WWW-Authenticate: " +
+    initialResponse.headers.at("WWW-Authenticate");
+
+  if (!enableAuthServiceUriFallback) {
+    return Failure(msg);
+  }
+
+  LOG(WARNING) << msg;
+
+  const URI registryRootUri = getRegistryRootUri(initialUri);
+  return curl(registryRootUri, basicAuthHeaders, stallTimeout)
+    .then([repository, registryRootUri](const http::Response& rootResponse)
+      -> Future<string> {
+      const Try<hashmap<string, string>> authParam =
+        getBearerAuthParam(registryRootUri, rootResponse);
+
+      if (authParam.isError()) {
+        LOG(WARNING) << authParam.error();
+        return Failure(authParam.error());
+      }
+
+      if (!authParam->contains("realm")) {
+        return Failure(
+            "Missing 'realm' in WWW-Authenticate header obtained from " +
+            stringify(registryRootUri));
+      }
+
+      return authParam->at("realm") + "?scope=repository:" + repository +
+             ":pull";
+    });
+}
+
 
 // If a '401 Unauthorized' response is received and the auth-scheme
 // is 'Bearer', we expect a header 'Www-Authenticate' containing the
@@ -1132,13 +1208,14 @@ Future<Nothing> DockerFetcherPluginProcess::_urlFetchBlob(
 // See details here:
 // https://docs.docker.com/registry/spec/auth/token/
 Future<http::Headers> DockerFetcherPluginProcess::getAuthHeader(
+    const string& repository,
     const URI& uri,
     const http::Headers& basicAuthHeaders,
     const http::Response& response)
 {
   const auto stallTimeout = this->stallTimeout;
 
-  return getAuthServiceUri(response)
+  return getAuthServiceUri(repository, uri, response, basicAuthHeaders)
     .then([basicAuthHeaders, stallTimeout](const string& authServiceUri) {
       return curl(authServiceUri, basicAuthHeaders, stallTimeout)
         .then([authServiceUri](const http::Response& response)
diff --git a/src/uri/fetchers/docker.hpp b/src/uri/fetchers/docker.hpp
index 2bb9214..62b5d81 100644
--- a/src/uri/fetchers/docker.hpp
+++ b/src/uri/fetchers/docker.hpp
@@ -45,7 +45,14 @@ public:
 
   static const char NAME[];
 
-  static Try<process::Owned<Fetcher::Plugin>> create(const Flags& flags);
+  // `enableAuthServiceUriFallback` switches on the fallback auth service URI
+  // generation scheme for V2 registries that do not provide 'service'/'scope'
+  // parameters in the initial 'WWW-Authenticate' header.
+  //
+  // NOTE: switching the fallback off is required for testing purposes.
+  static Try<process::Owned<Fetcher::Plugin>> create(
+      const Flags& flags,
+      bool enableAuthServiceUriFallback = true);
 
   static std::string getBlobPath(
       const std::string& directory,