Skip to content

Commit

Permalink
feat: SSO MFA - Add MFAToken to SSO Callback flow (#47648)
Browse files Browse the repository at this point in the history
* Add MFA token to SSO callback response.

* Add MFA token to auth response validation endpoints.

* Cleanup.
  • Loading branch information
Joerger authored Oct 17, 2024
1 parent 775044b commit 22edf09
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/auth/authclient/clt.go
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,8 @@ type OIDCAuthResponse struct {
// HostSigners is a list of signing host public keys
// trusted by proxy, used in console login
HostSigners []types.CertAuthority `json:"host_signers"`
// MFAToken is an SSO MFA token.
MFAToken string `json:"mfa_token"`
}

// OIDCAuthRequest is an OIDC auth request that supports standard json marshaling.
Expand Down Expand Up @@ -941,6 +943,8 @@ type SAMLAuthResponse struct {
// HostSigners is a list of signing host public keys
// trusted by proxy, used in console login
HostSigners []types.CertAuthority `json:"host_signers"`
// MFAToken is an SSO MFA token.
MFAToken string `json:"mfa_token"`
}

// SAMLAuthRequest is a SAML auth request that supports standard json marshaling.
Expand Down Expand Up @@ -1485,6 +1489,8 @@ type SSHLoginResponse struct {
HostSigners []TrustedCerts `json:"host_signers"`
// SAMLSingleLogoutEnabled is whether SAML SLO (single logout) is enabled for the SAML auth connector being used, if applicable.
SAMLSingleLogoutEnabled bool `json:"samlSingleLogoutEnabled"`
// MFAToken is an SSO MFA token.
MFAToken string `json:"mfa_token"`
}

// TrustedCerts contains host certificates, it preserves backwards compatibility
Expand Down
6 changes: 6 additions & 0 deletions lib/auth/authclient/http_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,8 @@ type OIDCAuthRawResponse struct {
// HostSigners is a list of signing host public keys
// trusted by proxy, used in console login
HostSigners []json.RawMessage `json:"host_signers"`
// MFAToken is an SSO MFA token.
MFAToken string `json:"mfa_token"`
}

// ValidateOIDCAuthCallback validates OIDC auth callback returned from redirect
Expand All @@ -658,6 +660,7 @@ func (c *HTTPClient) ValidateOIDCAuthCallback(ctx context.Context, q url.Values)
Cert: rawResponse.Cert,
Req: rawResponse.Req,
TLSCert: rawResponse.TLSCert,
MFAToken: rawResponse.MFAToken,
}
if len(rawResponse.Session) != 0 {
session, err := services.UnmarshalWebSession(rawResponse.Session)
Expand Down Expand Up @@ -707,6 +710,8 @@ type SAMLAuthRawResponse struct {
HostSigners []json.RawMessage `json:"host_signers"`
// TLSCert is TLS certificate authority certificate
TLSCert []byte `json:"tls_cert,omitempty"`
// MFAToken is an SSO MFA token.
MFAToken string `json:"mfa_token"`
}

// ValidateSAMLResponse validates response returned by SAML identity provider
Expand All @@ -729,6 +734,7 @@ func (c *HTTPClient) ValidateSAMLResponse(ctx context.Context, samlResponse, con
Cert: rawResponse.Cert,
Req: rawResponse.Req,
TLSCert: rawResponse.TLSCert,
MFAToken: rawResponse.MFAToken,
}
if len(rawResponse.Session) != 0 {
session, err := services.UnmarshalWebSession(rawResponse.Session)
Expand Down
5 changes: 5 additions & 0 deletions lib/web/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -2184,6 +2184,8 @@ type AuthParams struct {
// FIPS mode means Teleport started in a FedRAMP/FIPS 140-2 compliant
// configuration.
FIPS bool
// MFAToken is an SSO MFA token.
MFAToken string
}

// ConstructSSHResponse creates a special SSH response for SSH login method
Expand All @@ -2198,6 +2200,7 @@ func ConstructSSHResponse(response AuthParams) (*url.URL, error) {
Cert: response.Cert,
TLSCert: response.TLSCert,
HostSigners: authclient.AuthoritiesToTrustedCerts(response.HostSigners),
MFAToken: response.MFAToken,
}
out, err := json.Marshal(consoleResponse)
if err != nil {
Expand Down Expand Up @@ -5018,6 +5021,8 @@ type SSOCallbackResponse struct {
// ClientRedirectURL is the URL to redirect back to on completion of
// the SSO login process.
ClientRedirectURL string
// MFAToken is an SSO MFA token.
MFAToken string
}

// SSOSetWebSessionAndRedirectURL validates the CSRF token in the response
Expand Down

0 comments on commit 22edf09

Please sign in to comment.