cevoaustralia / aws-google-auth

Provides AWS STS credentials based on Google Apps SAML SSO auth (what a jumble!)
MIT License
538 stars 179 forks source link

Major Codebase Refactor for Easier Maintenance #38

Closed mide closed 6 years ago

mide commented 6 years ago

Breaking Changes

Under-the-hood Changes

Added the following tests

Needed Work

In order to get tests to pass, I had to ignore Flake8 rule E722. We should go back and determine what the correct exceptions are to catch and only catch those.

Note

Please don't feel you need to accept this, but do please let me know. If this breaks Cevo's workflows, I may just end up maintaining my own fork.

nonspecialist commented 6 years ago

Hmmm, I have a profile in ~/.aws/config with the profile prefix in the name; e.g.

[profile None]
region = ap-southeast-2
output = json
...

It's quite possible that this was due to an intermediate version, but the result is confusing. It breaks with:

(aws-google-auth) cmp@tak.local aws-google-auth $ bin/aws-google-auth 
Failed to import U2F libraries, U2F login unavailable. Other methods can still continue.
Google Password: 
Invalid parameters.
Traceback (most recent call last):
  File "bin/aws-google-auth", line 11, in <module>
    load_entry_point('aws-google-auth==0.0.16', 'console_scripts', 'aws-google-auth')()
  File "/home/cmp/Build/Cevo/aws-google-auth/lib/python2.7/site-packages/aws_google_auth-0.0.16-py2.7.egg/aws_google_auth/__init__.py", line 52, in main
    cli(sys.argv[1:])
  File "/home/cmp/Build/Cevo/aws-google-auth/lib/python2.7/site-packages/aws_google_auth-0.0.16-py2.7.egg/aws_google_auth/__init__.py", line 107, in cli
    config.raise_if_invalid()
  File "/home/cmp/Build/Cevo/aws-google-auth/lib/python2.7/site-packages/aws_google_auth-0.0.16-py2.7.egg/aws_google_auth/configuration.py", line 72, in raise_if_invalid
    assert (self.profile.__class__ is str), "Expected profile to be a string. Got {}.".format(self.profile.__class__)
AssertionError: Expected profile to be a string. Got <type 'NoneType'>.

