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

Load saml from responses #52

Merged
merged 6 commits into from
Sep 10, 2018
Merged

Conversation

jspc
Copy link
Contributor

@jspc jspc commented Aug 7, 2018

As per #49, SAML responses from AWS return a list of 1+ role/principal ARNs that can be assumed.

This PR will:

  1. Load saml responses from onelogin, okta and parse them
  2. Return an ARN immediately should the response contain just one
  3. Ask the user to choose an ARN should many be contained within a saml response
  4. Return an error should there be none

This looks like:

# Many ARNs
$(aws-creds-from-saml) ./clisso get                                                                                                                       
OneLogin password:                                                                                                                                                                                                                         
1. 123456 - Google Authenticator                                                                                                                                                                                                           
2. 234567 - Google Authenticator                                                                                                                                                                                                           
Please choose an MFA device to authenticate with (1-2): 2                                                                                                                                                                                  
Please enter the OTP from your MFA device: 098765                                                                                                                                                                                          
0. arn:aws:iam::nnnnn:role/development                                                                                                                                                                                    
1. arn:aws:iam::nnnnn:role/qa                                                                                                                                                                                 
2. arn:aws:iam::nnnnn:role/production                                                                                                                                                                                     
3. arn:aws:iam::nnnnn:role/audit                                                                                                                                                                                     
Please select an ARN to assume: 2                                                                                                                                                                                                          
Credentials written successfully to '/tmp/.aws/credentials'              

# Single ARN
$ (aws-creds-from-saml) ./clisso get rd                                                                                                           
OneLogin password:                                                                                                                                                                                                                         
1. 123456 - Google Authenticator                                                                                                                                                                                                           
2. 234567 - Google Authenticator                                                                                                                                                                                                           
Please choose an MFA device to authenticate with (1-2): 2                                                                                                                                                                                  
Please enter the OTP from your MFA device: 654654                                                                                                                                                                                          
Credentials written successfully to '/tmp/.aws/credentials'                                       

@jspc
Copy link
Contributor Author

jspc commented Aug 8, 2018

@johananl and any chance of a review in this, also?

@johananl
Copy link
Collaborator

johananl commented Sep 6, 2018

I have to rebase because of 8f13fe8 (breaking change by OneLogin).

@johananl
Copy link
Collaborator

johananl commented Sep 6, 2018

@jspc - could you maybe share how you've configured OneLogin to return multiple IAM roles in the SAML assertion? I've been struggling with this for a while now.

@ghost
Copy link

ghost commented Sep 6, 2018

@johananl you need a different version of OneLogin for this, if I remember correctly...

@jspc
Copy link
Contributor Author

jspc commented Sep 6, 2018

Have a look at https://onelogin.service-now.com/support/?id=kb_article&sys_id=66a91d03db109700d5505eea4b9619a5 from the linked issue

jspc and others added 4 commits September 10, 2018 12:44
Wrong OneLogin config can lead to a role attribute with an empty
value in the SAML assertion. Example:

<saml:Attribute NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic" Name="https://aws.amazon.com/SAML/Attributes/Role">
    <saml:AttributeValue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string"/>
</saml:Attribute>

We check for empty value before parsing ARNs to avoid index error.
@johananl
Copy link
Collaborator

Rebased over master.

The following dependency is missing: github.com/edaniels/go-saml
Enumerate roles starting at 1 instead of 0. This is more
human-friendly and consistent with MFA device selection behavior.
@johananl
Copy link
Collaborator

Thanks so much for this contribution @jspc. Superb work on this one.
This simplifies many areas of the code and makes the user experience much better when configuring new apps. Highly appreciated!

I took the liberty to refactor the role selection part - it would panic when selecting the last role in the list, plus I wanted to be consistent with enumerating from 1 instead of 0. I've also added handling for a SAML response which contains roles sections without a value (strange, but I've got this while testing using some OneLogin config). Lastly, I've added github.com/edaniels/go-saml as a dependency which was missing.

Thanks again!

@johananl johananl merged commit 2b6e59d into allcloud-io:master Sep 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants