Merge branch '16347-container-local-keepstore'
authorTom Clegg <tom@curii.com>
Thu, 28 Oct 2021 14:14:09 +0000 (10:14 -0400)
committerTom Clegg <tom@curii.com>
Thu, 28 Oct 2021 14:14:09 +0000 (10:14 -0400)
closes #16347

Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom@curii.com>

doc/admin/upgrading.html.textile.liquid
services/api/app/models/user.rb
services/api/db/migrate/20211027154300_delete_disabled_user_tokens_and_keys.rb [new file with mode: 0644]
services/api/test/integration/users_test.rb

index 170e2c51b3edc2e9850060f6e903295afafb7028..aee2b581b2f0bc607b42cab1cb8e744f11fb66cc 100644 (file)
@@ -37,7 +37,7 @@ TODO: extract this information based on git commit messages and generate changel
 
 h2(#main). development main (as of 2021-10-27)
 
-"Upgrading from 2.3.0":#v2_3_0
+"previous: Upgrading from 2.3.0":#v2_3_0
 
 h3. Dedicated keepstore process for each container
 
@@ -48,7 +48,7 @@ When Arvados runs a container via @arvados-dispatch-cloud@, the @crunch-run@ sup
 
 h2(#v2_3_0). v2.3.0 (2021-10-27)
 
-"Upgrading from 2.2.0":#v2_2_0
+"previous: Upgrading from 2.2.0":#v2_2_0
 
 h3. Ubuntu 18.04 packages for arvados-api-server and arvados-workbench now conflict with ruby-bundler
 
@@ -80,7 +80,7 @@ Typically a docker image collection contains a single @.tar@ file at the top lev
 
 h2(#v2_2_0). v2.2.0 (2021-06-03)
 
-"Upgrading from 2.1.0":#v2_1_0
+"previous: Upgrading from 2.1.0":#v2_1_0
 
 h3. New spelling of S3 credential configs
 
index 2e862d3ae6ba047584f7650af29fa4a44d1af107..366c03e309ca6f54c0ef5bd2ad9f3aa331c592ea 100644 (file)
@@ -300,6 +300,12 @@ SELECT target_uuid, perm_level
     Link.where(link_class: 'signature',
                      tail_uuid: self.uuid).destroy_all
 
+    # delete tokens for this user
+    ApiClientAuthorization.where(user_id: self.id).destroy_all
+    # delete ssh keys for this user
+    AuthorizedKey.where(owner_uuid: self.uuid).destroy_all
+    AuthorizedKey.where(authorized_user_uuid: self.uuid).destroy_all
+
     # delete user preferences (including profile)
     self.prefs = {}
 
diff --git a/services/api/db/migrate/20211027154300_delete_disabled_user_tokens_and_keys.rb b/services/api/db/migrate/20211027154300_delete_disabled_user_tokens_and_keys.rb
new file mode 100644 (file)
index 0000000..df3db6f
--- /dev/null
@@ -0,0 +1,15 @@
+# Copyright (C) The Arvados Authors. All rights reserved.
+#
+# SPDX-License-Identifier: AGPL-3.0
+
+class DeleteDisabledUserTokensAndKeys < ActiveRecord::Migration[5.2]
+  def up
+    execute "delete from api_client_authorizations where user_id in (select id from users where is_active ='false' and uuid not like '%-tpzed-anonymouspublic' and uuid not like '%-tpzed-000000000000000')"
+    execute "delete from authorized_keys where owner_uuid in (select uuid from users where is_active ='false' and uuid not like '%-tpzed-anonymouspublic' and uuid not like '%-tpzed-000000000000000')"
+    execute "delete from authorized_keys where authorized_user_uuid in (select uuid from users where is_active ='false' and uuid not like '%-tpzed-anonymouspublic' and uuid not like '%-tpzed-000000000000000')"
+  end
+
+  def down
+    # This migration is not reversible.
+  end
+end
index b24ddc5a52c02c495b14f9871763411fa4ccbea8..81168e15b7b43b134036717bbe9f427b9f0de0be 100644 (file)
@@ -198,6 +198,13 @@ class UsersTest < ActionDispatch::IntegrationTest
 
     verify_link_existence created['uuid'], created['email'], true, true, true, true, false
 
+    # create a token
+    token = act_as_system_user do
+      ApiClientAuthorization.create!(user: User.find_by_uuid(created['uuid']), api_client: ApiClient.all.first).api_token
+    end
+
+    assert_equal 1, ApiClientAuthorization.where(user_id: User.find_by_uuid(created['uuid']).id).size, 'expected token not found'
+
     post "/arvados/v1/users/#{created['uuid']}/unsetup", params: {}, headers: auth(:admin)
 
     assert_response :success
@@ -205,6 +212,7 @@ class UsersTest < ActionDispatch::IntegrationTest
     created2 = json_response
     assert_not_nil created2['uuid'], 'expected uuid for the newly created user'
     assert_equal created['uuid'], created2['uuid'], 'expected uuid not found'
+    assert_equal 0, ApiClientAuthorization.where(user_id: User.find_by_uuid(created['uuid']).id).size, 'token should have been deleted by user unsetup'
 
     verify_link_existence created['uuid'], created['email'], false, false, false, false, false
   end