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

Automate prompt for mfa, app, role selections #354

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

odg0318
Copy link

@odg0318 odg0318 commented Jun 18, 2022

Description

I implemented that the prompts can be skipped by configuring ~/.okta_aws_login_config and command line arguments.

Related Issue

Motivation and Context

To get AWS credentials, multiple prompts are required like the followings.

$ gimme-aws-creds --profile default
Using password from keyring for XXX@example.com
Multi-factor Authentication required.
Detected preferred provider in config: GOOGLE
Enter verification code:
done

Pick an app:
[0] AWS Dev
[1] AWS Ops
[2] AWS Prod
Selection: 2
Pick a role:
[0] arn:aws:iam::1234567890:role/XXX
[1] arn:aws:iam::1234567891:role/XXX
Selections (comma separated): 1
Saving arn:aws:iam::1234567891:role/XXX as default
Written profile default to /Users/krust/.aws/credentials

Because of the prompts, it is impossible to automate process to get AWS credentials. With my codes, the process will be changed like the following.

$ gimme-aws-creds --profile default --okta-app 2 --okta-role 1
Using password from keyring for donny.oh@krustuniverse.com
Multi-factor Authentication required.
Detected preferred provider in config: GOOGLE
Enter verification code:
done

Detected app in config: AWS Prod
Detected role in config: arn:aws:iam::1234567891:role/XXX
Saving arn:aws:iam::1234567891:role/XXX as default
Written profile default to /Users/krust/.aws/credentials
$ cat ~/.okta_aws_login_config | grep mfa
preferred_mfa_type = token:software:totp
preffered_mfa_provider = GOOGLE

How Has This Been Tested?

I manually tested the code in my local. If you have any idea to test this code, please let me know.

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@@ -578,4 +587,4 @@ def fail_if_profile_not_found(self, profile_config, conf_profile, default_sectio
"""
if not profile_config and conf_profile == default_section:
raise errors.GimmeAWSCredsError(
'DEFAULT profile is missing! This is profile is required when not using --profile')
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea why there is a change on this line.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was done by your editor when you saved the file, not a big deal.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your editor added a newline character at the end of the line. GitHub indicates the absence of this with a red circle around a horizontal line. When the character exists at the end of the last line of the file, GitHub just shows the line from the file. You can see the difference locally by running tail <filename>;echo foobar and if the trailing newline is not present "foobar" will appear appended to the last line, if the trailing newline does exist, "foobar" will be on its own line. The absence of a trailing newline can cause issues with file handling, particularly with older tools (though they're likely just working as intended).

@@ -145,6 +147,8 @@ def get_args(self):
'--action-setup-fido-authenticator', action='store_true',
help='Sets up a new FIDO WebAuthn authenticator in Okta'
)
parser.add_argument('--okta-app', type=int)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added two of new arguments; --okta-app, --okta-role are automatically select the specific app and role.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the inputs should be the app and role names, not their position in the list from Okta. Those positions will change as accounts/roles are added and removed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, there are existing config options for these settings (aws_appname and aws_rolename) the parameters should match those names

@@ -549,6 +557,9 @@ def okta(self):
if self.conf_dict.get('preferred_mfa_type'):
okta.set_preferred_mfa_type(self.conf_dict['preferred_mfa_type'])

if self.conf_dict.get('preffered_mfa_provider'):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added preffered_mfa_provider option in okta_aws_login_config. This will automatically select the specific mfa provider type like GOOGLE.

Copy link
Member

@epierce epierce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The concept for the changes are good, but some changes are needed to align them with the rest of the code.

@@ -549,6 +557,9 @@ def okta(self):
if self.conf_dict.get('preferred_mfa_type'):
okta.set_preferred_mfa_type(self.conf_dict['preferred_mfa_type'])

if self.conf_dict.get('preffered_mfa_provider'):
okta.set_preferred_mfa_provider(self.conf_dict['preffered_mfa_provider'])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spelling error - preferred_mfa_provider, not preffered_mfa_provider

@@ -145,6 +147,8 @@ def get_args(self):
'--action-setup-fido-authenticator', action='store_true',
help='Sets up a new FIDO WebAuthn authenticator in Okta'
)
parser.add_argument('--okta-app', type=int)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the inputs should be the app and role names, not their position in the list from Okta. Those positions will change as accounts/roles are added and removed.

@@ -145,6 +147,8 @@ def get_args(self):
'--action-setup-fido-authenticator', action='store_true',
help='Sets up a new FIDO WebAuthn authenticator in Okta'
)
parser.add_argument('--okta-app', type=int)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, there are existing config options for these settings (aws_appname and aws_rolename) the parameters should match those names

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants