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

fix role/principal ARN position switch #199

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
22 changes: 20 additions & 2 deletions aws_google_auth/amazon.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,27 @@ def roles(self):
return roles

def assume_role(self, role, principal, saml_assertion, duration=None, auto_duration=True):

# There is a possiblity that the role and the principal ARN might switch positions
# as mentioned in the below issue:
# https://github.com/cevoaustralia/aws-google-auth/issues/163#issuecomment-599113325
#
# To resolve this, a check is first made to see if the role contains the string "role"
# and similarly if principal contains the string "provider"; if yes, then the ordering
# is as expected, else switch them
#
# This switching logic is based on the ARN naming format as provided by AWS in their docs:
# https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_identifiers.html#identifiers-arns
if "role" in role and "provider" in principal:
_role = role
_principal = principal
else:
_role = principal
_principal = role

sts_call_vars = {
'RoleArn': role,
'PrincipalArn': principal,
'RoleArn': _role,
'PrincipalArn': _principal,
'SAMLAssertion': saml_assertion
}

Expand Down