Merge branch 'master' into 15558-alternate-email-addresses
authorPeter Amstutz <pamstutz@veritasgenetics.com>
Thu, 5 Sep 2019 21:27:43 +0000 (17:27 -0400)
committerPeter Amstutz <pamstutz@veritasgenetics.com>
Thu, 5 Sep 2019 21:27:43 +0000 (17:27 -0400)
Arvados-DCO-1.1-Signed-off-by: Peter Amstutz <pamstutz@veritasgenetics.com>

19 files changed:
.licenseignore
lib/config/config.default.yml
lib/config/export.go
lib/config/generated_config.go
sdk/cwl/arvados_cwl/__init__.py
sdk/cwl/arvados_cwl/runner.py
sdk/cwl/setup.py
sdk/cwl/tests/test_submit.py
sdk/cwl/tests/wf/feddemo [new symlink]
sdk/cwl/tests/wf/revsort/revsort.cwl [new file with mode: 0644]
sdk/cwl/tests/wf/revsort/revtool.cwl [new file with mode: 0644]
sdk/cwl/tests/wf/revsort/sorttool.cwl [new file with mode: 0644]
sdk/go/arvados/config.go
services/api/app/controllers/user_sessions_controller.rb
services/api/app/models/api_client_authorization.rb
services/api/config/arvados_config.rb
services/api/test/functional/user_sessions_controller_test.rb
services/api/test/integration/remote_user_test.rb
vendor/vendor.json

index 28ddf9c290a2a77adcb1f60b8ecbb806a81d48fd..ad80dc3f4b671cc165db40fe6b215359933a0315 100644 (file)
@@ -79,3 +79,4 @@ lib/dispatchcloud/test/sshkey_*
 *.asc
 sdk/java-v2/build.gradle
 sdk/java-v2/settings.gradle
+sdk/cwl/tests/wf/feddemo
\ No newline at end of file
index 24b2e450eb8c927388ec5add94299fb931163ccf..c7a038bec6c5da05fbeef993acae2f31ff7197b9 100644 (file)
@@ -413,11 +413,20 @@ Clusters:
         MaxUUIDEntries:       1000
 
     Login:
-      # These settings are provided by your OAuth2 provider (e.g.,
-      # sso-provider).
+      # These settings are provided by your OAuth2 provider (eg
+      # Google) used to perform upstream authentication.
       ProviderAppSecret: ""
       ProviderAppID: ""
 
+      # The cluster ID to delegate the user database.  When set,
+      # logins on this cluster will be redirected to the login cluster
+      # (login cluster must appear in RemoteHosts with Proxy: true)
+      LoginCluster: ""
+
+      # How long a cached token belonging to a remote cluster will
+      # remain valid before it needs to be revalidated.
+      RemoteTokenRefresh: 5m
+
     Git:
       # Path to git or gitolite-shell executable. Each authenticated
       # request will execute this program with the single argument "http-backend"
