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

allow interactive prompts when using cached creds #442

Merged
merged 1 commit into from
Jan 15, 2024
Merged

allow interactive prompts when using cached creds #442

merged 1 commit into from
Jan 15, 2024

Conversation

cfbao
Copy link
Member

@cfbao cfbao commented Jan 15, 2024

In my testing, I find the strict behaviour when using --cache to be counter intuitive and unnecessarily harsh.
It also makes extending code more difficult.

More here: #442 (comment)

Comment on lines -46 to +43
if( cache ) {
if( string.IsNullOrEmpty( account ) || string.IsNullOrEmpty( role ) ) {
throw new BmxException( "Account & Role must be provided when using cached AWS credentials" );
}

// if using cache, avoid calling Okta at all if possible
if( cache && !string.IsNullOrEmpty( account ) && !string.IsNullOrEmpty( role ) ) {
Copy link
Member Author

@cfbao cfbao Jan 15, 2024

Choose a reason for hiding this comment

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

Real change part 1 of 2:

Don't fail the run if account & role aren't provided via config or CLI flags.

  • In my testing, I find erroring out here to be counter intuitive and unnecessarily harsh. It's perfectly fine if users want to get the cached creds early in an interactive run (which will call Okta), and later utilize the cached creds in a script (where account & role are provided via flags and Okta won't be called).
  • Erroring out here kinda mixes the purpose of the cache and nonInteractive parameters of this method, which makes extending this method to work with writing credential process command (this propsal) more difficult.

Comment on lines +84 to +85
// try getting from cache again even if calling Okta is inevitable (we still avoid the AWS call)
if( cache ) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Real change part 2 of 2.

Copy link
Member

Choose a reason for hiding this comment

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

Seems fine, I think the code as originally written would have guarded against valid credentials in BMX that Okta no longer believes are valid (user unassigned from app etc...?)

That doesn't seem like something BMX would be able to care for, it could only be done authoritatively on the AWS side by revoking old sessions altogether.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think the code as originally written would have guarded against valid credentials in BMX that Okta no longer believes are valid (user unassigned from app etc...?)

No, there's no material difference here.

If user is unassigned from the app, and

  • if they provide everything upfront, we don't call Okta in both worlds, and they can use the creds just fine
  • if they don't provide everything upfront
    • in the old world BMX fails directly
    • in the new world they won't see the account & role they want in the selection prompts

Comment on lines -26 to +27
if( string.IsNullOrEmpty( account ) ) {
if( !string.IsNullOrEmpty( config.Account ) ) {
account = config.Account;
}
if( string.IsNullOrEmpty( account ) && !string.IsNullOrEmpty( config.Account ) ) {
account = config.Account;
Copy link
Member Author

Choose a reason for hiding this comment

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

Unrelated nit: combine ifs to reduce nesting

Comment on lines -68 to 61
if( !nonInteractive ) {
string[] accounts = awsApps.Select( app => app.Label ).ToArray();
account = consolePrompter.PromptAccount( accounts );
} else {
if( nonInteractive ) {
throw new BmxException( "Account value was not provided" );
Copy link
Member Author

Choose a reason for hiding this comment

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

Unrelated nit: revert condition to early exit & reduce nesting.

@cfbao cfbao marked this pull request as ready for review January 15, 2024 19:44
@cfbao cfbao requested a review from a team as a code owner January 15, 2024 19:44
@cfbao cfbao merged commit 75f1728 into main Jan 15, 2024
9 checks passed
@cfbao cfbao deleted the tweak branch January 15, 2024 21:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants