Skip to content

Instantly share code, notes, and snippets.

@stbenjam stbenjam/2fa.rb
Created Jul 26, 2018

What would you like to do?
Finds the users in your orgs who have commit but no 2FA enabled
#!/usr/bin/env ruby
require 'octokit'
require 'set'
ORGS = %w[catello].freeze
puts 'You must specify a github token in the GITHUB_TOKEN environment variable.'
exit 1
client = ENV['GITHUB_TOKEN'])
comitters =
disabled =
ORGS.each do |org|
puts "Processing organization #{org}"
disabled |= client.organization_members(org, filter: '2fa_disabled').map(&:login)
puts "#{disabled.count} members in #{org} do not have 2FA enabled. Finding out which have commit..."
client.repos(org).map(&:full_name).each do |repo|
puts "Processing repo #{repo}"
comitters |= client.collaborators(repo).select { |u| u[:permissions][:push] || u[:permissions][:admin] }.map(&:login)
print "\nThe following users with admin or push access do NOT have 2FA enabled for their account:\n "
print (comitters & disabled).to_a.join("\n ")
print "\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.