mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 22:27:35 +00:00

# 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>
193 lines
5.9 KiB
Go
193 lines
5.9 KiB
Go
package idp
|
|
|
|
import (
|
|
"github.com/zitadel/zitadel/internal/crypto"
|
|
"github.com/zitadel/zitadel/internal/domain"
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
|
"github.com/zitadel/zitadel/internal/zerrors"
|
|
)
|
|
|
|
type SAMLIDPAddedEvent struct {
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
ID string `json:"id"`
|
|
Name string `json:"name,omitempty"`
|
|
Metadata []byte `json:"metadata,omitempty"`
|
|
Key *crypto.CryptoValue `json:"key,omitempty"`
|
|
Certificate []byte `json:"certificate,omitempty"`
|
|
Binding string `json:"binding,omitempty"`
|
|
WithSignedRequest bool `json:"withSignedRequest,omitempty"`
|
|
NameIDFormat *domain.SAMLNameIDFormat `json:"nameIDFormat,omitempty"`
|
|
TransientMappingAttributeName string `json:"transientMappingAttributeName,omitempty"`
|
|
FederatedLogoutEnabled bool `json:"federatedLogoutEnabled,omitempty"`
|
|
Options
|
|
}
|
|
|
|
func NewSAMLIDPAddedEvent(
|
|
base *eventstore.BaseEvent,
|
|
id,
|
|
name string,
|
|
metadata []byte,
|
|
key *crypto.CryptoValue,
|
|
certificate []byte,
|
|
binding string,
|
|
withSignedRequest bool,
|
|
nameIDFormat *domain.SAMLNameIDFormat,
|
|
transientMappingAttributeName string,
|
|
federatedLogoutEnabled bool,
|
|
options Options,
|
|
) *SAMLIDPAddedEvent {
|
|
return &SAMLIDPAddedEvent{
|
|
BaseEvent: *base,
|
|
ID: id,
|
|
Name: name,
|
|
Metadata: metadata,
|
|
Key: key,
|
|
Certificate: certificate,
|
|
Binding: binding,
|
|
WithSignedRequest: withSignedRequest,
|
|
NameIDFormat: nameIDFormat,
|
|
TransientMappingAttributeName: transientMappingAttributeName,
|
|
FederatedLogoutEnabled: federatedLogoutEnabled,
|
|
Options: options,
|
|
}
|
|
}
|
|
|
|
func (e *SAMLIDPAddedEvent) Payload() interface{} {
|
|
return e
|
|
}
|
|
|
|
func (e *SAMLIDPAddedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
|
return nil
|
|
}
|
|
|
|
func SAMLIDPAddedEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
|
e := &SAMLIDPAddedEvent{
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
}
|
|
|
|
err := event.Unmarshal(e)
|
|
if err != nil {
|
|
return nil, zerrors.ThrowInternal(err, "IDP-v9uajo3k71", "unable to unmarshal event")
|
|
}
|
|
|
|
return e, nil
|
|
}
|
|
|
|
type SAMLIDPChangedEvent struct {
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
ID string `json:"id"`
|
|
Name *string `json:"name,omitempty"`
|
|
Metadata []byte `json:"metadata,omitempty"`
|
|
Key *crypto.CryptoValue `json:"key,omitempty"`
|
|
Certificate []byte `json:"certificate,omitempty"`
|
|
Binding *string `json:"binding,omitempty"`
|
|
WithSignedRequest *bool `json:"withSignedRequest,omitempty"`
|
|
NameIDFormat *domain.SAMLNameIDFormat `json:"nameIDFormat,omitempty"`
|
|
TransientMappingAttributeName *string `json:"transientMappingAttributeName,omitempty"`
|
|
FederatedLogoutEnabled *bool `json:"federatedLogoutEnabled,omitempty"`
|
|
OptionChanges
|
|
}
|
|
|
|
func NewSAMLIDPChangedEvent(
|
|
base *eventstore.BaseEvent,
|
|
id string,
|
|
changes []SAMLIDPChanges,
|
|
) (*SAMLIDPChangedEvent, error) {
|
|
if len(changes) == 0 {
|
|
return nil, zerrors.ThrowPreconditionFailed(nil, "IDP-cz6mnf860t", "Errors.NoChangesFound")
|
|
}
|
|
changedEvent := &SAMLIDPChangedEvent{
|
|
BaseEvent: *base,
|
|
ID: id,
|
|
}
|
|
for _, change := range changes {
|
|
change(changedEvent)
|
|
}
|
|
return changedEvent, nil
|
|
}
|
|
|
|
type SAMLIDPChanges func(*SAMLIDPChangedEvent)
|
|
|
|
func ChangeSAMLName(name string) func(*SAMLIDPChangedEvent) {
|
|
return func(e *SAMLIDPChangedEvent) {
|
|
e.Name = &name
|
|
}
|
|
}
|
|
|
|
func ChangeSAMLMetadata(metadata []byte) func(*SAMLIDPChangedEvent) {
|
|
return func(e *SAMLIDPChangedEvent) {
|
|
e.Metadata = metadata
|
|
}
|
|
}
|
|
|
|
func ChangeSAMLKey(key *crypto.CryptoValue) func(*SAMLIDPChangedEvent) {
|
|
return func(e *SAMLIDPChangedEvent) {
|
|
e.Key = key
|
|
}
|
|
}
|
|
|
|
func ChangeSAMLCertificate(certificate []byte) func(*SAMLIDPChangedEvent) {
|
|
return func(e *SAMLIDPChangedEvent) {
|
|
e.Certificate = certificate
|
|
}
|
|
}
|
|
|
|
func ChangeSAMLBinding(binding string) func(*SAMLIDPChangedEvent) {
|
|
return func(e *SAMLIDPChangedEvent) {
|
|
e.Binding = &binding
|
|
}
|
|
}
|
|
|
|
func ChangeSAMLWithSignedRequest(withSignedRequest bool) func(*SAMLIDPChangedEvent) {
|
|
return func(e *SAMLIDPChangedEvent) {
|
|
e.WithSignedRequest = &withSignedRequest
|
|
}
|
|
}
|
|
|
|
func ChangeSAMLNameIDFormat(nameIDFormat *domain.SAMLNameIDFormat) func(*SAMLIDPChangedEvent) {
|
|
return func(e *SAMLIDPChangedEvent) {
|
|
e.NameIDFormat = nameIDFormat
|
|
}
|
|
}
|
|
|
|
func ChangeSAMLTransientMappingAttributeName(name string) func(*SAMLIDPChangedEvent) {
|
|
return func(e *SAMLIDPChangedEvent) {
|
|
e.TransientMappingAttributeName = &name
|
|
}
|
|
}
|
|
|
|
func ChangeSAMLFederatedLogoutEnabled(federatedLogoutEnabled bool) func(*SAMLIDPChangedEvent) {
|
|
return func(e *SAMLIDPChangedEvent) {
|
|
e.FederatedLogoutEnabled = &federatedLogoutEnabled
|
|
}
|
|
}
|
|
|
|
func ChangeSAMLOptions(options OptionChanges) func(*SAMLIDPChangedEvent) {
|
|
return func(e *SAMLIDPChangedEvent) {
|
|
e.OptionChanges = options
|
|
}
|
|
}
|
|
|
|
func (e *SAMLIDPChangedEvent) Payload() interface{} {
|
|
return e
|
|
}
|
|
|
|
func (e *SAMLIDPChangedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
|
return nil
|
|
}
|
|
|
|
func SAMLIDPChangedEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
|
e := &SAMLIDPChangedEvent{
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
}
|
|
|
|
err := event.Unmarshal(e)
|
|
if err != nil {
|
|
return nil, zerrors.ThrowInternal(err, "IDP-w1t1824tw5", "unable to unmarshal event")
|
|
}
|
|
|
|
return e, nil
|
|
}
|