-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: SSO MFA - Add
SSOMFASessionData
(#47647)
* Add MFA Session Data struct and methods. * Cleanup; Add test. * Rename to upsert. * Fix license.
- Loading branch information
Showing
5 changed files
with
205 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Teleport | ||
// Copyright (C) 2024 Gravitational, Inc. | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Affero General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Affero General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Affero General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
package auth | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/gravitational/trace" | ||
|
||
mfav1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/mfa/v1" | ||
"github.com/gravitational/teleport/lib/defaults" | ||
"github.com/gravitational/teleport/lib/services" | ||
"github.com/gravitational/teleport/lib/utils" | ||
) | ||
|
||
// UpsertSSOMFASession upserts a new unverified SSO MFA session for the given username, | ||
// sessionID, connector details, and challenge extensions. | ||
func (a *Server) UpsertSSOMFASession(ctx context.Context, user string, sessionID string, connectorID string, connectorType string, ext *mfav1.ChallengeExtensions) error { | ||
err := a.UpsertSSOMFASessionData(ctx, &services.SSOMFASessionData{ | ||
Username: user, | ||
RequestID: sessionID, | ||
ConnectorID: connectorID, | ||
ConnectorType: connectorType, | ||
ChallengeExtensions: ext, | ||
}) | ||
return trace.Wrap(err) | ||
} | ||
|
||
// UpsertSSOMFASessionWithToken upserts the given SSO MFA session with a random mfa token. | ||
func (a *Server) UpsertSSOMFASessionWithToken(ctx context.Context, sd *services.SSOMFASessionData) (token string, err error) { | ||
sd.Token, err = utils.CryptoRandomHex(defaults.TokenLenBytes) | ||
if err != nil { | ||
return "", trace.Wrap(err) | ||
} | ||
|
||
if err := a.UpsertSSOMFASessionData(ctx, sd); err != nil { | ||
return "", trace.Wrap(err) | ||
} | ||
|
||
return sd.Token, nil | ||
} | ||
|
||
// GetSSOMFASession returns the SSO MFA session for the given username and sessionID. | ||
func (a *Server) GetSSOMFASession(ctx context.Context, sessionID string) (*services.SSOMFASessionData, error) { | ||
sd, err := a.GetSSOMFASessionData(ctx, sessionID) | ||
if err != nil { | ||
return nil, trace.Wrap(err) | ||
} | ||
|
||
return sd, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Teleport | ||
* Copyright (C) 2024 Gravitational, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package services | ||
|
||
import mfav1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/mfa/v1" | ||
|
||
// SSOMFASessionData SSO MFA Session data. | ||
type SSOMFASessionData struct { | ||
// RequestID is the ID of the corresponding SSO Auth request, which is used to | ||
// identity this session. | ||
RequestID string `json:"request_id,omitempty"` | ||
// Username is the Teleport username. | ||
Username string `json:"username,omitempty"` | ||
// Token is an active token used to verify the owner of this SSO MFA session data. | ||
Token string `json:"token,omitempty"` | ||
// ConnectorID is id of the corresponding Auth connector. | ||
ConnectorID string `json:"connector_id,omitempty"` | ||
// ConnectorType is SSO type of the corresponding Auth connector (SAML, OIDC). | ||
ConnectorType string `json:"connector_type,omitempty"` | ||
// ChallengeExtensions are Teleport extensions that apply to this SSO MFA session. | ||
ChallengeExtensions *mfav1.ChallengeExtensions `json:"challenge_extensions,omitempty"` | ||
} |