2015-10-24 18:46:33 +05:30
|
|
|
namespace :gitlab do
|
|
|
|
namespace :two_factor do
|
2020-03-13 15:44:24 +05:30
|
|
|
desc "GitLab | 2FA | Disable Two-factor authentication (2FA) for all users"
|
2018-05-09 12:01:36 +05:30
|
|
|
task disable_for_all_users: :gitlab_environment do
|
2015-10-24 18:46:33 +05:30
|
|
|
scope = User.with_two_factor
|
|
|
|
count = scope.count
|
|
|
|
|
|
|
|
if count > 0
|
2016-06-16 23:09:34 +05:30
|
|
|
puts "This will disable 2FA for #{count.to_s.color(:red)} users..."
|
2015-10-24 18:46:33 +05:30
|
|
|
|
|
|
|
begin
|
|
|
|
ask_to_continue
|
|
|
|
scope.find_each(&:disable_two_factor!)
|
2016-06-16 23:09:34 +05:30
|
|
|
puts "Successfully disabled 2FA for #{count} users.".color(:green)
|
2015-10-24 18:46:33 +05:30
|
|
|
rescue Gitlab::TaskAbortedByUserError
|
2016-06-16 23:09:34 +05:30
|
|
|
puts "Quitting...".color(:red)
|
2015-10-24 18:46:33 +05:30
|
|
|
end
|
|
|
|
else
|
2016-06-16 23:09:34 +05:30
|
|
|
puts "There are currently no users with 2FA enabled.".color(:yellow)
|
2015-10-24 18:46:33 +05:30
|
|
|
end
|
|
|
|
end
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
namespace :rotate_key do
|
|
|
|
def rotator
|
|
|
|
@rotator ||= Gitlab::OtpKeyRotator.new(ENV['filename'])
|
|
|
|
end
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
desc "GitLab | 2FA | Rotate Key | Encrypt user OTP secrets with a new encryption key"
|
2017-09-10 17:25:29 +05:30
|
|
|
task apply: :environment do |t, args|
|
|
|
|
rotator.rotate!(old_key: ENV['old_key'], new_key: ENV['new_key'])
|
|
|
|
end
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
desc "GitLab | 2FA | Rotate Key | Rollback to secrets encrypted with the old encryption key"
|
2017-09-10 17:25:29 +05:30
|
|
|
task rollback: :environment do
|
|
|
|
rotator.rollback!
|
|
|
|
end
|
|
|
|
end
|
2015-10-24 18:46:33 +05:30
|
|
|
end
|
|
|
|
end
|