2023-02-15 09:14:59 +01:00
|
|
|
package command
|
|
|
|
|
2023-02-28 21:20:58 +01:00
|
|
|
import (
|
|
|
|
"context"
|
2023-03-24 16:18:56 +01:00
|
|
|
"time"
|
2023-02-28 21:20:58 +01:00
|
|
|
|
|
|
|
"github.com/zitadel/zitadel/internal/command/preparation"
|
2024-05-23 07:04:07 +02:00
|
|
|
"github.com/zitadel/zitadel/internal/domain"
|
2023-02-28 21:20:58 +01:00
|
|
|
"github.com/zitadel/zitadel/internal/repository/idp"
|
2024-06-19 13:56:33 +03:00
|
|
|
"github.com/zitadel/zitadel/internal/telemetry/tracing"
|
2023-12-08 16:30:55 +02:00
|
|
|
"github.com/zitadel/zitadel/internal/zerrors"
|
2023-02-28 21:20:58 +01:00
|
|
|
)
|
2023-02-15 09:14:59 +01:00
|
|
|
|
2023-02-24 15:16:06 +01:00
|
|
|
type GenericOAuthProvider struct {
|
|
|
|
Name string
|
|
|
|
ClientID string
|
|
|
|
ClientSecret string
|
|
|
|
AuthorizationEndpoint string
|
|
|
|
TokenEndpoint string
|
|
|
|
UserEndpoint string
|
|
|
|
Scopes []string
|
2023-03-03 11:38:49 +01:00
|
|
|
IDAttribute string
|
2025-02-26 13:20:47 +01:00
|
|
|
UsePKCE bool
|
2023-02-24 15:16:06 +01:00
|
|
|
IDPOptions idp.Options
|
|
|
|
}
|
|
|
|
|
2023-02-27 16:32:18 +01:00
|
|
|
type GenericOIDCProvider struct {
|
2023-03-16 16:47:22 +01:00
|
|
|
Name string
|
|
|
|
Issuer string
|
|
|
|
ClientID string
|
|
|
|
ClientSecret string
|
|
|
|
Scopes []string
|
|
|
|
IsIDTokenMapping bool
|
2025-02-26 13:20:47 +01:00
|
|
|
UsePKCE bool
|
2023-03-16 16:47:22 +01:00
|
|
|
IDPOptions idp.Options
|
2023-02-27 16:32:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type JWTProvider struct {
|
|
|
|
Name string
|
|
|
|
Issuer string
|
|
|
|
JWTEndpoint string
|
|
|
|
KeyEndpoint string
|
|
|
|
HeaderName string
|
|
|
|
IDPOptions idp.Options
|
|
|
|
}
|
|
|
|
|
2023-03-15 07:48:37 +01:00
|
|
|
type AzureADProvider struct {
|
|
|
|
Name string
|
|
|
|
ClientID string
|
|
|
|
ClientSecret string
|
|
|
|
Scopes []string
|
|
|
|
Tenant string
|
|
|
|
EmailVerified bool
|
|
|
|
IDPOptions idp.Options
|
|
|
|
}
|
|
|
|
|
2023-03-08 11:17:28 +01:00
|
|
|
type GitHubProvider struct {
|
|
|
|
Name string
|
|
|
|
ClientID string
|
|
|
|
ClientSecret string
|
|
|
|
Scopes []string
|
|
|
|
IDPOptions idp.Options
|
|
|
|
}
|
|
|
|
|
|
|
|
type GitHubEnterpriseProvider struct {
|
|
|
|
Name string
|
|
|
|
ClientID string
|
|
|
|
ClientSecret string
|
|
|
|
AuthorizationEndpoint string
|
|
|
|
TokenEndpoint string
|
|
|
|
UserEndpoint string
|
|
|
|
Scopes []string
|
|
|
|
IDPOptions idp.Options
|
|
|
|
}
|
|
|
|
|
2023-03-13 17:34:29 +01:00
|
|
|
type GitLabProvider struct {
|
|
|
|
Name string
|
|
|
|
ClientID string
|
|
|
|
ClientSecret string
|
|
|
|
Scopes []string
|
|
|
|
IDPOptions idp.Options
|
|
|
|
}
|
|
|
|
|
|
|
|
type GitLabSelfHostedProvider struct {
|
|
|
|
Name string
|
|
|
|
Issuer string
|
|
|
|
ClientID string
|
|
|
|
ClientSecret string
|
|
|
|
Scopes []string
|
|
|
|
IDPOptions idp.Options
|
|
|
|
}
|
|
|
|
|
2023-02-21 18:18:28 +01:00
|
|
|
type GoogleProvider struct {
|
|
|
|
Name string
|
|
|
|
ClientID string
|
|
|
|
ClientSecret string
|
|
|
|
Scopes []string
|
|
|
|
IDPOptions idp.Options
|
|
|
|
}
|
|
|
|
|
2023-02-15 09:14:59 +01:00
|
|
|
type LDAPProvider struct {
|
2023-03-24 16:18:56 +01:00
|
|
|
Name string
|
|
|
|
Servers []string
|
|
|
|
StartTLS bool
|
|
|
|
BaseDN string
|
|
|
|
BindDN string
|
|
|
|
BindPassword string
|
|
|
|
UserBase string
|
|
|
|
UserObjectClasses []string
|
|
|
|
UserFilters []string
|
|
|
|
Timeout time.Duration
|
2025-02-18 10:06:50 +00:00
|
|
|
RootCA []byte
|
2023-03-24 16:18:56 +01:00
|
|
|
LDAPAttributes idp.LDAPAttributes
|
|
|
|
IDPOptions idp.Options
|
2023-02-15 09:14:59 +01:00
|
|
|
}
|
2023-02-28 21:20:58 +01:00
|
|
|
|
2023-09-29 11:26:14 +02:00
|
|
|
type SAMLProvider struct {
|
2024-05-23 07:04:07 +02:00
|
|
|
Name string
|
|
|
|
Metadata []byte
|
|
|
|
MetadataURL string
|
|
|
|
Binding string
|
|
|
|
WithSignedRequest bool
|
|
|
|
NameIDFormat *domain.SAMLNameIDFormat
|
|
|
|
TransientMappingAttributeName string
|
feat: federated logout for SAML IdPs (#9931)
# Which Problems Are Solved
Currently if a user signs in using an IdP, once they sign out of
Zitadel, the corresponding IdP session is not terminated. This can be
the desired behavior. In some cases, e.g. when using a shared computer
it results in a potential security risk, since a follower user might be
able to sign in as the previous using the still open IdP session.
# How the Problems Are Solved
- Admins can enabled a federated logout option on SAML IdPs through the
Admin and Management APIs.
- During the termination of a login V1 session using OIDC end_session
endpoint, Zitadel will check if an IdP was used to authenticate that
session.
- In case there was a SAML IdP used with Federated Logout enabled, it
will intercept the logout process, store the information into the shared
cache and redirect to the federated logout endpoint in the V1 login.
- The V1 login federated logout endpoint checks every request on an
existing cache entry. On success it will create a SAML logout request
for the used IdP and either redirect or POST to the configured SLO
endpoint. The cache entry is updated with a `redirected` state.
- A SLO endpoint is added to the `/idp` handlers, which will handle the
SAML logout responses. At the moment it will check again for an existing
federated logout entry (with state `redirected`) in the cache. On
success, the user is redirected to the initially provided
`post_logout_redirect_uri` from the end_session request.
# Additional Changes
None
# Additional Context
- This PR merges the https://github.com/zitadel/zitadel/pull/9841 and
https://github.com/zitadel/zitadel/pull/9854 to main, additionally
updating the docs on Entra ID SAML.
- closes #9228
- backport to 3.x
---------
Co-authored-by: Silvan <27845747+adlerhurst@users.noreply.github.com>
Co-authored-by: Zach Hirschtritt <zachary.hirschtritt@klaviyo.com>
(cherry picked from commit 2cf3ef4de4ef993367daec6ff3974bdbdf70d2f3)
2025-05-23 13:52:25 +02:00
|
|
|
FederatedLogoutEnabled bool
|
2024-05-23 07:04:07 +02:00
|
|
|
IDPOptions idp.Options
|
2023-09-29 11:26:14 +02:00
|
|
|
}
|
|
|
|
|
2023-08-31 08:39:16 +02:00
|
|
|
type AppleProvider struct {
|
|
|
|
Name string
|
|
|
|
ClientID string
|
|
|
|
TeamID string
|
|
|
|
KeyID string
|
|
|
|
PrivateKey []byte
|
|
|
|
Scopes []string
|
|
|
|
IDPOptions idp.Options
|
|
|
|
}
|
|
|
|
|
2024-05-07 08:11:20 +02:00
|
|
|
// ExistsIDPOnOrgOrInstance query first org level IDPs and then instance level IDPs, no check if the IDP is active
|
|
|
|
func ExistsIDPOnOrgOrInstance(ctx context.Context, filter preparation.FilterToQueryReducer, instanceID, orgID, id string) (exists bool, err error) {
|
2024-06-19 13:56:33 +03:00
|
|
|
ctx, span := tracing.NewSpan(ctx)
|
|
|
|
defer func() { span.EndWithError(err) }()
|
|
|
|
|
2023-02-28 21:20:58 +01:00
|
|
|
writeModel := NewOrgIDPRemoveWriteModel(orgID, id)
|
|
|
|
events, err := filter(ctx, writeModel.Query())
|
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(events) > 0 {
|
|
|
|
writeModel.AppendEvents(events...)
|
|
|
|
if err := writeModel.Reduce(); err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
return writeModel.State.Exists(), nil
|
|
|
|
}
|
|
|
|
|
2024-05-07 08:11:20 +02:00
|
|
|
instanceWriteModel := NewInstanceIDPRemoveWriteModel(instanceID, id)
|
2023-02-28 21:20:58 +01:00
|
|
|
events, err = filter(ctx, instanceWriteModel.Query())
|
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(events) == 0 {
|
|
|
|
return false, nil
|
|
|
|
}
|
|
|
|
instanceWriteModel.AppendEvents(events...)
|
|
|
|
if err := instanceWriteModel.Reduce(); err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
return instanceWriteModel.State.Exists(), nil
|
|
|
|
}
|
2023-05-24 20:29:58 +02:00
|
|
|
|
2024-05-07 08:11:20 +02:00
|
|
|
// ExistsIDP query IDPs only with the ID, no check if the IDP is active
|
|
|
|
func ExistsIDP(ctx context.Context, filter preparation.FilterToQueryReducer, id string) (exists bool, err error) {
|
|
|
|
writeModel := NewIDPTypeWriteModel(id)
|
|
|
|
events, err := filter(ctx, writeModel.Query())
|
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
if len(events) == 0 {
|
|
|
|
return false, nil
|
|
|
|
}
|
|
|
|
writeModel.AppendEvents(events...)
|
|
|
|
if err := writeModel.Reduce(); err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
return writeModel.State.Exists(), nil
|
|
|
|
}
|
|
|
|
|
2023-05-24 20:29:58 +02:00
|
|
|
func IDPProviderWriteModel(ctx context.Context, filter preparation.FilterToQueryReducer, id string) (_ *AllIDPWriteModel, err error) {
|
|
|
|
writeModel := NewIDPTypeWriteModel(id)
|
|
|
|
events, err := filter(ctx, writeModel.Query())
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if len(events) == 0 {
|
2023-12-08 16:30:55 +02:00
|
|
|
return nil, zerrors.ThrowPreconditionFailed(nil, "COMMAND-as02jin", "Errors.IDPConfig.NotExisting")
|
2023-05-24 20:29:58 +02:00
|
|
|
}
|
|
|
|
writeModel.AppendEvents(events...)
|
|
|
|
if err := writeModel.Reduce(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
allWriteModel, err := NewAllIDPWriteModel(
|
|
|
|
writeModel.ResourceOwner,
|
|
|
|
writeModel.ResourceOwner == writeModel.InstanceID,
|
|
|
|
writeModel.ID,
|
|
|
|
writeModel.Type,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
events, err = filter(ctx, allWriteModel.Query())
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
allWriteModel.AppendEvents(events...)
|
|
|
|
if err := allWriteModel.Reduce(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return allWriteModel, err
|
|
|
|
}
|