Skip to content

Instantly share code, notes, and snippets.

@xtoddx
Created July 28, 2015 19:54
Show Gist options
  • Save xtoddx/8e759fee43aa95b186ee to your computer and use it in GitHub Desktop.
Save xtoddx/8e759fee43aa95b186ee to your computer and use it in GitHub Desktop.
who-iam.rb
#!/usr/bin/env ruby
# Inspired by:
# http://blog.jverkamp.com/2015/07/22/finding-aws-iam-users-by-access-key/
require 'fog/aws'
Fog.credential = ARGV.shift.to_sym
search_id = ARGV.shift
iam = Fog::AWS::IAM.new
map = {}
iam.users.each {|x| map[x.arn] = x.access_keys.map(&:id) }
results = map.select{|arn, ids| ids.include?(search_id) }
p results.keys
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment