Skip to content

Web-Discover: Add support for connection testers with per-session MFA enabled#22529

Merged
kimlisa merged 9 commits into
masterfrom
lisa/web/mfa-check-conntest
Mar 10, 2023
Merged

Web-Discover: Add support for connection testers with per-session MFA enabled#22529
kimlisa merged 9 commits into
masterfrom
lisa/web/mfa-check-conntest

Conversation

@kimlisa
Copy link
Copy Markdown
Contributor

@kimlisa kimlisa commented Mar 2, 2023

resolves #16702

Description

Implements the frontend part of RFD 0111
backend here: #22528

Before connection testing, we check if MFA is required.
If required:

  • we render a MFA dialog that asks user to provide MFA credentials
  • take this response and send it with the test connection request

Only supported for resource type node, kube, and database (no support for windows desktops yet)

Testing

Manually tested for a node, kube, and a database resource with a user assigned a role with option.require_session_mfa: true

If you want to test run yourself, this PR has all it needs, or I have a cloud cluster already running with changes if interested

Demo testing connection to a node

requiresessionmfademo.mov

@github-actions github-actions Bot requested review from ravicious and rudream March 2, 2023 04:28
@kimlisa kimlisa removed request for ravicious and rudream March 2, 2023 04:29
@kimlisa kimlisa changed the title Web: Add support for connection testers with per-session MFA enabled Discover: Add support for connection testers with per-session MFA enabled Mar 2, 2023
@kimlisa kimlisa changed the title Discover: Add support for connection testers with per-session MFA enabled Web-Discover: Add support for connection testers with per-session MFA enabled Mar 2, 2023
@kimlisa
Copy link
Copy Markdown
Contributor Author

kimlisa commented Mar 6, 2023

@ibeckermayer @ryanclark friendly ping

@kimlisa kimlisa force-pushed the lisa/mfa-check-conntest branch from dcd17b5 to 037ea12 Compare March 6, 2023 21:58
@kimlisa kimlisa force-pushed the lisa/web/mfa-check-conntest branch from 7c8f963 to 249afa8 Compare March 6, 2023 22:02
Copy link
Copy Markdown
Contributor

@ibeckermayer ibeckermayer left a comment

Choose a reason for hiding this comment

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

Seems like something we should add to the manual test plan.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
mfaAuthnResponse: MfaAuthnResponse
mfaAuthnResponse?: MfaAuthnResponse

Comment on lines 46 to 50
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
// runConnectionDiagnostic will initially make a call to check if
// resource target requires MFA authentication. After this initial
// check depending on if user successfully authenticated or not (
// determined by the presence of the token field), will make a call
// to test connection.
// If mfaAuthnResponse is provided, or if it's undefined and this function determines
// MFA authentication to be unnecessary for the given diagnostic request, it will run
// the diagnostic.
//
// If mfaAuthnResponse is undefined, runConnectionDiagnostic will initially
// make a call to check if resource target requires MFA authentication. If it does,
// it will set showMfaDialog to true, and it is up the parent component to ensure that this
// change in showMfaDialog's state to true causes the user to be prompted for MFA authentication,
// and that the subsequent call to runConnectionDiagnostic is made with the mfaAuthnResponse
// derived from that process.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

