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

Add ExternalID support to assume-role ingestion #42

Merged
merged 2 commits into from
Mar 5, 2021
Merged
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
14 changes: 9 additions & 5 deletions cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,13 @@ def handle_ingest(args):

if args.role_to_assume:

assumed_role = session.client('sts').assume_role(
RoleArn=args.role_to_assume,
RoleSessionName=f"awspx",
DurationSeconds=args.role_to_assume_duration
)["Credentials"]
assume_role_args = {"RoleArn": args.role_to_assume,
"RoleSessionName": "awspx",
"DurationSeconds": args.role_to_assume_duration,
**dict({"ExternalId": args.role_to_assume_external_id} if args.role_to_assume_external_id else {})
}

assumed_role = session.client('sts').assume_role(**assume_role_args)["Credentials"]

session = boto3.session.Session(
aws_access_key_id=assumed_role["AccessKeyId"],
Expand Down Expand Up @@ -287,6 +289,8 @@ def attack(name):
help="ARN of a role to assume for ingestion (useful for cross-account ingestion).")
pnr.add_argument('--assume-role-duration', dest='role_to_assume_duration', type=int, default=3600,
help="Maximum session duration in seconds (for --assume-role).")
pnr.add_argument('--assume-role-external-id', dest='role_to_assume_external_id',
help="External ID for the role to assume.")
pnr.add_argument('--region', dest='region', default="eu-west-1", choices=Profile.regions,
help="Region to ingest (defaults to profile region, or `eu-west-1` if not set).")
pnr.add_argument('--database', dest='database', default=None,
Expand Down