index 6eb4fbe5f570d4abf9ffd885f1ab0d822acf7fa2..69aae2c624a68ed4fcf5837739e33e3d97fc30e7 100644 (file)
@@ -117,7 +117,11 @@ var whitelist = map[string]bool{
        "InstanceTypes":                                true,
        "InstanceTypes.*":                              true,
        "InstanceTypes.*.*":                            true,
-       "Login":                                        false,
+       "Login":                                        true,
+       "Login.ProviderAppSecret":                      false,
+       "Login.ProviderAppID":                          false,
+       "Login.LoginCluster":                           true,
+       "Login.RemoteTokenRefresh":                     true,
        "Mail":                                         false,
        "ManagementToken":                              false,
        "PostgreSQL":                                   false,
index 8a5b4610c2b9b3ec88dd7029eed52bc7de4ce704..f8a0e097dc7d4e3f9de577d747cd9c0b54a87d0b 100644 (file)
@@ -419,11 +419,20 @@ Clusters:
         MaxUUIDEntries:       1000
 
     Login:
-      # These settings are provided by your OAuth2 provider (e.g.,
-      # sso-provider).
+      # These settings are provided by your OAuth2 provider (eg
+      # Google) used to perform upstream authentication.
       ProviderAppSecret: ""
       ProviderAppID: ""
 
+      # The cluster ID to delegate the user database.  When set,
+      # logins on this cluster will be redirected to the login cluster
+      # (login cluster must appear in RemoteHosts with Proxy: true)
+      LoginCluster: ""
+
+      # How long a cached token belonging to a remote cluster will
+      # remain valid before it needs to be revalidated.
+      RemoteTokenRefresh: 5m
+
     Git:
       # Path to git or gitolite-shell executable. Each authenticated
       # request will execute this program with the single argument "http-backend"
index 4c983858020ba52a8610c3b37e274e2d3643e487..ccbce3ed3eaee5b05d7cf55f879cacfc0c87e2fb 100644 (file)
@@ -336,4 +336,5 @@ def main(args, stdout, stderr, api_client=None, keep_client=None,
                              logger_handler=arvados.log_handler,
                              custom_schema_callback=add_arv_hints,
                              loadingContext=executor.loadingContext,
-                             runtimeContext=executor.runtimeContext)
+                             runtimeContext=executor.runtimeContext,
+                             input_required=not (arvargs.create_workflow or arvargs.update_workflow))
index 5e42df62413ebcbe63455005cbc6c9a5ae2e8b36..19a6dd98b332c6dbc8363e989104a075cf90f587 100644 (file)
@@ -334,7 +334,8 @@ def upload_dependencies(arvrunner, name, document_loader,
                                  builder_job_order,
                                  discovered)
 
-    visit_class(workflowobj, ("CommandLineTool", "Workflow"), discover_default_secondary_files)
+    copied, _ = document_loader.resolve_all(copy.deepcopy(cmap(workflowobj)), base_url=uri, checklinks=False)
+    visit_class(copied, ("CommandLineTool", "Workflow"), discover_default_secondary_files)
 
     for d in list(discovered):
         # Only interested in discovered secondaryFiles which are local
