Skip to content

Set the usage ping cron based on UUID

What does this MR do?

Sets the usage ping cron based on UUID and removes randomization for minute and hour.

  • Added some salt minute and hour to the uuid to ensure the minute, hour and day-of-week are calculated independently

Current Issue

  • On the day of the cron, if the app is initialized before the cron runs
  • Hour & minute could be set to a past time
  • This way we risk skipping the cron job

See issue #220483 (closed) and slack See https://gitlab.slack.com/archives/C02PF508L/p1593184126036700

Are the current uuid digest generators uniform

Testing if our uuid-digest based cron calculations is uniform is possible using Kolmogorov–Smirnov test

require 'statistics'
require 'securerandom'
require 'digest'

MAX = 5000


puts "Digest::MD5.hexdigest(SecureRandom.uuid + 'hour').to_i(16) % 24"
secure_random_group = [*1..MAX].map {|e| SecureRandom.rand(24)}
uuid_random_group =  [*1..MAX].map {|e| Digest::MD5.hexdigest(SecureRandom.uuid + 'hour').to_i(16) % 24 }
puts StatisticalTest::KSTest.two_samples(group_one: secure_random_group, group_two: uuid_random_group, alpha: 0.001)


puts "Digest::MD5.hexdigest(SecureRandom.uuid + 'minute').to_i(16) % 60"
secure_random_group = [*1..MAX].map {|e| SecureRandom.rand(60)}
uuid_random_group =  [*1..MAX].map {|e| Digest::MD5.hexdigest(SecureRandom.uuid + 'minute').to_i(16) % 60 }
puts StatisticalTest::KSTest.two_samples(group_one: secure_random_group, group_two: uuid_random_group, alpha: 0.001)


puts "Digest::MD5.hexdigest(uuid).to_i(16) % 7"
secure_random_group = [*1..MAX].map {|e| SecureRandom.rand(7)}
uuid_random_group =  [*1..MAX].map {|e| Digest::MD5.hexdigest(SecureRandom.uuid).to_i(16) % 7 }
puts StatisticalTest::KSTest.two_samples(group_one: secure_random_group, group_two: uuid_random_group, alpha: 0.001)

Result

The null hypothesis is true with 99.9% confidence which means that our uuid-digest-based samples and SecureRandom.rand based ones are drawn from the same distribution for both minute & hour.

Digest::MD5.hexdigest(SecureRandom.uuid + 'hour').to_i(16) % 24
{:d_max=>0.019199999999999995, :d_critical=>0.03716922188849838, :total_samples=>10000, :alpha=>0.001, :null=>true, :alternative=>false, :confidence_level=>0.999}
Digest::MD5.hexdigest(SecureRandom.uuid + 'minute').to_i(16) % 60
{:d_max=>0.0184, :d_critical=>0.03716922188849838, :total_samples=>10000, :alpha=>0.001, :null=>true, :alternative=>false, :confidence_level=>0.999}
Digest::MD5.hexdigest(uuid).to_i(16) % 7
{:d_max=>0.012800000000000034, :d_critical=>0.03716922188849838, :total_samples=>10000, :alpha=>0.001, :null=>true, :alternative=>false, :confidence_level=>0.999}

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team
Edited by Alper Akgun

Merge request reports