-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
Copy path2fa_checker.rb
46 lines (38 loc) · 1.42 KB
/
2fa_checker.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# GitHub & GitHub Enterprise 2FA auditor
# ======================================
#
# Usage: ruby 2fa_checker.rb <orgname>
#
# These environment variables must be set:
# - GITHUB_TOKEN: A valid personal access token with Organzation admin priviliges
# - GITHUB_API_ENDPOINT: A valid GitHub/GitHub Enterprise API endpoint URL
# (use https://api.github.com for GitHub.com auditing)
#
# Requires the Octokit Rubygem: https://github.com/octokit/octokit.rb
require 'octokit.rb'
begin
ACCESS_TOKEN = ENV.fetch("GITHUB_TOKEN")
API_ENDPOINT = ENV.fetch("GITHUB_API_ENDPOINT")
rescue KeyError
$stderr.puts "To run this script, please set the following environment variables:"
$stderr.puts "- GITHUB_TOKEN: A valid personal access token with Organzation admin priviliges"
$stderr.puts "- GITHUB_API_ENDPOINT: A valid GitHub/GitHub Enterprise API endpoint URL"
$stderr.puts " (use https://api.github.com for GitHub.com auditing)"
exit 1
end
Octokit.configure do |kit|
kit.api_endpoint = API_ENDPOINT
kit.access_token = ACCESS_TOKEN
kit.auto_paginate = true
end
if ARGV.length != 1
$stderr.puts "Pass a valid Organization name to audit."
exit 1
end
ORG = ARGV[0].to_s
client = Octokit::Client.new
users = client.organization_members(ORG, {:filter => "2fa_disabled"})
puts "The following #{users.count} users do not have 2FA enabled:\n\n"
users.each do |user|
puts "#{user[:login]}"
end