i found your explanation confusing, so i cleared it up like this (i try to follow golang convention commenting so i don't have to think too hard when switching):

  // runConnectionDiagnostic depending on the value of `mfaAuthnResponse` does the following:
  //   1) If param `mfaAuthnResponse` is undefined or null, it will check if MFA is required.
  //      - If MFA is required, it sets a flag that indicates a users
  //        MFA credentials are required, and skips the request to test connection.
  //      - If MFA is NOT required, it makes the request to test connection.
  //   2) If param `mfaAuthnResponse` is defined, it skips checking if MFA is required,
  //      and makes the request to test connection.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

How does setAttempt ever get set to success here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

it doesn't or rather it's not necessary. i think this component was created in such that after a successful "submit" the control is passed back to the parent (with the onAuthenticate or onMfaReponse func). I thought it made sense b/c there shouldn't be anything else that needs to be done after user submits. Perhaps it would've made more sense to call onClose before onAuthenticate/onMfaResponse. So if we are closing the dialog, it's clearer that we don't need anything to re-render, which is the purpose of setAttempt(success)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe worth a concise comment explaining this because it's not the standard usage pattern.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A comment about the distinct prompt shapes and how they change the behavior of the hook would be helpful.

@kimlisa
Copy link
Copy Markdown
Contributor Author

kimlisa commented Mar 6, 2023

@ibeckermayer @ryanclark i made this commit as an example: 90e5050, where i am using snake cased fields outside the service layer...

was wondering if that was okay, the conversion of field names just to satisfy JS convention was getting tiring. will change back if requested.

context: #22528 (comment)

@kimlisa
Copy link
Copy Markdown
Contributor Author

kimlisa commented Mar 7, 2023

Seems like something we should add to the manual test plan.

I will do this in another PR. there is a lot that needs to be added/updated in the test plan

@kimlisa kimlisa requested a review from ibeckermayer March 7, 2023 03:38
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we name this something other than Default?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

asked discussed in call, renamed to DefaultProps

@ibeckermayer
Copy link
Copy Markdown
Contributor

@ibeckermayer @ryanclark i made this commit as an example: 90e5050, where i am using snake cased fields outside the service layer...

was wondering if that was okay, the conversion of field names just to satisfy JS convention was getting tiring. will change back if requested.

context: #22528 (comment)

My preference is that we change the backend's responses to use camelCase like you and Alexey were doing. AFAIK the web endpoints are all only used by the web client, and so there's no good reason not to tailor them for the web client in a way that reduces boilerplate.

I'd prefer to avoid doing it ad-hoc like this, as it will make the pattern inconsistent and therefore more difficult to change to the correct solution, whatever that is.

@kimlisa
Copy link
Copy Markdown
Contributor Author

kimlisa commented Mar 8, 2023

My preference is that we change the backend's responses to use camelCase like you and Alexey were doing. AFAIK the web endpoints are all only used by the web client, and so there's no good reason not to tailor them for the web client in a way that reduces boilerplate.

Pushing for camel consistency is a losing battle b/c we have a lot more devs touching the web layer. Hard to reinforce camel when everything else is snaked so folks will naturally default to snake.

I'd prefer to avoid doing it ad-hoc like this, as it will make the pattern inconsistent and therefore more difficult to change to the correct solution, whatever that is.

Most devs will default to snake, so if we all get onboard, eventually it'll become consistent? 🥲 But the correct solution is to transition into grpc.

Btw, I double checked that ryan was okay with my approach.

@kimlisa kimlisa requested a review from ryanclark March 8, 2023 08:23
@kimlisa kimlisa force-pushed the lisa/mfa-check-conntest branch from cff9f2a to d01349f Compare March 8, 2023 08:30
@kimlisa kimlisa force-pushed the lisa/web/mfa-check-conntest branch from a673c68 to 2376f84 Compare March 8, 2023 08:34
@kimlisa kimlisa force-pushed the lisa/mfa-check-conntest branch from d01349f to f035473 Compare March 9, 2023 19:58
kimlisa added 4 commits March 9, 2023 13:06
- Add MFA response field for test connection reqs
- Define new types for checking if MFA is required
Adds a new function field for ReAuthenticate dialog
that just returns the MFA response
@kimlisa kimlisa force-pushed the lisa/web/mfa-check-conntest branch from 2376f84 to d376076 Compare March 9, 2023 21:07
@kimlisa kimlisa changed the base branch from lisa/mfa-check-conntest to master March 9, 2023 21:07
@kimlisa kimlisa enabled auto-merge March 10, 2023 16:30
@kimlisa kimlisa disabled auto-merge March 10, 2023 16:31
@kimlisa kimlisa enabled auto-merge March 10, 2023 18:56
@kimlisa kimlisa added this pull request to the merge queue Mar 10, 2023
Merged via the queue into master with commit bc6e0d9 Mar 10, 2023
@public-teleport-github-review-bot
Copy link
Copy Markdown

@kimlisa See the table below for backport results.

Branch Result
branch/v11 Failed
branch/v12 Failed

kimlisa added a commit that referenced this pull request Mar 10, 2023
… enabled (#22529)

* Define new endpoints and request fields

- Add MFA response field for test connection reqs
- Define new types for checking if MFA is required

* Implement logic to check if MFA is required

* Add MFA dialog to test connectors

Adds a new function field for ReAuthenticate dialog
that just returns the MFA response

* Update storybook

* Change json field names as a result of backend CR

* Address CRs

* Address CR 2
kimlisa added a commit that referenced this pull request Mar 11, 2023
… enabled (#22529)

* Define new endpoints and request fields

- Add MFA response field for test connection reqs
- Define new types for checking if MFA is required

* Implement logic to check if MFA is required

* Add MFA dialog to test connectors

Adds a new function field for ReAuthenticate dialog
that just returns the MFA response

* Update storybook

* Change json field names as a result of backend CR

* Address CRs

* Address CR 2
kimlisa added a commit that referenced this pull request Mar 13, 2023
… enabled (#22529) (#22943)

* Define new endpoints and request fields

- Add MFA response field for test connection reqs
- Define new types for checking if MFA is required

* Implement logic to check if MFA is required

* Add MFA dialog to test connectors

Adds a new function field for ReAuthenticate dialog
that just returns the MFA response

* Update storybook

* Change json field names as a result of backend CR

* Address CRs

* Address CR 2
kimlisa added a commit that referenced this pull request Mar 13, 2023
… enabled (#22529) (#22944)

* Define new endpoints and request fields

- Add MFA response field for test connection reqs
- Define new types for checking if MFA is required

* Implement logic to check if MFA is required

* Add MFA dialog to test connectors

Adds a new function field for ReAuthenticate dialog
that just returns the MFA response

* Update storybook

* Change json field names as a result of backend CR

* Address CRs

* Address CR 2
@r0mant r0mant deleted the lisa/web/mfa-check-conntest branch March 24, 2023 22:25
kimlisa added a commit that referenced this pull request Mar 29, 2023
kimlisa added a commit that referenced this pull request Apr 4, 2023
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.

Teleport discover fails to connect when existing roles require MFA

4 participants