index b59df35c777ee1da5d125ca8504742f7fbaff04b..d51781757479d91dce34bd3c71cf4782b9757e66 100644 (file)
@@ -38,8 +38,8 @@ setup(name='arvados-cwl-runner',
       # Note that arvados/build/run-build-packages.sh looks at this
       # file to determine what version of cwltool and schema-salad to build.
       install_requires=[
-          'cwltool==1.0.20190607183319',
-          'schema-salad==4.2.20190417121603',
+          'cwltool==1.0.20190831161204',
+          'schema-salad==4.5.20190815125611',
           'typing >= 3.6.4',
           'ruamel.yaml >=0.15.54, <=0.15.77',
           'arvados-python-client{}'.format(pysdk_dep),
index d215cba7fc0041fc6ec9540bda956e856c393c2a..d6ef665fb8fb3b89325ef022697c2f74cda05a0f 100644 (file)
@@ -1465,3 +1465,39 @@ class TestCreateWorkflow(unittest.TestCase):
         self.assertEqual(stubs.capture_stdout.getvalue(),
                          stubs.expect_workflow_uuid + '\n')
         self.assertEqual(exited, 0)
+
+    @stubs
+    def test_create_with_imports(self, stubs):
+        project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
+
+        exited = arvados_cwl.main(
+            ["--create-workflow", "--debug",
+             "--api=containers",
+             "--project-uuid", project_uuid,
+             "tests/wf/feddemo/feddemo.cwl"],
+            stubs.capture_stdout, sys.stderr, api_client=stubs.api)
+
+        stubs.api.pipeline_templates().create.refute_called()
+        stubs.api.container_requests().create.refute_called()
+
+        self.assertEqual(stubs.capture_stdout.getvalue(),
+                         stubs.expect_workflow_uuid + '\n')
+        self.assertEqual(exited, 0)
+
+    @stubs
+    def test_create_with_no_input(self, stubs):
+        project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
+
+        exited = arvados_cwl.main(
+            ["--create-workflow", "--debug",
+             "--api=containers",
+             "--project-uuid", project_uuid,
+             "tests/wf/revsort/revsort.cwl"],
+            stubs.capture_stdout, sys.stderr, api_client=stubs.api)
+
+        stubs.api.pipeline_templates().create.refute_called()
+        stubs.api.container_requests().create.refute_called()
+
+        self.assertEqual(stubs.capture_stdout.getvalue(),
+                         stubs.expect_workflow_uuid + '\n')
+        self.assertEqual(exited, 0)
diff --git a/sdk/cwl/tests/wf/feddemo b/sdk/cwl/tests/wf/feddemo
new file mode 120000 (symlink)
index 0000000..077f65b
--- /dev/null
@@ -0,0 +1 @@
+../../../../doc/user/cwl/federated
\ No newline at end of file
diff --git a/sdk/cwl/tests/wf/revsort/revsort.cwl b/sdk/cwl/tests/wf/revsort/revsort.cwl
new file mode 100644 (file)
index 0000000..af0be2f
--- /dev/null
@@ -0,0 +1,62 @@
+# Copyright (C) The Arvados Authors. All rights reserved.
+#
+# SPDX-License-Identifier: Apache-2.0
+
+#
+# This is a two-step workflow which uses "revtool" and "sorttool" defined above.
+#
+class: Workflow
+doc: "Reverse the lines in a document, then sort those lines."
+cwlVersion: v1.0
+
+
+# The inputs array defines the structure of the input object that describes
+# the inputs to the workflow.
+#
+# The "reverse_sort" input parameter demonstrates the "default" field.  If the
+# field "reverse_sort" is not provided in the input object, the default value will
+# be used.
+inputs:
+  input:
+    type: File
+    doc: "The input file to be processed."
+  reverse_sort:
+    type: boolean
+    default: true
+    doc: "If true, reverse (decending) sort"
+
+# The "outputs" array defines the structure of the output object that describes
+# the outputs of the workflow.
+#
+# Each output field must be connected to the output of one of the workflow
+# steps using the "connect" field.  Here, the parameter "#output" of the
+# workflow comes from the "#sorted" output of the "sort" step.
+outputs:
+  output:
+    type: File
+    outputSource: sorted/output
+    doc: "The output with the lines reversed and sorted."
+
+# The "steps" array lists the executable steps that make up the workflow.
+# The tool to execute each step is listed in the "run" field.
+#
+# In the first step, the "inputs" field of the step connects the upstream
+# parameter "#input" of the workflow to the input parameter of the tool
+# "revtool.cwl#input"
+#
+# In the second step, the "inputs" field of the step connects the output
+# parameter "#reversed" from the first step to the input parameter of the
+# tool "sorttool.cwl#input".
+steps:
+  rev:
+    in:
+      input: input
+    out: [output]
+    run: revtool.cwl
+
+  sorted:
+    in:
+      input: rev/output
+      reverse: reverse_sort
+    out: [output]
+    run: sorttool.cwl
diff --git a/sdk/cwl/tests/wf/revsort/revtool.cwl b/sdk/cwl/tests/wf/revsort/revtool.cwl
new file mode 100644 (file)
index 0000000..7802717
--- /dev/null
@@ -0,0 +1,45 @@
+# Copyright (C) The Arvados Authors. All rights reserved.
+#
+# SPDX-License-Identifier: Apache-2.0
+
+#
+# Simplest example command line program wrapper for the Unix tool "rev".
+#
+class: CommandLineTool
+cwlVersion: v1.0
+doc: "Reverse each line using the `rev` command"
+
+hints:
+  ResourceRequirement:
+    ramMin: 8
+
+# The "inputs" array defines the structure of the input object that describes
+# the inputs to the underlying program.  Here, there is one input field
+# defined that will be called "input" and will contain a "File" object.
+#
+# The input binding indicates that the input value should be turned into a
+# command line argument.  In this example inputBinding is an empty object,
+# which indicates that the file name should be added to the command line at
+# a default location.
+inputs:
+  input:
+    type: File
+    inputBinding: {}
+
+# The "outputs" array defines the structure of the output object that
+# describes the outputs of the underlying program.  Here, there is one
+# output field defined that will be called "output", must be a "File" type,
+# and after the program executes, the output value will be the file
+# output.txt in the designated output directory.
+outputs:
+  output:
+    type: File
+    outputBinding:
+      glob: output.txt
+
+# The actual program to execute.
+baseCommand: rev
+
+# Specify that the standard output stream must be redirected to a file called
+# output.txt in the designated output directory.
+stdout: output.txt
diff --git a/sdk/cwl/tests/wf/revsort/sorttool.cwl b/sdk/cwl/tests/wf/revsort/sorttool.cwl
new file mode 100644 (file)
index 0000000..95f50cc
--- /dev/null
@@ -0,0 +1,42 @@
+# Copyright (C) The Arvados Authors. All rights reserved.
+#
+# SPDX-License-Identifier: Apache-2.0
+
+# Example command line program wrapper for the Unix tool "sort"
+# demonstrating command line flags.
+class: CommandLineTool
+doc: "Sort lines using the `sort` command"
+cwlVersion: v1.0
+hints:
+  ResourceRequirement:
+    ramMin: 8
+
+# This example is similar to the previous one, with an additional input
+# parameter called "reverse".  It is a boolean parameter, which is
+# intepreted as a command line flag.  The value of "prefix" is used for
+# flag to put on the command line if "reverse" is true, if "reverse" is
+# false, no flag is added.
+#
+# This example also introduced the "position" field.  This indicates the
+# sorting order of items on the command line.  Lower numbers are placed
+# before higher numbers.  Here, the "-r" (same as "--reverse") flag (if
+#  present) will be added to the command line before the input file path.
+inputs:
+  - id: reverse
+    type: boolean
+    inputBinding:
+      position: 1
+      prefix: "-r"
+  - id: input
+    type: File
+    inputBinding:
+      position: 2
+
+outputs:
+  - id: output
+    type: File
+    outputBinding:
+      glob: output.txt
+
+baseCommand: sort
+stdout: output.txt
index 5a18972f5232127466a1590c023915deef354935..29dd62ac1eb2ca3f0c224bd08033284451f45c05 100644 (file)
@@ -119,8 +119,10 @@ type Cluster struct {
                Repositories string
        }
        Login struct {
-               ProviderAppSecret string
-               ProviderAppID     string
+               ProviderAppSecret  string
+               ProviderAppID      string
+               LoginCluster       string
+               RemoteTokenRefresh Duration
        }
        Mail struct {
                MailchimpAPIKey                string
index ca7ba4a40aaec0f8381512252ada75b622f61d39..4364229b77284e9dbaab975c626ec9e5e52c3e33 100644 (file)
@@ -13,6 +13,10 @@ class UserSessionsController < ApplicationController
 
   # omniauth callback method
   def create
+    if !Rails.configuration.Login.LoginCluster.empty? and Rails.configuration.Login.LoginCluster != Rails.configuration.ClusterID
+      raise "Local login disabled when LoginCluster is set"
+    end
+
     omniauth = request.env['omniauth.auth']
 
     begin
@@ -96,13 +100,30 @@ class UserSessionsController < ApplicationController
     end
     p = []
     p << "auth_provider=#{CGI.escape(params[:auth_provider])}" if params[:auth_provider]
-    if params[:return_to]
-      # Encode remote param inside callback's return_to, so that we'll get it on
-      # create() after login.
-      remote_param = params[:remote].nil? ? '' : params[:remote]
-      p << "return_to=#{CGI.escape(remote_param + ',' + params[:return_to])}"
+
+    if !Rails.configuration.Login.LoginCluster.empty? and Rails.configuration.Login.LoginCluster != Rails.configuration.ClusterID
+      host = ApiClientAuthorization.remote_host(uuid_prefix: Rails.configuration.Login.LoginCluster)
+      if not host
+        raise "LoginCluster #{Rails.configuration.Login.LoginCluster} missing from RemoteClusters"
+      end
+      scheme = "https"
+      cluster = Rails.configuration.RemoteClusters[Rails.configuration.Login.LoginCluster]
+      if cluster and cluster['Scheme'] and !cluster['Scheme'].empty?
+        scheme = cluster['Scheme']
+      end
+      login_cluster = "#{scheme}://#{host}"
+      p << "remote=#{CGI.escape(params[:remote])}" if params[:remote]
+      p << "return_to=#{CGI.escape(params[:return_to])}" if params[:return_to]
+      redirect_to "#{login_cluster}/login?#{p.join('&')}"
+    else
+      if params[:return_to]
+        # Encode remote param inside callback's return_to, so that we'll get it on
+        # create() after login.
+        remote_param = params[:remote].nil? ? '' : params[:remote]
+        p << "return_to=#{CGI.escape(remote_param + ',' + params[:return_to])}"
+      end
+      redirect_to "/auth/joshid?#{p.join('&')}"
     end
-    redirect_to "/auth/joshid?#{p.join('&')}"
   end
 
   def send_api_token_to(callback_url, user, remote=nil)
index 7645d1597ca726579dd91ead5285a9f0253c3873..55db16a4b5e3e81fe407263d0dda69cb1dce9c35 100644 (file)
@@ -87,19 +87,33 @@ class ApiClientAuthorization < ArvadosModel
   end
 
   def self.remote_host(uuid_prefix:)
-    (Rails.configuration.RemoteClusters[uuid_prefix].andand.Host) ||
-      (Rails.configuration.RemoteClusters["*"].Proxy &&
+    (Rails.configuration.RemoteClusters[uuid_prefix].andand["Host"]) ||
+      (Rails.configuration.RemoteClusters["*"]["Proxy"] &&
        uuid_prefix+".arvadosapi.com")
   end
 
+  def self.make_http_client
+    clnt = HTTPClient.new
+    if Rails.configuration.TLS.Insecure
+      clnt.ssl_config.verify_mode = OpenSSL::SSL::VERIFY_NONE
+    else
+      # Use system CA certificates
+      ["/etc/ssl/certs/ca-certificates.crt",
+       "/etc/pki/tls/certs/ca-bundle.crt"]
+        .select { |ca_path| File.readable?(ca_path) }
+        .each { |ca_path| clnt.ssl_config.add_trust_ca(ca_path) }
+    end
+    clnt
+  end
+
   def self.validate(token:, remote: nil)
     return nil if !token
     remote ||= Rails.configuration.ClusterID
 
     case token[0..2]
     when 'v2/'
-      _, uuid, secret, optional = token.split('/')
-      unless uuid.andand.length == 27 && secret.andand.length.andand > 0
+      _, token_uuid, secret, optional = token.split('/')
+      unless token_uuid.andand.length == 27 && secret.andand.length.andand > 0
         return nil
       end
 
@@ -108,11 +122,11 @@ class ApiClientAuthorization < ArvadosModel
         # matches expections.
         c = Container.where(uuid: optional).first
         if !c.nil?
-          if !c.auth_uuid.nil? and c.auth_uuid != uuid
+          if !c.auth_uuid.nil? and c.auth_uuid != token_uuid
             # token doesn't match the container's token
             return nil
           end
-          if !c.runtime_token.nil? and "v2/#{uuid}/#{secret}" != c.runtime_token
+          if !c.runtime_token.nil? and "v2/#{token_uuid}/#{secret}" != c.runtime_token
             # token doesn't match the container's token
             return nil
           end
@@ -123,45 +137,45 @@ class ApiClientAuthorization < ArvadosModel
         end
       end
 
+      # fast path: look up the token in the local database
       auth = ApiClientAuthorization.
              includes(:user, :api_client).
-             where('uuid=? and (expires_at is null or expires_at > CURRENT_TIMESTAMP)', uuid).
+             where('uuid=? and (expires_at is null or expires_at > CURRENT_TIMESTAMP)', token_uuid).
              first
       if auth && auth.user &&
          (secret == auth.api_token ||
           secret == OpenSSL::HMAC.hexdigest('sha1', auth.api_token, remote))
+        # found it
         return auth
       end
 
-      uuid_prefix = uuid[0..4]
-      if uuid_prefix == Rails.configuration.ClusterID
-        # If the token were valid, we would have validated it above
+      token_uuid_prefix = token_uuid[0..4]
+      if token_uuid_prefix == Rails.configuration.ClusterID
+        # Token is supposedly issued by local cluster, but if the
+        # token were valid, we would have been found in the database
+        # in the above query.
         return nil
-      elsif uuid_prefix.length != 5
+      elsif token_uuid_prefix.length != 5
         # malformed
         return nil
       end
 
-      host = remote_host(uuid_prefix: uuid_prefix)
+      # Invariant: token_uuid_prefix != Rails.configuration.ClusterID
+      #
+      # In other words the remaing code in this method below is the
+      # case that determines whether to accept a token that was issued
+      # by a remote cluster when the token absent or expired in our
+      # database.  To begin, we need to ask the cluster that issued
+      # the token to [re]validate it.
+      clnt = ApiClientAuthorization.make_http_client
+
+      host = remote_host(uuid_prefix: token_uuid_prefix)
       if !host
-        Rails.logger.warn "remote authentication rejected: no host for #{uuid_prefix.inspect}"
+        Rails.logger.warn "remote authentication rejected: no host for #{token_uuid_prefix.inspect}"
         return nil
       end
 
-      # Token was issued by a different cluster. If it's expired or
-      # missing in our database, ask the originating cluster to
-      # [re]validate it.
       begin
-        clnt = HTTPClient.new
-        if Rails.configuration.TLS.Insecure
-          clnt.ssl_config.verify_mode = OpenSSL::SSL::VERIFY_NONE
-        else
-          # Use system CA certificates
-          ["/etc/ssl/certs/ca-certificates.crt",
-           "/etc/pki/tls/certs/ca-bundle.crt"]
-            .select { |ca_path| File.readable?(ca_path) }
-            .each { |ca_path| clnt.ssl_config.add_trust_ca(ca_path) }
-        end
         remote_user = SafeJSON.load(
           clnt.get_content('https://' + host + '/arvados/v1/users/current',
                            {'remote' => Rails.configuration.ClusterID},
@@ -170,63 +184,91 @@ class ApiClientAuthorization < ArvadosModel
         Rails.logger.warn "remote authentication with token #{token.inspect} failed: #{e}"
         return nil
       end
-      if !remote_user.is_a?(Hash) || !remote_user['uuid'].is_a?(String) || remote_user['uuid'][0..4] != uuid[0..4]
+
+      # Check the response is well formed.
+      if !remote_user.is_a?(Hash) || !remote_user['uuid'].is_a?(String)
         Rails.logger.warn "remote authentication rejected: remote_user=#{remote_user.inspect}"
         return nil
       end
-      act_as_system_user do
-        # Add/update user and token in our database so we can
-        # validate subsequent requests faster.
-
-        user = User.find_or_create_by(uuid: remote_user['uuid']) do |user|
-          # (this block runs for the "create" case, not for "find")
-          user.is_admin = false
-          user.email = remote_user['email']
-          if remote_user['username'].andand.length.andand > 0
-            user.set_initial_username(requested: remote_user['username'])
-          end
-        end
 
+      remote_user_prefix = remote_user['uuid'][0..4]
+
+      # Clusters can only authenticate for their own users.
+      if remote_user_prefix != token_uuid_prefix
+        Rails.logger.warn "remote authentication rejected: claimed remote user #{remote_user_prefix} but token was issued by #{token_uuid_prefix}"
+        return nil
+      end
+
+      # Invariant:    remote_user_prefix == token_uuid_prefix
+      # therefore:    remote_user_prefix != Rails.configuration.ClusterID
+
+      # Add or update user and token in local database so we can
+      # validate subsequent requests faster.
+
+      user = User.find_by_uuid(remote_user['uuid'])
+
+      if !user
+        # Create a new record for this user.
+        user = User.new(uuid: remote_user['uuid'],
+                        is_active: false,
+                        is_admin: false,
+                        email: remote_user['email'],
+                        owner_uuid: system_user_uuid)
+        user.set_initial_username(requested: remote_user['username'])
+      end
+
+      # Sync user record.
+      if remote_user_prefix == Rails.configuration.Login.LoginCluster
+        # Remote cluster controls our user database, copy both
+        # 'is_active' and 'is_admin'
+        user.is_active = remote_user['is_active']
+        user.is_admin = remote_user['is_admin']
+      else
         if Rails.configuration.Users.NewUsersAreActive ||
-           Rails.configuration.RemoteClusters[remote_user['uuid'][0..4]].andand["ActivateUsers"]
-          # Update is_active to whatever it is at the remote end
+           Rails.configuration.RemoteClusters[remote_user_prefix].andand["ActivateUsers"]
+          # Default policy is to activate users, so match activate
+          # with the remote record.
           user.is_active = remote_user['is_active']
         elsif !remote_user['is_active']
-          # Remote user is inactive; our mirror should be, too.
+          # Deactivate user if the remote is inactive, otherwise don't
+          # change 'is_active'.
           user.is_active = false
         end
+      end
 
-        %w[first_name last_name email prefs].each do |attr|
-          user.send(attr+'=', remote_user[attr])
-        end
+      %w[first_name last_name email prefs].each do |attr|
+        user.send(attr+'=', remote_user[attr])
+      end
 
+      act_as_system_user do
         user.save!
 
-        auth = ApiClientAuthorization.find_or_create_by(uuid: uuid) do |auth|
+        # We will accept this token (and avoid reloading the user
+        # record) for 'RemoteTokenRefresh' (default 5 minutes).
+        # Possible todo:
+        # Request the actual api_client_auth record from the remote
+        # server in case it wants the token to expire sooner.
+        auth = ApiClientAuthorization.find_or_create_by(uuid: token_uuid) do |auth|
           auth.user = user
-          auth.api_token = secret
           auth.api_client_id = 0
         end
-
-        # Accept this token (and don't reload the user record) for
-        # 5 minutes. TODO: Request the actual api_client_auth
-        # record from the remote server in case it wants the token
-        # to expire sooner.
         auth.update_attributes!(user: user,
                                 api_token: secret,
                                 api_client_id: 0,
-                                expires_at: Time.now + 5.minutes)
+                                expires_at: Time.now + Rails.configuration.Login.RemoteTokenRefresh)
       end
       return auth
     else
+      # token is not a 'v2' token
       auth = ApiClientAuthorization.
-             includes(:user, :api_client).
-             where('api_token=? and (expires_at is null or expires_at > CURRENT_TIMESTAMP)', token).
-             first
+               includes(:user, :api_client).
+               where('api_token=? and (expires_at is null or expires_at > CURRENT_TIMESTAMP)', token).
+               first
       if auth && auth.user
         return auth
       end
     end
+
     return nil
   end
 
index 09e54b9d4f4037656d76f5749e8ce959aed2848d..5546e8e406de5ec5c3c44e9ab889786391bcd4c1 100644 (file)
@@ -107,6 +107,8 @@ arvcfg.declare_config "Users.NewUserNotificationRecipients", Hash, :new_user_not
 arvcfg.declare_config "Users.NewInactiveUserNotificationRecipients", Hash, :new_inactive_user_notification_recipients, method(:arrayToHash)
 arvcfg.declare_config "Login.ProviderAppSecret", NonemptyString, :sso_app_secret
 arvcfg.declare_config "Login.ProviderAppID", NonemptyString, :sso_app_id
+arvcfg.declare_config "Login.LoginCluster", String
+arvcfg.declare_config "Login.RemoteTokenRefresh", ActiveSupport::Duration
 arvcfg.declare_config "TLS.Insecure", Boolean, :sso_insecure
 arvcfg.declare_config "Services.SSO.ExternalURL", NonemptyString, :sso_provider_url
 arvcfg.declare_config "AuditLogs.MaxAge", ActiveSupport::Duration, :max_audit_log_age
index cee8245b25120192bd198115cba374a2232ab4b6..d96ccb0903fc72026297a412ac474a8ac895af04 100644 (file)
@@ -6,7 +6,16 @@ require 'test_helper'
 
 class UserSessionsControllerTest < ActionController::TestCase
 
-  test "new user from new api client" do
+  test "redirect to joshid" do
+    api_client_page = 'http://client.example.com/home'
+    get :login, params: {return_to: api_client_page}
+    assert_response :redirect
+    assert_equal("http://test.host/auth/joshid?return_to=%2Chttp%3A%2F%2Fclient.example.com%2Fhome", @response.redirect_url)
+    assert_nil assigns(:api_client)
+  end
+
+
+  test "send token when user is already logged in" do
     authorize_with :inactive
     api_client_page = 'http://client.example.com/home'
     get :login, params: {return_to: api_client_page}
@@ -35,4 +44,24 @@ class UserSessionsControllerTest < ActionController::TestCase
     get :login, params: {return_to: api_client_page, remote: remote_prefix}
     assert_response 400
   end
+
+  test "login to LoginCluster" do
+    Rails.configuration.Login.LoginCluster = 'zbbbb'
+    Rails.configuration.RemoteClusters['zbbbb'] = {'Host' => 'zbbbb.example.com'}
+    api_client_page = 'http://client.example.com/home'
+    get :login, params: {return_to: api_client_page}
+    assert_response :redirect
+    assert_equal("https://zbbbb.example.com/login?return_to=http%3A%2F%2Fclient.example.com%2Fhome", @response.redirect_url)
+    assert_nil assigns(:api_client)
+  end
+
+  test "don't go into redirect loop if LoginCluster is self" do
+    Rails.configuration.Login.LoginCluster = 'zzzzz'
+    api_client_page = 'http://client.example.com/home'
+    get :login, params: {return_to: api_client_page}
+    assert_response :redirect
+    assert_equal("http://test.host/auth/joshid?return_to=%2Chttp%3A%2F%2Fclient.example.com%2Fhome", @response.redirect_url)
+    assert_nil assigns(:api_client)
+  end
+
 end
index c388ac0bf2ad1a8efe27df3d0cc493dfe1ab1f3a..b3cfe27190e78dce0e15182e7724d283c7b1755f 100644 (file)
@@ -268,6 +268,19 @@ class RemoteUsersTest < ActionDispatch::IntegrationTest
     assert_equal 'barney', json_response['username']
   end
 
+  test 'get user from Login cluster' do
+    Rails.configuration.Login.LoginCluster = 'zbbbb'
+    get '/arvados/v1/users/current',
+      params: {format: 'json'},
+      headers: auth(remote: 'zbbbb')
+    assert_response :success
+    assert_equal 'zbbbb-tpzed-000000000000000', json_response['uuid']
+    assert_equal true, json_response['is_admin']
+    assert_equal true, json_response['is_active']
+    assert_equal 'foo@example.com', json_response['email']
+    assert_equal 'barney', json_response['username']
+  end
+
   test 'pre-activate remote user' do
     @stub_content = {
       uuid: 'zbbbb-tpzed-000000000001234',
index cfcba1b21888a867698980a3f9434133d02ed607..c146a000325cb25b27cbe30e5e37c80b9144b0bf 100644 (file)
@@ -3,25 +3,25 @@
        "ignore": "test",
        "package": [
                {
-                       "checksumSHA1": "j4je0EzPGzjb6INLY1BHZ+hyMjc=",
+                       "checksumSHA1": "jfYWZyRWLMfG0J5K7G2K8a9AKfs=",
                        "origin": "github.com/curoverse/goamz/aws",
                        "path": "github.com/AdRoll/goamz/aws",
-                       "revision": "888b4804f2653cd35ebcc95f046079e63b5b2799",
-                       "revisionTime": "2017-07-27T13:52:37Z"
+                       "revision": "1bba09f407ef1d02c90bc37eff7e91e2231fa587",
+                       "revisionTime": "2019-09-05T14:15:25Z"
                },
                {
-                       "checksumSHA1": "0+n3cT6e7sQCCbBAH8zg6neiHTk=",
+                       "checksumSHA1": "lqoARtBgwnvhEhLyIjR3GLnR5/c=",
                        "origin": "github.com/curoverse/goamz/s3",
                        "path": "github.com/AdRoll/goamz/s3",
-                       "revision": "888b4804f2653cd35ebcc95f046079e63b5b2799",
-                       "revisionTime": "2017-07-27T13:52:37Z"
+                       "revision": "1bba09f407ef1d02c90bc37eff7e91e2231fa587",
+                       "revisionTime": "2019-09-05T14:15:25Z"
                },
                {
                        "checksumSHA1": "tvxbsTkdjB0C/uxEglqD6JfVnMg=",
                        "origin": "github.com/curoverse/goamz/s3/s3test",
                        "path": "github.com/AdRoll/goamz/s3/s3test",
-                       "revision": "888b4804f2653cd35ebcc95f046079e63b5b2799",
-                       "revisionTime": "2017-07-27T13:52:37Z"
+                       "revision": "1bba09f407ef1d02c90bc37eff7e91e2231fa587",
+                       "revisionTime": "2019-09-05T14:15:25Z"
                },
                {
                        "checksumSHA1": "KF4DsRUpZ+h+qRQ/umRAQZfVvw0=",