18676: make sure to handle V2 tokens properly.
authorWard Vandewege <ward@curii.com>
Thu, 10 Feb 2022 17:42:28 +0000 (12:42 -0500)
committerWard Vandewege <ward@curii.com>
Thu, 10 Feb 2022 17:42:28 +0000 (12:42 -0500)
Arvados-DCO-1.1-Signed-off-by: Ward Vandewege <ward@curii.com>

doc/install/install-keep-web.html.textile.liquid
services/api/app/models/api_client_authorization.rb

index ea2ffb5e4889a4329fa6cc94f0d9a474722aa7ba..98c31654852d5bf8a2d92b54db2feb6397e1003c 100644 (file)
@@ -109,8 +109,7 @@ h2(#update-config). Configure anonymous user token
 {% assign railsout = "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz" %}
 If you intend to use Keep-web to serve public data to anonymous clients, configure it with an anonymous token.
 
-# First, generate a long random string and put it in the @config.yml@ file, in the @AnonymousUserToken@ field.
-# Then, use the following command on the <strong>API server</strong> to register the anonymous user token in the database. {% include 'install_rails_command' %}
+# Generate a random string (>= 50 characters long) and put it in the @config.yml@ file, in the @AnonymousUserToken@ field.
 
 <notextile>
 <pre><code>    Users:
index 26853c34967a5b66de29e24d46ba85551809b4ff..f4bf4f0698ba79f7c712c6fccb3399efd35d18c3 100644 (file)
@@ -112,7 +112,19 @@ class ApiClientAuthorization < ArvadosModel
   end
 
   def self.check_anonymous_user_token token
-    if token.length >= 50 and token == Rails.configuration.Users.AnonymousUserToken
+    case token[0..2]
+    when 'v2/'
+      _, token_uuid, secret, optional = token.split('/')
+      unless token_uuid.andand.length == 27 && secret.andand.length.andand > 0
+        # invalid token
+        return nil
+      end
+    else
+      # v1 token
+      secret = token
+    end
+
+    if secret.length >= 50 and secret == Rails.configuration.Users.AnonymousUserToken
       return ApiClientAuthorization.new(user: User.find_by_uuid(anonymous_user_uuid),
                                         uuid: Rails.configuration.ClusterID+"-gj3su-anonymouspublic",
                                         api_token: token,