Created
September 2, 2014 14:39
-
-
Save nickrw/8059cb4475e89d3090cd to your computer and use it in GitHub Desktop.
Finds the IAM user that owns an AWS access key
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Usage: ./find-access-key-by-id.sh <ACCESS KEY ID> | |
# Dependencies: | |
# * awscli (pip install awscli) | |
# * jq (https://github.com/stedolan/jq) | |
MYSTERY_KEY=$1 | |
users=$(aws iam list-users | jq -r .Users[].UserName) | |
for iamuser in $users; do | |
match=$(aws iam list-access-keys --user-name $iamuser | \ | |
jq -r ".AccessKeyMetadata[] | |
| select(.AccessKeyId == \"$MYSTERY_KEY\") | |
| .UserName + \": \" + .AccessKeyId + \" (\" + .Status + \")\"" | |
) | |
if [ ! -z "$match" ]; then | |
echo "$match" | |
exit 0 | |
fi | |
done | |
exit 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment