15232: Fix type of Collections.BlobSigningTTL config key.
authorTom Clegg <tclegg@veritasgenetics.com>
Wed, 15 May 2019 18:02:33 +0000 (14:02 -0400)
committerTom Clegg <tclegg@veritasgenetics.com>
Wed, 15 May 2019 18:02:33 +0000 (14:02 -0400)
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tclegg@veritasgenetics.com>

lib/config/config.default.yml
lib/config/generated_config.go
services/api/app/models/blob.rb
services/api/app/models/collection.rb
services/api/config/arvados_config.rb
services/api/lib/audit_logs.rb
services/api/lib/tasks/delete_old_container_logs.rake
services/api/lib/tasks/delete_old_job_logs.rake
services/api/lib/trashable.rb
services/api/test/unit/collection_test.rb
services/api/test/unit/container_request_test.rb

index c767f76132e8b10e168a36035c693576f0fae728..1c9793f974db1427ae7374f1ab11cce3abe54bb5 100644 (file)
@@ -163,7 +163,7 @@ Clusters:
       #
       # Currently, websocket event notifications rely on audit logs, so
       # this should not be set lower than 600 (5 minutes).
-      MaxAge: 1209600
+      MaxAge: 336h
 
       # Maximum number of log rows to delete in a single SQL transaction.
       #
@@ -234,11 +234,11 @@ Clusters:
       # blob_signing_key note above.
       #
       # The default is 2 weeks.
-      BlobSigningTTL: 1209600
+      BlobSigningTTL: 336h
 
       # Default lifetime for ephemeral collections: 2 weeks. This must not
       # be less than blob_signature_ttl.
-      DefaultTrashLifetime: 1209600
+      DefaultTrashLifetime: 336h
 
       # Interval (seconds) between trash sweeps. During a trash sweep,
       # collections are marked as trash if their trash_at time has
index 3c16e89558b865757066cc382d763ca51866b09d..3cbc9041a8b15de4b518e8f9b4cd4b634ff06579 100644 (file)
@@ -169,7 +169,7 @@ Clusters:
       #
       # Currently, websocket event notifications rely on audit logs, so
       # this should not be set lower than 600 (5 minutes).
-      MaxAge: 1209600
+      MaxAge: 336h
 
       # Maximum number of log rows to delete in a single SQL transaction.
       #
@@ -240,11 +240,11 @@ Clusters:
       # blob_signing_key note above.
       #
       # The default is 2 weeks.
-      BlobSigningTTL: 1209600
+      BlobSigningTTL: 336h
 
       # Default lifetime for ephemeral collections: 2 weeks. This must not
       # be less than blob_signature_ttl.
-      DefaultTrashLifetime: 1209600
+      DefaultTrashLifetime: 336h
 
       # Interval (seconds) between trash sweeps. During a trash sweep,
       # collections are marked as trash if their trash_at time has
index 54a4f369d9a058666c826cdd1a19e272962f8f3e..9f9a20fe33fa3b05bb6afc688a419c5934ce72e8 100644 (file)
@@ -51,11 +51,11 @@ class Blob
       timestamp = opts[:expire]
     else
       timestamp = db_current_time.to_i +
-        (opts[:ttl] || Rails.configuration.Collections.BlobSigningTTL)
+        (opts[:ttl] || Rails.configuration.Collections.BlobSigningTTL.to_i)
     end
     timestamp_hex = timestamp.to_s(16)
     # => "53163cb4"
-    blob_signature_ttl = Rails.configuration.Collections.BlobSigningTTL.to_s(16)
+    blob_signature_ttl = Rails.configuration.Collections.BlobSigningTTL.to_i.to_s(16)
 
     # Generate a signature.
     signature =
@@ -103,7 +103,7 @@ class Blob
     if timestamp.to_i(16) < (opts[:now] or db_current_time.to_i)
       raise Blob::InvalidSignatureError.new 'Signature expiry time has passed.'
     end
-    blob_signature_ttl = Rails.configuration.Collections.BlobSigningTTL.to_s(16)
+    blob_signature_ttl = Rails.configuration.Collections.BlobSigningTTL.to_i.to_s(16)
 
     my_signature =
       generate_signature((opts[:key] or Rails.configuration.Collections.BlobSigningKey),
index e0f653969948d6187865229be31b02f5e31a5294..22c260356702dcafb9f6b80dafe3532172b1b23a 100644 (file)
@@ -371,7 +371,7 @@ class Collection < ArvadosModel
       return manifest_text
     else
       token = Thread.current[:token]
-      exp = [db_current_time.to_i + Rails.configuration.Collections.BlobSigningTTL,
+      exp = [db_current_time.to_i + Rails.configuration.Collections.BlobSigningTTL.to_i,
              trash_at].compact.map(&:to_i).min
       self.class.sign_manifest manifest_text, token, exp
     end
@@ -379,7 +379,7 @@ class Collection < ArvadosModel
 
   def self.sign_manifest manifest, token, exp=nil
     if exp.nil?
-      exp = db_current_time.to_i + Rails.configuration.Collections.BlobSigningTTL
+      exp = db_current_time.to_i + Rails.configuration.Collections.BlobSigningTTL.to_i
     end
     signing_opts = {
       api_token: token,
index c114bb95a3eec80aa49af7a7990cdb839ebdffaa..8e4151a73e5d1daa7c2e4da89d4bbe0ca5bd96a0 100644 (file)
@@ -106,7 +106,7 @@ arvcfg.declare_config "Collections.CollectionVersioning", Boolean, :collection_v
 arvcfg.declare_config "Collections.PreserveVersionIfIdle", ActiveSupport::Duration, :preserve_version_if_idle
 arvcfg.declare_config "Collections.TrashSweepInterval", ActiveSupport::Duration, :trash_sweep_interval
 arvcfg.declare_config "Collections.BlobSigningKey", NonemptyString, :blob_signing_key
-arvcfg.declare_config "Collections.BlobSigningTTL", Integer, :blob_signature_ttl
+arvcfg.declare_config "Collections.BlobSigningTTL", ActiveSupport::Duration, :blob_signature_ttl
 arvcfg.declare_config "Collections.BlobSigning", Boolean, :permit_create_collection_with_unsigned_manifest, ->(cfg, k, v) { ConfigLoader.set_cfg cfg, "Collections.BlobSigning", !v }
 arvcfg.declare_config "Containers.SupportedDockerImageFormats", Array, :docker_image_formats
 arvcfg.declare_config "Containers.LogReuseDecisions", Boolean, :log_reuse_decisions
index e97f65a97397c86474fa69d190e92cd1fabfe8ce..886c8873891c044270313e3563c73e4fe950c5cb 100644 (file)
@@ -44,7 +44,7 @@ module AuditLogs
   end
 
   def self.tidy_in_background
-    max_age = Rails.configuration.AuditLogs.MaxAge
+    max_age = Rails.configuration.AuditLogs.MaxAge.to_i
     max_batch = Rails.configuration.AuditLogs.MaxDeleteBatch
     return if max_age <= 0 || max_batch <= 0
 
index c5c5cdc76933dc833eb0fb5c8b46995152dc503f..2146d9bc379409fbe2bffaac73dd273c29fb93e3 100644 (file)
@@ -11,7 +11,7 @@ namespace :db do
   desc "Remove old container log entries from the logs table"
 
   task delete_old_container_logs: :environment do
-    delete_sql = "DELETE FROM logs WHERE id in (SELECT logs.id FROM logs JOIN containers ON logs.object_uuid = containers.uuid WHERE event_type IN ('stdout', 'stderr', 'arv-mount', 'crunch-run', 'crunchstat') AND containers.log IS NOT NULL AND clock_timestamp() - containers.finished_at > interval '#{Rails.configuration.Containers.Logging.MaxAge} seconds')"
+    delete_sql = "DELETE FROM logs WHERE id in (SELECT logs.id FROM logs JOIN containers ON logs.object_uuid = containers.uuid WHERE event_type IN ('stdout', 'stderr', 'arv-mount', 'crunch-run', 'crunchstat') AND containers.log IS NOT NULL AND clock_timestamp() - containers.finished_at > interval '#{Rails.configuration.Containers.Logging.MaxAge.to_i} seconds')"
 
     ActiveRecord::Base.connection.execute(delete_sql)
   end
index 3c1c049998377ffe79ac9cb3a2b512d34a6834f9..a1ae2226a071b7f9b8ca0e81148e7ac5ba679b08 100644 (file)
@@ -9,7 +9,7 @@
 namespace :db do
   desc "Remove old job stderr entries from the logs table"
   task delete_old_job_logs: :environment do
-    delete_sql = "DELETE FROM logs WHERE id in (SELECT logs.id FROM logs JOIN jobs ON logs.object_uuid = jobs.uuid WHERE event_type = 'stderr' AND jobs.log IS NOT NULL AND clock_timestamp() - jobs.finished_at > interval '#{Rails.configuration.Containers.Logging.MaxAge} seconds')"
+    delete_sql = "DELETE FROM logs WHERE id in (SELECT logs.id FROM logs JOIN jobs ON logs.object_uuid = jobs.uuid WHERE event_type = 'stderr' AND jobs.log IS NOT NULL AND clock_timestamp() - jobs.finished_at > interval '#{Rails.configuration.Containers.Logging.MaxAge.to_i} seconds')"
 
     ActiveRecord::Base.connection.execute(delete_sql)
   end
index f7faabc4c262c990ee20ee60a9cdc829b1bf8214..c99b08513b64a57b046dccea7905ca032bd3b916 100644 (file)
@@ -65,7 +65,7 @@ module Trashable
       earliest_delete = [
         @validation_timestamp,
         trash_at_was,
-      ].compact.min + Rails.configuration.Collections.BlobSigningTTL.seconds
+      ].compact.min + Rails.configuration.Collections.BlobSigningTTL
 
       # The previous value of delete_at is also an upper bound on the
       # longest-lived permission token. For example, if TTL=14,
@@ -96,7 +96,7 @@ module TrashableController
       @object.update_attributes!(trash_at: db_current_time)
     end
     earliest_delete = (@object.trash_at +
-                       Rails.configuration.Collections.BlobSigningTTL.seconds)
+                       Rails.configuration.Collections.BlobSigningTTL)
     if @object.delete_at > earliest_delete
       @object.update_attributes!(delete_at: earliest_delete)
     end
index 477f9e27505200b3e080ae29b8362151adb6e21d..8cb5bbd5903251a45a7877a4aa2bc8ebc8af1ac3 100644 (file)
@@ -760,7 +760,7 @@ class CollectionTest < ActiveSupport::TestCase
                              name: 'foo',
                              trash_at: db_current_time + 1.years)
       sig_exp = /\+A[0-9a-f]{40}\@([0-9]+)/.match(c.signed_manifest_text)[1].to_i
