Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions web/packages/teleport/src/Account/AccountNew.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { FeatureBox } from 'teleport/components/Layout';
import ReAuthenticate from 'teleport/components/ReAuthenticate';
import { RemoveDialog } from 'teleport/components/MfaDeviceList';

import { MFAChallengeScope } from 'teleport/services/auth/auth';
import { MfaChallengeScope } from 'teleport/services/auth/auth';

import { AuthDeviceList } from './ManageDevices/AuthDeviceList/AuthDeviceList';
import useManageDevices, {
Expand Down Expand Up @@ -216,7 +216,7 @@ export function Account({
onAuthenticated={setToken}
onClose={hideReAuthenticate}
actionText="registering a new device"
challengeScope={MFAChallengeScope.USER_SESSION}
challengeScope={MfaChallengeScope.USER_SESSION}
/>
)}
{isAddDeviceVisible && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import MfaDeviceList, { RemoveDialog } from 'teleport/components/MfaDeviceList';

import ReAuthenticate from 'teleport/components/ReAuthenticate';

import { MFAChallengeScope } from 'teleport/services/auth/auth';
import { MfaChallengeScope } from 'teleport/services/auth/auth';

import AddDevice from './AddDevice';
import useManageDevices, { State } from './useManageDevices';
Expand Down Expand Up @@ -106,7 +106,7 @@ export function ManageDevices({
onAuthenticated={setToken}
onClose={hideReAuthenticate}
actionText="registering a new device"
challengeScope={MFAChallengeScope.USER_SESSION}
challengeScope={MfaChallengeScope.USER_SESSION}
/>
)}
{isAddDeviceVisible && (
Expand Down
4 changes: 2 additions & 2 deletions web/packages/teleport/src/Console/DocumentSsh/useGetScpUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { useCallback } from 'react';
import useAttempt from 'shared/hooks/useAttemptNext';

import cfg, { UrlScpParams } from 'teleport/config';
import auth, { MFAChallengeScope } from 'teleport/services/auth/auth';
import auth, { MfaChallengeScope } from 'teleport/services/auth/auth';

export default function useGetScpUrl(addMfaToScpUrls: boolean) {
const { setAttempt, attempt, handleError } = useAttempt('');
Expand All @@ -36,7 +36,7 @@ export default function useGetScpUrl(addMfaToScpUrls: boolean) {
}
try {
let webauthn = await auth.getWebauthnResponse(
MFAChallengeScope.USER_SESSION
MfaChallengeScope.USER_SESSION
);
setAttempt({
status: 'success',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import {
import { sortNodeLogins } from 'teleport/services/nodes';
import { ApiError } from 'teleport/services/api/parseError';

import { MFAChallengeScope } from 'teleport/services/auth/auth';
import { MfaChallengeScope } from 'teleport/services/auth/auth';

import { NodeMeta } from '../../useDiscover';

Expand Down Expand Up @@ -174,7 +174,7 @@ export function TestConnection(props: AgentStepProps) {
})
}
onClose={cancelMfaDialog}
challengeScope={MFAChallengeScope.USER_SESSION}
challengeScope={MfaChallengeScope.USER_SESSION}
/>
)}
<Header>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import TextSelectCopy from 'teleport/components/TextSelectCopy';
import { generateTshLoginCommand } from 'teleport/lib/util';
import ReAuthenticate from 'teleport/components/ReAuthenticate';

import { MFAChallengeScope } from 'teleport/services/auth/auth';
import { MfaChallengeScope } from 'teleport/services/auth/auth';

import {
ActionButtons,
Expand Down Expand Up @@ -91,7 +91,7 @@ export function TestConnectionView({
<ReAuthenticate
onMfaResponse={res => testConnection(makeTestConnRequest(), res)}
onClose={cancelMfaDialog}
challengeScope={MFAChallengeScope.USER_SESSION}
challengeScope={MfaChallengeScope.USER_SESSION}
/>
)}
<Header>Test Connection</Header>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import TextSelectCopy from 'teleport/components/TextSelectCopy';
import { generateTshLoginCommand } from 'teleport/lib/util';
import ReAuthenticate from 'teleport/components/ReAuthenticate';

import { MFAChallengeScope } from 'teleport/services/auth/auth';
import { MfaChallengeScope } from 'teleport/services/auth/auth';

import {
ActionButtons,
Expand Down Expand Up @@ -103,7 +103,7 @@ export function TestConnection({
<ReAuthenticate
onMfaResponse={res => testConnection(makeTestConnRequest(), res)}
onClose={cancelMfaDialog}
challengeScope={MFAChallengeScope.USER_SESSION}
challengeScope={MfaChallengeScope.USER_SESSION}
/>
)}
<Header>Test Connection</Header>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
} from 'teleport/Discover/Shared';
import { sortNodeLogins } from 'teleport/services/nodes';

import { MFAChallengeScope } from 'teleport/services/auth/auth';
import { MfaChallengeScope } from 'teleport/services/auth/auth';

import { NodeMeta } from '../../useDiscover';

Expand Down Expand Up @@ -89,7 +89,7 @@ export function TestConnection(props: AgentStepProps) {
<ReAuthenticate
onMfaResponse={res => testConnection(selectedOpt.value, res)}
onClose={cancelMfaDialog}
challengeScope={MFAChallengeScope.USER_SESSION}
challengeScope={MfaChallengeScope.USER_SESSION}
/>
)}
<Header>Test Connection</Header>
Expand Down
14 changes: 11 additions & 3 deletions web/packages/teleport/src/Users/useUsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { useAttempt } from 'shared/hooks';

import { User } from 'teleport/services/user';
import useTeleport from 'teleport/useTeleport';
import auth from 'teleport/services/auth/auth';

export default function useUsers({
InviteCollaborators,
Expand Down Expand Up @@ -82,11 +83,18 @@ export default function useUsers({
});
}

function onCreate(u: User) {
async function onCreate(u: User) {
const webauthnResponse = await auth.getWebauthnResponseForAdminAction(true);
return ctx.userService
.createUser(u)
.createUser(u, webauthnResponse)
.then(result => setUsers([result, ...users]))
.then(() => ctx.userService.createResetPasswordToken(u.name, 'invite'));
.then(() =>
ctx.userService.createResetPasswordToken(
u.name,
'invite',
webauthnResponse
)
);
}

function onInviteCollaboratorsClose(newUsers?: User[]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import React from 'react';

import { MFAChallengeScope } from 'teleport/services/auth/auth';
import { MfaChallengeScope } from 'teleport/services/auth/auth';

import { State } from './useReAuthenticate';
import { ReAuthenticate } from './ReAuthenticate';
Expand Down Expand Up @@ -49,5 +49,5 @@ const props: State = {
onClose: () => null,
auth2faType: 'on',
actionText: 'performing this action',
challengeScope: MFAChallengeScope.UNSPECIFIED,
challengeScope: MfaChallengeScope.UNSPECIFIED,
};
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import useAttempt from 'shared/hooks/useAttemptNext';

import cfg from 'teleport/config';
import auth from 'teleport/services/auth';
import { MFAChallengeScope } from 'teleport/services/auth/auth';
import { MfaChallengeScope } from 'teleport/services/auth/auth';

import type { MfaAuthnResponse } from 'teleport/services/mfa';

Expand Down Expand Up @@ -53,7 +53,7 @@ export default function useReAuthenticate(props: Props) {
.catch(handleError);
}

function submitWithWebauthn(scope: MFAChallengeScope) {
function submitWithWebauthn(scope: MfaChallengeScope) {
setAttempt({ status: 'processing' });

if ('onMfaResponse' in props) {
Expand Down Expand Up @@ -119,7 +119,7 @@ type BaseProps = {
/**
* The MFA challenge scope of the action to perform, as defined in webauthn.proto.
*/
challengeScope: MFAChallengeScope;
challengeScope: MfaChallengeScope;
};

// MfaResponseProps defines a function
Expand Down
4 changes: 4 additions & 0 deletions web/packages/teleport/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,10 @@ const cfg = {
return cfg.auth.allowPasswordless;
},

isAdminActionMfaEnforced() {
return cfg.auth.second_factor === 'webauthn';
},

getPrimaryAuthType(): PrimaryAuthType {
if (cfg.auth.localConnectorName === 'passwordless') {
return 'passwordless';
Expand Down
48 changes: 30 additions & 18 deletions web/packages/teleport/src/services/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/

import 'whatwg-fetch';
import auth, { MFAChallengeScope } from 'teleport/services/auth/auth';
import auth, { MfaChallengeScope } from 'teleport/services/auth/auth';

import { storageService } from '../storageService';
import { WebauthnAssertionResponse } from '../auth';
Expand All @@ -31,12 +31,16 @@ const api = {
return api.fetchJsonWithMfaAuthnRetry(url, { signal: abortSignal });
},

post(url, data?, abortSignal?) {
return api.fetchJsonWithMfaAuthnRetry(url, {
body: JSON.stringify(data),
method: 'POST',
signal: abortSignal,
});
post(url, data?, abortSignal?, webauthnResponse?: WebauthnAssertionResponse) {
return api.fetchJsonWithMfaAuthnRetry(
url,
{
body: JSON.stringify(data),
method: 'POST',
signal: abortSignal,
},
webauthnResponse
);
},

postFormData(url, formData) {
Expand All @@ -58,18 +62,26 @@ const api = {
throw new Error('data for body is not a type of FormData');
},

delete(url, data?) {
return api.fetchJsonWithMfaAuthnRetry(url, {
body: JSON.stringify(data),
method: 'DELETE',
});
delete(url, data?, webauthnResponse?: WebauthnAssertionResponse) {
return api.fetchJsonWithMfaAuthnRetry(
url,
{
body: JSON.stringify(data),
method: 'DELETE',
},
webauthnResponse
);
},

put(url, data) {
return api.fetchJsonWithMfaAuthnRetry(url, {
body: JSON.stringify(data),
method: 'PUT',
});
put(url, data, webauthnResponse?: WebauthnAssertionResponse) {
return api.fetchJsonWithMfaAuthnRetry(
url,
{
body: JSON.stringify(data),
method: 'PUT',
},
webauthnResponse
);
},

/**
Expand Down Expand Up @@ -118,7 +130,7 @@ const api = {
let webauthnResponseForRetry;
try {
webauthnResponseForRetry = await auth.getWebauthnResponse(
MFAChallengeScope.ADMIN_ACTION
MfaChallengeScope.ADMIN_ACTION
);
} catch (err) {
throw new Error(
Expand Down
Loading