18676: simplify AnonymousUserToken configuration.
authorWard Vandewege <ward@curii.com>
Thu, 3 Feb 2022 18:58:39 +0000 (13:58 -0500)
committerWard Vandewege <ward@curii.com>
Thu, 3 Feb 2022 18:58:39 +0000 (13:58 -0500)
Arvados-DCO-1.1-Signed-off-by: Ward Vandewege <ward@curii.com>

lib/boot/seed.go
lib/config/config.default.yml
services/api/app/models/api_client_authorization.rb
services/api/app/models/database_seeds.rb
services/api/lib/current_api_client.rb

index bd1e942658e9f50fba873d3de4f3a1c971dd54dc..b43d907201d47a44c013ec7d201955f7f5145377 100644 (file)
@@ -27,9 +27,5 @@ func (seedDatabase) Run(ctx context.Context, fail func(error), super *Supervisor
        if err != nil {
                return err
        }
-       err = super.RunProgram(ctx, "services/api", runOptions{env: railsEnv}, "bundle", "exec", "./script/get_anonymous_user_token.rb")
-       if err != nil {
-               return err
-       }
        return nil
 }
index 17bba5410bb4f31efceb8b1b6ed74eb372d183b8..a7ce9828573fb4b5832f49837de19413af4aa6d4 100644 (file)
@@ -294,9 +294,7 @@ Clusters:
       NewInactiveUserNotificationRecipients: {}
 
       # Set AnonymousUserToken to enable anonymous user access. Populate this
-      # field with a long random string. Then run "bundle exec
-      # ./script/get_anonymous_user_token.rb" in the directory where your API
-      # server is running to record the token in the database.
+      # field with a random string at least 50 characters long.
       AnonymousUserToken: ""
 
       # If a new user has an alternate email address (local@domain)
index 7c7ed759c60058b5915ad1d56505dba6b56d84dd..26853c34967a5b66de29e24d46ba85551809b4ff 100644 (file)
@@ -111,6 +111,17 @@ class ApiClientAuthorization < ArvadosModel
     clnt
   end
 
+  def self.check_anonymous_user_token token
+    if token.length >= 50 and token == Rails.configuration.Users.AnonymousUserToken
+      return ApiClientAuthorization.new(user: User.find_by_uuid(anonymous_user_uuid),
+                                        uuid: Rails.configuration.ClusterID+"-gj3su-anonymouspublic",
+                                        api_token: token,
+                                        api_client: anonymous_user_token_api_client)
+    else
+      return nil
+    end
+  end
+
   def self.check_system_root_token token
     if token == Rails.configuration.SystemRootToken
       return ApiClientAuthorization.new(user: User.find_by_uuid(system_user_uuid),
@@ -126,6 +137,11 @@ class ApiClientAuthorization < ArvadosModel
     return nil if token.nil? or token.empty?
     remote ||= Rails.configuration.ClusterID
 
+    auth = self.check_anonymous_user_token(token)
+    if !auth.nil?
+      return auth
+    end
+
     auth = self.check_system_root_token(token)
     if !auth.nil?
       return auth
index 67bd3d10d78975cd942a32acc7bb49306d31e0cc..e0ae850ae7b10412eaa5a7578601de5da0f5e064 100644 (file)
@@ -14,6 +14,7 @@ class DatabaseSeeds
       anonymous_group
       anonymous_group_read_permission
       anonymous_user
+      anonymous_user_token_api_client
       system_root_token_api_client
       public_project_group
       public_project_read_permission
index 37e86976c1d9c5032d1948b415290069def7e1b3..ee666b77ab78632f843211fc9e510f9dd11f564c 100644 (file)
@@ -225,6 +225,16 @@ module CurrentApiClient
     end
   end
 
+  def anonymous_user_token_api_client
+    $anonymous_user_token_api_client = check_cache $anonymous_user_token_api_client do
+      act_as_system_user do
+        ActiveRecord::Base.transaction do
+          ApiClient.find_or_create_by!(is_trusted: false, url_prefix: "", name: "AnonymousUserToken")
+        end
+      end
+    end
+  end
+
   def system_root_token_api_client
     $system_root_token_api_client = check_cache $system_root_token_api_client do
       act_as_system_user do