-      expect_max_sig_exp = db_current_time.to_i + Rails.configuration.Collections.BlobSigningTTL
+      expect_max_sig_exp = db_current_time.to_i + Rails.configuration.Collections.BlobSigningTTL.to_i
       assert_operator c.trash_at.to_i, :>, expect_max_sig_exp
       assert_operator sig_exp.to_i, :<=, expect_max_sig_exp
     end
@@ -849,7 +849,7 @@ class CollectionTest < ActiveSupport::TestCase
     test test_name do
       act_as_user users(:active) do
         min_exp = (db_current_time +
-                   Rails.configuration.Collections.BlobSigningTTL.seconds)
+                   Rails.configuration.Collections.BlobSigningTTL)
         if fixture_name == :expired_collection
           # Fixture-finder shorthand doesn't find trashed collections
           # because they're not in the default scope.
index 0dad6ee75ccf64b6484bf8da202b780932ff7a95..69e277cc2c000ae627c4b1193c629ac8cf99e7dc 100644 (file)
@@ -837,7 +837,7 @@ class ContainerRequestTest < ActiveSupport::TestCase
     assert_not_nil(trash)
     assert_not_nil(delete)
     assert_in_delta(trash, now + 1.second, 10)
-    assert_in_delta(delete, now + Rails.configuration.Collections.BlobSigningTTL.second, 10)
+    assert_in_delta(delete, now + Rails.configuration.Collections.BlobSigningTTL, 10)
   end
 
   def check_output_ttl_1y(now, trash, delete)