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

Fix WebUI Admin Action infinite retry with no MFA devices #51134

Merged
merged 7 commits into from
Jan 25, 2025

Conversation

Joerger
Copy link
Contributor

@Joerger Joerger commented Jan 16, 2025

#49679 and subsequently #50570 introduced a change where getMfaChallengeResponse could return null | undefined when the user had no MFA challenges (no devices or not required). fetchJsonWithMfaAuthnRetry expects getMfaChallengeResponse to return {} in these cases, and will retry with MFA until it gets either an empty or non-empty object.

This PR fixes the issue by:

  1. addressing the recursive fetchJsonWithMfaAuthnRetry which could result in an infinite loop. It's no longer recursive so it will only retry once even if null or undefined is received.
  2. Reverting part of https://github.com/gravitational/teleport/pull/50570/files and instead making getMfaChallengeResponse return {} so we can properly determine at any point whether an mfa response is undefined or an empty response resulting from a no-op challenge attempt (no devices or not required).

Closes #51105

image

@Joerger Joerger requested a review from ravicious January 16, 2025 19:21
@github-actions github-actions bot requested review from rudream and ryanclark January 16, 2025 19:21
@Joerger Joerger force-pushed the joerger/fix-webui-admin-action-retry branch from 21430bc to 61b4600 Compare January 16, 2025 19:36
@Joerger Joerger added backport/branch/v17 no-changelog Indicates that a PR does not require a changelog entry labels Jan 16, 2025
Copy link
Member

@ravicious ravicious left a comment

Choose a reason for hiding this comment

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

Looks good, but there are still a few failing tests, even after fixing those in api.test.ts.

web/packages/teleport/src/services/auth/auth.ts Outdated Show resolved Hide resolved
web/packages/teleport/src/services/auth/auth.ts Outdated Show resolved Hide resolved
web/packages/teleport/src/services/api/api.ts Show resolved Hide resolved
web/packages/teleport/src/services/api/api.ts Outdated Show resolved Hide resolved
web/packages/teleport/src/services/api/api.ts Show resolved Hide resolved
@Joerger Joerger force-pushed the joerger/fix-webui-admin-action-retry branch from 61b4600 to cbc4c2a Compare January 21, 2025 18:59
@Joerger Joerger requested a review from ravicious January 21, 2025 19:31
web/packages/teleport/src/services/api/api.ts Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

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

Leaving a preemptive approval, but how do I even test it, bar what Xin described in the issue? If I set second factor to optional, I cannot even log in as a user with no MFA. The login form shows "t is undefined" error and I'm forced to select a multi-factor type anyway.

I managed to work around this by choosing an authenticator app as the MFA type and then providing a bogus code. But how is it supposed to work for normal users? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You have to make an SSO user, which wouldn't have an MFA device until you add one

Comment on lines 146 to 151
return await api.fetch(url, customOptions, mfaResponse);
} catch (err) {
// error reading JSON
const message = response.ok
? err.message
: `${response.status} - ${response.url}`;
throw new ApiError({ message, response, opts: { cause: err } });
}

if (response.ok) {
return json;
}

/** This error can occur in the edge case where a role in the user's certificate was deleted during their session. */
const isRoleNotFoundErr = isRoleNotFoundError(parseError(json));
if (isRoleNotFoundErr) {
websession.logoutWithoutSlo({
/* Don't remember location after login, since they may no longer have access to the page they were on. */
rememberLocation: false,
/* Show "access changed" notice on login page. */
withAccessChangedMessage: true,
});
return;
// Retry with MFA if we get an admin action MFA error.
if (!mfaResponse && isAdminActionRequiresMfaError(err)) {
mfaResponse = await api.getAdminActionMfaResponse();
return await api.fetch(url, customOptions, mfaResponse);
Copy link
Contributor

Choose a reason for hiding this comment

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

No need for the awaits here

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, it's not a big deal, but if you have a promise, you can return it from an async function without awaiting.

I'm not sure if there's a lint rule which would automatically take care of this. await-thenable and no-misused-promises seem to be about different cases entirely. typescript-eslint/typescript-eslint#8517

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see, I wasn't sure how the try/catch would work without the first await

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry @Joerger, you're absolutely correct

image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No problem, reverted that one.

@Joerger Joerger requested a review from ryanclark January 22, 2025 19:55
@Joerger Joerger added this pull request to the merge queue Jan 25, 2025
Merged via the queue into master with commit 6b6b0cd Jan 25, 2025
41 checks passed
@Joerger Joerger deleted the joerger/fix-webui-admin-action-retry branch January 25, 2025 02:50
@public-teleport-github-review-bot

@Joerger See the table below for backport results.

Branch Result
branch/v17 Failed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/branch/v17 no-changelog Indicates that a PR does not require a changelog entry size/sm ui
Projects
None yet
Development

Successfully merging this pull request may close these issues.

User creation hangs in the web UI with no error message if no MFA method is added
3 participants