If I edit out the profile prefix (so it's just [None]) then all's well.

If I specify a profile on the command-line, eg aws-google-auth -p cevo-dev then it works too; but not if I just run it without setting a default profile.

$AWS_PROFILE is unset.

I think it's because config.read(args.profile) gets a NoneType first, before any sanity checking is done and then, after environment variables are read again, it's overridden by default_if_none which is passed a NoneType in as the default

Adding default='default' to line 27 of __init__.py fixes this but it would be useful to report on which profile is having issues, so the user can adjust/edit their ~/.aws/config file if needed.

nonspecialist commented 6 years ago

I think my description is confusing, so I'll adjust it.

Missing any default value for the profile argument results in a NoneType being used to load, and re-load the profile, instead of using the profile "default"

mide commented 6 years ago

Hmmm, okay. That's an interesting case. I'll take a look at that in the morning @nonspecialist. (I'm in the US - New York time zone)

coveralls commented 6 years ago

Coverage Status

Coverage increased (+8.8%) to 41.23% when pulling 622662638e170b6ca2e9c1154ba6c79d6e1628de on mide:code-cleanup into 50bcd11da1ddf11f6cb7788d09e6ab10a00a1e70 on cevoaustralia:master.

mide commented 6 years ago

@nonspecialist I was able to reproduce the problem and I feel that 2a53e49251c658b760bdeea052bf4bacf147be18 should solve your problem. That being said, I don't think we want the default to be None and instead be sts. So now when you don't specify a profile, it should use sts.

coveralls commented 6 years ago

Coverage Status

Coverage increased (+8.7%) to 41.136% when pulling 6bcc759e34e44725fc1aee90844076bdad70c0f2 on mide:code-cleanup into 50bcd11da1ddf11f6cb7788d09e6ab10a00a1e70 on cevoaustralia:master.

coveralls commented 6 years ago

Coverage Status

Coverage increased (+8.7%) to 41.136% when pulling 6bcc759e34e44725fc1aee90844076bdad70c0f2 on mide:code-cleanup into 50bcd11da1ddf11f6cb7788d09e6ab10a00a1e70 on cevoaustralia:master.

coveralls commented 6 years ago

Coverage Status

Coverage increased (+8.7%) to 41.136% when pulling 6bcc759e34e44725fc1aee90844076bdad70c0f2 on mide:code-cleanup into 50bcd11da1ddf11f6cb7788d09e6ab10a00a1e70 on cevoaustralia:master.

coveralls commented 6 years ago

Coverage Status

Coverage increased (+8.7%) to 41.136% when pulling 6bcc759e34e44725fc1aee90844076bdad70c0f2 on mide:code-cleanup into 50bcd11da1ddf11f6cb7788d09e6ab10a00a1e70 on cevoaustralia:master.

coveralls commented 6 years ago

Coverage Status

Coverage increased (+8.8%) to 41.23% when pulling 2a53e49251c658b760bdeea052bf4bacf147be18 on mide:code-cleanup into 50bcd11da1ddf11f6cb7788d09e6ab10a00a1e70 on cevoaustralia:master.

coveralls commented 6 years ago

Coverage Status

Coverage increased (+8.8%) to 41.23% when pulling 2a53e49251c658b760bdeea052bf4bacf147be18 on mide:code-cleanup into 50bcd11da1ddf11f6cb7788d09e6ab10a00a1e70 on cevoaustralia:master.

coveralls commented 6 years ago

Coverage Status

Coverage increased (+8.8%) to 41.23% when pulling 2a53e49251c658b760bdeea052bf4bacf147be18 on mide:code-cleanup into 50bcd11da1ddf11f6cb7788d09e6ab10a00a1e70 on cevoaustralia:master.

coveralls commented 6 years ago

Coverage Status

Coverage increased (+8.8%) to 41.23% when pulling 2a53e49251c658b760bdeea052bf4bacf147be18 on mide:code-cleanup into 50bcd11da1ddf11f6cb7788d09e6ab10a00a1e70 on cevoaustralia:master.

SamBarker commented 6 years ago

@mide sorry for the slow reply.

Being back in front of the computer again I've just outlined our cross account usage a bit more on https://github.com/cevoaustralia/aws-google-auth/issues/42#issuecomment-358106519 hopefully that makes our current use case a bit clearer.

mide commented 6 years ago

@SamBarker - I think I'm a little lost, is that just for context, or do you expect changes from that comment?

SamBarker commented 6 years ago

Just for context! Not expecting anything else at all.

On Wed, 17 Jan 2018 at 10:18, Mark Ide notifications@github.com wrote:

@SamBarker https://github.com/sambarker - I think I'm a little lost, is that just for context, or do you expect changes from that comment?

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/cevoaustralia/aws-google-auth/pull/38#issuecomment-358109307, or mute the thread https://github.com/notifications/unsubscribe-auth/ACs8qkgdhcqIP9nf6u8oXi8t3NJYm1oDks5tLRIxgaJpZM4RWd6w .

--

[image: MahiFX]

Sam Barker

Senior Developer


MahiFX

Level 3,

50 Victoria Street,

Christchurch, 8013


Mobile: +64 (0)21 1917157

Skype: sammahifx

[image: MFX Compass]

--


IMPORTANT NOTICE: MahiFX Limited (MahiFX Ltd) and MahiFX (UK) Limited (MahiFX (UK)) are operating subsidiaries within the MahiFX group of companies (collectively, the MahiFX Group). All references to “MahiFX” refer to the MahiFX Group. MahiFX Limited is registered in New Zealand (Company no. 2446590, NZBusNo 9429031595070) and Australia (Australian registered body number ARBN 152-535-085). MahiFX Limited is authorised and regulated under the Australian Securities and Investment Commission (AFSL number 414198) and the New Zealand Financial Markets Authority (FSPR number FSP197465). MahiFX (UK) Limited is registered in the United Kingdom, (registered company number 08107062). MahiFX (UK) Limited is authorised and regulated under the Financial Conduct Authority (reference number 751019).

This email, its attachments and any rights attaching hereto are confidential and intended exclusively for the person to whom the email is addressed. If you are not the intended recipient, do not read, copy, disclose or use the contents in any way. Please notify the sender by return email and destroy the email and attachments immediately. MahiFX does not accept any liability for any changes made to this email or attachments after sending by MahiFX. You must scan this email and attachments for viruses. The opinions expressed are not necessarily those of MahiFX. MahiFX accepts no liability for any loss, damage or consequence, whether caused by our own negligence or not, resulting directly or indirectly from the use of this email and attachments.

For more information about MahiFX Limited see mahifx.com.

mide commented 6 years ago

Great! Thank you!

nonspecialist commented 6 years ago

Excellent! Works for my bizarre-o ~/.aws/config with and without specifying a profile. I like the coalesce cleanup too.

👍

mide commented 6 years ago

Thanks!

stevemac007 commented 6 years ago

Looks great @mide - I've confirmed that my existing config works well. Lets get this merged and then we can look at updating the remaining open PR's.

cliveza commented 6 years ago

@stevemac007 Could we get a new python package please?

nonspecialist commented 6 years ago

@cliveza the travis build should publish a new package automatically, but TravisCI has had some problems over the past 24 hours. I'll check the build and kick it manually if need be

nonspecialist commented 6 years ago

@cliveza pypi and Docker tags have been updated