Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce autorolestargetname to allow for custom target IAM roles #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions ghostbuster/scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,14 @@ def add_account_ids(list_accounts_response):
default="",
required=False,
help="Like --roles, but finds all organisation accounts automatically. The argument value should be ARN of a role "
"with organizations:ListAccounts and organizations:DescribeAccount. Ec2/lambda/whatever is running ghostbuster"
" must have permissions to assume the organisation lookup role."
"with organizations:ListAccounts and organizations:DescribeAccount. Ec2/lambda/whatever is running ghostbuster"
" must have permissions to assume the organisation lookup role.",
)
@click.option(
"--autorolestargetname",
default="GhostBusterTargetAccountRole",
required=False,
help="The name of the role to assume for each account in autoroles. Defaults to GhostBusterTargetAccountRole.",
)
@cli.command(help="Scan for dangling elastic IPs inside your AWS accounts.")
@pass_info
Expand All @@ -325,8 +331,9 @@ def aws(
profile: str,
roles: str,
autoroles: str,
json: bool
):
autorolestargetname: str,
json: bool,
):
"""Scan for dangling elastic IPs inside your AWS accounts."""
# ascii art
if not skipascii and not json:
Expand Down Expand Up @@ -369,7 +376,7 @@ def aws(

# collection of records from r53 using roles
for account_id in account_ids:
role_arn = "arn:aws:iam::{0}:role/GhostbusterTargetAccountRole".format(account_id)
role_arn = "arn:aws:iam::{0}:role/{1}".format(account_id, autorolestargetname)
try:
role_session = assume_role(role_arn)
log("Successfully assumed role from account {0}".format(account_id))
Expand All @@ -385,7 +392,9 @@ def aws(
elastic_ips = []
if roles or autoroles: # collection of EIPs using roles
for account_id in account_ids:
role_arn = "arn:aws:iam::{0}:role/GhostbusterTargetAccountRole".format(account_id)
role_arn = "arn:aws:iam::{0}:role/{1}".format(
account_id, autorolestargetname
)
try:
role_session = assume_role(role_arn)
except ClientError as error:
Expand Down