2023-05-05 15:34:53 +00:00
|
|
|
package session
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
|
|
|
|
2024-05-16 05:07:56 +00:00
|
|
|
"golang.org/x/text/language"
|
|
|
|
|
2023-10-10 13:20:53 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/api/http"
|
2023-08-24 09:41:52 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/crypto"
|
2023-06-07 15:28:42 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/domain"
|
2023-05-05 15:34:53 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
2023-12-08 14:30:55 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/zerrors"
|
2023-05-05 15:34:53 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2023-08-11 15:36:18 +00:00
|
|
|
sessionEventPrefix = "session."
|
|
|
|
AddedType = sessionEventPrefix + "added"
|
|
|
|
UserCheckedType = sessionEventPrefix + "user.checked"
|
|
|
|
PasswordCheckedType = sessionEventPrefix + "password.checked"
|
|
|
|
IntentCheckedType = sessionEventPrefix + "intent.checked"
|
|
|
|
WebAuthNChallengedType = sessionEventPrefix + "webAuthN.challenged"
|
|
|
|
WebAuthNCheckedType = sessionEventPrefix + "webAuthN.checked"
|
2023-08-15 09:50:42 +00:00
|
|
|
TOTPCheckedType = sessionEventPrefix + "totp.checked"
|
2023-08-24 09:41:52 +00:00
|
|
|
OTPSMSChallengedType = sessionEventPrefix + "otp.sms.challenged"
|
|
|
|
OTPSMSSentType = sessionEventPrefix + "otp.sms.sent"
|
|
|
|
OTPSMSCheckedType = sessionEventPrefix + "otp.sms.checked"
|
|
|
|
OTPEmailChallengedType = sessionEventPrefix + "otp.email.challenged"
|
|
|
|
OTPEmailSentType = sessionEventPrefix + "otp.email.sent"
|
|
|
|
OTPEmailCheckedType = sessionEventPrefix + "otp.email.checked"
|
2023-08-11 15:36:18 +00:00
|
|
|
TokenSetType = sessionEventPrefix + "token.set"
|
|
|
|
MetadataSetType = sessionEventPrefix + "metadata.set"
|
2023-11-06 09:48:28 +00:00
|
|
|
LifetimeSetType = sessionEventPrefix + "lifetime.set"
|
2023-08-11 15:36:18 +00:00
|
|
|
TerminateType = sessionEventPrefix + "terminated"
|
2023-05-05 15:34:53 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type AddedEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
2023-10-19 10:34:00 +00:00
|
|
|
UserAgent *domain.UserAgent `json:"user_agent,omitempty"`
|
2023-05-05 15:34:53 +00:00
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *AddedEvent) Payload() interface{} {
|
2023-05-05 15:34:53 +00:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *AddedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2023-05-05 15:34:53 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewAddedEvent(ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
2023-10-19 10:34:00 +00:00
|
|
|
userAgent *domain.UserAgent,
|
2023-05-05 15:34:53 +00:00
|
|
|
) *AddedEvent {
|
|
|
|
return &AddedEvent{
|
|
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
AddedType,
|
|
|
|
),
|
2023-10-19 10:34:00 +00:00
|
|
|
UserAgent: userAgent,
|
2023-05-05 15:34:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func AddedEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
2023-05-05 15:34:53 +00:00
|
|
|
added := &AddedEvent{
|
|
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
|
|
}
|
2023-10-19 10:19:10 +00:00
|
|
|
|
|
|
|
err := event.Unmarshal(added)
|
2023-05-05 15:34:53 +00:00
|
|
|
if err != nil {
|
2023-12-08 14:30:55 +00:00
|
|
|
return nil, zerrors.ThrowInternal(err, "SESSION-DG4gn", "unable to unmarshal session added")
|
2023-05-05 15:34:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return added, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type UserCheckedEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
|
2024-05-16 05:07:56 +00:00
|
|
|
UserID string `json:"userID"`
|
|
|
|
UserResourceOwner string `json:"userResourceOwner"`
|
|
|
|
CheckedAt time.Time `json:"checkedAt"`
|
|
|
|
PreferredLanguage *language.Tag `json:"preferredLanguage,omitempty"`
|
2023-05-05 15:34:53 +00:00
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *UserCheckedEvent) Payload() interface{} {
|
2023-05-05 15:34:53 +00:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *UserCheckedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2023-05-05 15:34:53 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewUserCheckedEvent(
|
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
2023-11-16 06:35:50 +00:00
|
|
|
userID,
|
|
|
|
userResourceOwner string,
|
2023-05-05 15:34:53 +00:00
|
|
|
checkedAt time.Time,
|
2024-05-16 05:07:56 +00:00
|
|
|
preferredLanguage *language.Tag,
|
2023-05-05 15:34:53 +00:00
|
|
|
) *UserCheckedEvent {
|
|
|
|
return &UserCheckedEvent{
|
|
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
UserCheckedType,
|
|
|
|
),
|
2023-11-16 06:35:50 +00:00
|
|
|
UserID: userID,
|
|
|
|
UserResourceOwner: userResourceOwner,
|
|
|
|
CheckedAt: checkedAt,
|
2024-05-16 05:07:56 +00:00
|
|
|
PreferredLanguage: preferredLanguage,
|
2023-05-05 15:34:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func UserCheckedEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
2023-05-05 15:34:53 +00:00
|
|
|
added := &UserCheckedEvent{
|
|
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
|
|
}
|
2023-10-19 10:19:10 +00:00
|
|
|
err := event.Unmarshal(added)
|
2023-05-05 15:34:53 +00:00
|
|
|
if err != nil {
|
2023-12-08 14:30:55 +00:00
|
|
|
return nil, zerrors.ThrowInternal(err, "SESSION-DSGn5", "unable to unmarshal user checked")
|
2023-05-05 15:34:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return added, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type PasswordCheckedEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
|
|
|
|
CheckedAt time.Time `json:"checkedAt"`
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *PasswordCheckedEvent) Payload() interface{} {
|
2023-05-05 15:34:53 +00:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *PasswordCheckedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2023-05-05 15:34:53 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewPasswordCheckedEvent(
|
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
|
|
|
checkedAt time.Time,
|
|
|
|
) *PasswordCheckedEvent {
|
|
|
|
return &PasswordCheckedEvent{
|
|
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
PasswordCheckedType,
|
|
|
|
),
|
|
|
|
CheckedAt: checkedAt,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func PasswordCheckedEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
2023-05-05 15:34:53 +00:00
|
|
|
added := &PasswordCheckedEvent{
|
|
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
|
|
}
|
2023-10-19 10:19:10 +00:00
|
|
|
err := event.Unmarshal(added)
|
2023-05-05 15:34:53 +00:00
|
|
|
if err != nil {
|
2023-12-08 14:30:55 +00:00
|
|
|
return nil, zerrors.ThrowInternal(err, "SESSION-DGt21", "unable to unmarshal password checked")
|
2023-05-05 15:34:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return added, nil
|
|
|
|
}
|
|
|
|
|
2023-06-21 14:06:18 +00:00
|
|
|
type IntentCheckedEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
|
|
|
|
CheckedAt time.Time `json:"checkedAt"`
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *IntentCheckedEvent) Payload() interface{} {
|
2023-06-21 14:06:18 +00:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *IntentCheckedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2023-06-21 14:06:18 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewIntentCheckedEvent(
|
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
|
|
|
checkedAt time.Time,
|
|
|
|
) *IntentCheckedEvent {
|
|
|
|
return &IntentCheckedEvent{
|
|
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
IntentCheckedType,
|
|
|
|
),
|
|
|
|
CheckedAt: checkedAt,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func IntentCheckedEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
2023-06-21 14:06:18 +00:00
|
|
|
added := &IntentCheckedEvent{
|
|
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
|
|
}
|
2023-10-19 10:19:10 +00:00
|
|
|
err := event.Unmarshal(added)
|
2023-06-21 14:06:18 +00:00
|
|
|
if err != nil {
|
2023-12-08 14:30:55 +00:00
|
|
|
return nil, zerrors.ThrowInternal(err, "SESSION-DGt90", "unable to unmarshal intent checked")
|
2023-06-21 14:06:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return added, nil
|
|
|
|
}
|
|
|
|
|
2023-08-11 15:36:18 +00:00
|
|
|
type WebAuthNChallengedEvent struct {
|
2023-06-07 15:28:42 +00:00
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
|
|
|
|
Challenge string `json:"challenge,omitempty"`
|
|
|
|
AllowedCrentialIDs [][]byte `json:"allowedCrentialIDs,omitempty"`
|
|
|
|
UserVerification domain.UserVerificationRequirement `json:"userVerification,omitempty"`
|
2023-08-11 15:36:18 +00:00
|
|
|
RPID string `json:"rpid,omitempty"`
|
2023-06-07 15:28:42 +00:00
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *WebAuthNChallengedEvent) Payload() interface{} {
|
2023-06-07 15:28:42 +00:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *WebAuthNChallengedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2023-06-07 15:28:42 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-08-11 15:36:18 +00:00
|
|
|
func (e *WebAuthNChallengedEvent) SetBaseEvent(base *eventstore.BaseEvent) {
|
2023-06-07 15:28:42 +00:00
|
|
|
e.BaseEvent = *base
|
|
|
|
}
|
|
|
|
|
2023-08-11 15:36:18 +00:00
|
|
|
func NewWebAuthNChallengedEvent(
|
2023-06-07 15:28:42 +00:00
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
|
|
|
challenge string,
|
|
|
|
allowedCrentialIDs [][]byte,
|
|
|
|
userVerification domain.UserVerificationRequirement,
|
2023-08-11 15:36:18 +00:00
|
|
|
rpid string,
|
|
|
|
) *WebAuthNChallengedEvent {
|
|
|
|
return &WebAuthNChallengedEvent{
|
2023-06-07 15:28:42 +00:00
|
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
2023-08-11 15:36:18 +00:00
|
|
|
WebAuthNChallengedType,
|
2023-06-07 15:28:42 +00:00
|
|
|
),
|
|
|
|
Challenge: challenge,
|
|
|
|
AllowedCrentialIDs: allowedCrentialIDs,
|
|
|
|
UserVerification: userVerification,
|
2023-08-11 15:36:18 +00:00
|
|
|
RPID: rpid,
|
2023-06-07 15:28:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-11 15:36:18 +00:00
|
|
|
type WebAuthNCheckedEvent struct {
|
2023-06-07 15:28:42 +00:00
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
|
2023-08-11 15:36:18 +00:00
|
|
|
CheckedAt time.Time `json:"checkedAt"`
|
|
|
|
UserVerified bool `json:"userVerified,omitempty"`
|
2023-06-07 15:28:42 +00:00
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *WebAuthNCheckedEvent) Payload() interface{} {
|
2023-06-07 15:28:42 +00:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *WebAuthNCheckedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2023-06-07 15:28:42 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-08-11 15:36:18 +00:00
|
|
|
func (e *WebAuthNCheckedEvent) SetBaseEvent(base *eventstore.BaseEvent) {
|
2023-06-07 15:28:42 +00:00
|
|
|
e.BaseEvent = *base
|
|
|
|
}
|
|
|
|
|
2023-08-11 15:36:18 +00:00
|
|
|
func NewWebAuthNCheckedEvent(
|
2023-06-07 15:28:42 +00:00
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
|
|
|
checkedAt time.Time,
|
2023-08-11 15:36:18 +00:00
|
|
|
userVerified bool,
|
|
|
|
) *WebAuthNCheckedEvent {
|
|
|
|
return &WebAuthNCheckedEvent{
|
2023-06-07 15:28:42 +00:00
|
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
2023-08-11 15:36:18 +00:00
|
|
|
WebAuthNCheckedType,
|
2023-06-07 15:28:42 +00:00
|
|
|
),
|
2023-08-11 15:36:18 +00:00
|
|
|
CheckedAt: checkedAt,
|
|
|
|
UserVerified: userVerified,
|
2023-06-07 15:28:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-15 09:50:42 +00:00
|
|
|
type TOTPCheckedEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
|
|
|
|
CheckedAt time.Time `json:"checkedAt"`
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *TOTPCheckedEvent) Payload() interface{} {
|
2023-08-15 09:50:42 +00:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *TOTPCheckedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2023-08-15 09:50:42 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *TOTPCheckedEvent) SetBaseEvent(base *eventstore.BaseEvent) {
|
|
|
|
e.BaseEvent = *base
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewTOTPCheckedEvent(
|
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
|
|
|
checkedAt time.Time,
|
|
|
|
) *TOTPCheckedEvent {
|
|
|
|
return &TOTPCheckedEvent{
|
|
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
TOTPCheckedType,
|
|
|
|
),
|
|
|
|
CheckedAt: checkedAt,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-24 09:41:52 +00:00
|
|
|
type OTPSMSChallengedEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
|
2023-10-13 14:45:38 +00:00
|
|
|
Code *crypto.CryptoValue `json:"code"`
|
|
|
|
Expiry time.Duration `json:"expiry"`
|
|
|
|
CodeReturned bool `json:"codeReturned,omitempty"`
|
|
|
|
TriggeredAtOrigin string `json:"triggerOrigin,omitempty"`
|
2023-08-24 09:41:52 +00:00
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *OTPSMSChallengedEvent) Payload() interface{} {
|
2023-08-24 09:41:52 +00:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *OTPSMSChallengedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2023-08-24 09:41:52 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *OTPSMSChallengedEvent) SetBaseEvent(base *eventstore.BaseEvent) {
|
|
|
|
e.BaseEvent = *base
|
|
|
|
}
|
|
|
|
|
2023-10-13 14:45:38 +00:00
|
|
|
func (e *OTPSMSChallengedEvent) TriggerOrigin() string {
|
|
|
|
return e.TriggeredAtOrigin
|
|
|
|
}
|
|
|
|
|
2023-08-24 09:41:52 +00:00
|
|
|
func NewOTPSMSChallengedEvent(
|
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
|
|
|
code *crypto.CryptoValue,
|
|
|
|
expiry time.Duration,
|
|
|
|
codeReturned bool,
|
|
|
|
) *OTPSMSChallengedEvent {
|
|
|
|
return &OTPSMSChallengedEvent{
|
|
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
OTPSMSChallengedType,
|
|
|
|
),
|
2023-10-13 14:45:38 +00:00
|
|
|
Code: code,
|
|
|
|
Expiry: expiry,
|
|
|
|
CodeReturned: codeReturned,
|
feat: trusted (instance) domains (#8369)
# Which Problems Are Solved
ZITADEL currently selects the instance context based on a HTTP header
(see https://github.com/zitadel/zitadel/issues/8279#issue-2399959845 and
checks it against the list of instance domains. Let's call it instance
or API domain.
For any context based URL (e.g. OAuth, OIDC, SAML endpoints, links in
emails, ...) the requested domain (instance domain) will be used. Let's
call it the public domain.
In cases of proxied setups, all exposed domains (public domains) require
the domain to be managed as instance domain.
This can either be done using the "ExternalDomain" in the runtime config
or via system API, which requires a validation through CustomerPortal on
zitadel.cloud.
# How the Problems Are Solved
- Two new headers / header list are added:
- `InstanceHostHeaders`: an ordered list (first sent wins), which will
be used to match the instance.
(For backward compatibility: the `HTTP1HostHeader`, `HTTP2HostHeader`
and `forwarded`, `x-forwarded-for`, `x-forwarded-host` are checked
afterwards as well)
- `PublicHostHeaders`: an ordered list (first sent wins), which will be
used as public host / domain. This will be checked against a list of
trusted domains on the instance.
- The middleware intercepts all requests to the API and passes a
`DomainCtx` object with the hosts and protocol into the context
(previously only a computed `origin` was passed)
- HTTP / GRPC server do not longer try to match the headers to instances
themself, but use the passed `http.DomainContext` in their interceptors.
- The `RequestedHost` and `RequestedDomain` from authz.Instance are
removed in favor of the `http.DomainContext`
- When authenticating to or signing out from Console UI, the current
`http.DomainContext(ctx).Origin` (already checked by instance
interceptor for validity) is used to compute and dynamically add a
`redirect_uri` and `post_logout_redirect_uri`.
- Gateway passes all configured host headers (previously only did
`x-zitadel-*`)
- Admin API allows to manage trusted domain
# Additional Changes
None
# Additional Context
- part of #8279
- open topics:
- "single-instance" mode
- Console UI
2024-07-31 15:00:38 +00:00
|
|
|
TriggeredAtOrigin: http.DomainContext(ctx).Origin(),
|
2023-08-24 09:41:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type OTPSMSSentEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *OTPSMSSentEvent) Payload() interface{} {
|
2023-08-24 09:41:52 +00:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *OTPSMSSentEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2023-08-24 09:41:52 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *OTPSMSSentEvent) SetBaseEvent(base *eventstore.BaseEvent) {
|
|
|
|
e.BaseEvent = *base
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewOTPSMSSentEvent(
|
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
|
|
|
) *OTPSMSSentEvent {
|
|
|
|
return &OTPSMSSentEvent{
|
|
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
OTPSMSSentType,
|
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type OTPSMSCheckedEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
|
|
|
|
CheckedAt time.Time `json:"checkedAt"`
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *OTPSMSCheckedEvent) Payload() interface{} {
|
2023-08-24 09:41:52 +00:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *OTPSMSCheckedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2023-08-24 09:41:52 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *OTPSMSCheckedEvent) SetBaseEvent(base *eventstore.BaseEvent) {
|
|
|
|
e.BaseEvent = *base
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewOTPSMSCheckedEvent(
|
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
|
|
|
checkedAt time.Time,
|
|
|
|
) *OTPSMSCheckedEvent {
|
|
|
|
return &OTPSMSCheckedEvent{
|
|
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
OTPSMSCheckedType,
|
|
|
|
),
|
|
|
|
CheckedAt: checkedAt,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type OTPEmailChallengedEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
|
2023-10-10 13:20:53 +00:00
|
|
|
Code *crypto.CryptoValue `json:"code"`
|
|
|
|
Expiry time.Duration `json:"expiry"`
|
|
|
|
ReturnCode bool `json:"returnCode,omitempty"`
|
|
|
|
URLTmpl string `json:"urlTmpl,omitempty"`
|
|
|
|
TriggeredAtOrigin string `json:"triggerOrigin,omitempty"`
|
2023-08-24 09:41:52 +00:00
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *OTPEmailChallengedEvent) Payload() interface{} {
|
2023-08-24 09:41:52 +00:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *OTPEmailChallengedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2023-08-24 09:41:52 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *OTPEmailChallengedEvent) SetBaseEvent(base *eventstore.BaseEvent) {
|
|
|
|
e.BaseEvent = *base
|
|
|
|
}
|
|
|
|
|
2023-10-10 13:20:53 +00:00
|
|
|
func (e *OTPEmailChallengedEvent) TriggerOrigin() string {
|
|
|
|
return e.TriggeredAtOrigin
|
|
|
|
}
|
|
|
|
|
2023-08-24 09:41:52 +00:00
|
|
|
func NewOTPEmailChallengedEvent(
|
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
|
|
|
code *crypto.CryptoValue,
|
|
|
|
expiry time.Duration,
|
|
|
|
returnCode bool,
|
|
|
|
urlTmpl string,
|
|
|
|
) *OTPEmailChallengedEvent {
|
|
|
|
return &OTPEmailChallengedEvent{
|
|
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
OTPEmailChallengedType,
|
|
|
|
),
|
2023-10-10 13:20:53 +00:00
|
|
|
Code: code,
|
|
|
|
Expiry: expiry,
|
|
|
|
ReturnCode: returnCode,
|
|
|
|
URLTmpl: urlTmpl,
|
feat: trusted (instance) domains (#8369)
# Which Problems Are Solved
ZITADEL currently selects the instance context based on a HTTP header
(see https://github.com/zitadel/zitadel/issues/8279#issue-2399959845 and
checks it against the list of instance domains. Let's call it instance
or API domain.
For any context based URL (e.g. OAuth, OIDC, SAML endpoints, links in
emails, ...) the requested domain (instance domain) will be used. Let's
call it the public domain.
In cases of proxied setups, all exposed domains (public domains) require
the domain to be managed as instance domain.
This can either be done using the "ExternalDomain" in the runtime config
or via system API, which requires a validation through CustomerPortal on
zitadel.cloud.
# How the Problems Are Solved
- Two new headers / header list are added:
- `InstanceHostHeaders`: an ordered list (first sent wins), which will
be used to match the instance.
(For backward compatibility: the `HTTP1HostHeader`, `HTTP2HostHeader`
and `forwarded`, `x-forwarded-for`, `x-forwarded-host` are checked
afterwards as well)
- `PublicHostHeaders`: an ordered list (first sent wins), which will be
used as public host / domain. This will be checked against a list of
trusted domains on the instance.
- The middleware intercepts all requests to the API and passes a
`DomainCtx` object with the hosts and protocol into the context
(previously only a computed `origin` was passed)
- HTTP / GRPC server do not longer try to match the headers to instances
themself, but use the passed `http.DomainContext` in their interceptors.
- The `RequestedHost` and `RequestedDomain` from authz.Instance are
removed in favor of the `http.DomainContext`
- When authenticating to or signing out from Console UI, the current
`http.DomainContext(ctx).Origin` (already checked by instance
interceptor for validity) is used to compute and dynamically add a
`redirect_uri` and `post_logout_redirect_uri`.
- Gateway passes all configured host headers (previously only did
`x-zitadel-*`)
- Admin API allows to manage trusted domain
# Additional Changes
None
# Additional Context
- part of #8279
- open topics:
- "single-instance" mode
- Console UI
2024-07-31 15:00:38 +00:00
|
|
|
TriggeredAtOrigin: http.DomainContext(ctx).Origin(),
|
2023-08-24 09:41:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type OTPEmailSentEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *OTPEmailSentEvent) Payload() interface{} {
|
2023-08-24 09:41:52 +00:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *OTPEmailSentEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2023-08-24 09:41:52 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *OTPEmailSentEvent) SetBaseEvent(base *eventstore.BaseEvent) {
|
|
|
|
e.BaseEvent = *base
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewOTPEmailSentEvent(
|
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
|
|
|
) *OTPEmailSentEvent {
|
|
|
|
return &OTPEmailSentEvent{
|
|
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
OTPEmailSentType,
|
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type OTPEmailCheckedEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
|
|
|
|
CheckedAt time.Time `json:"checkedAt"`
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *OTPEmailCheckedEvent) Payload() interface{} {
|
2023-08-24 09:41:52 +00:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *OTPEmailCheckedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2023-08-24 09:41:52 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *OTPEmailCheckedEvent) SetBaseEvent(base *eventstore.BaseEvent) {
|
|
|
|
e.BaseEvent = *base
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewOTPEmailCheckedEvent(
|
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
|
|
|
checkedAt time.Time,
|
|
|
|
) *OTPEmailCheckedEvent {
|
|
|
|
return &OTPEmailCheckedEvent{
|
|
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
OTPEmailCheckedType,
|
|
|
|
),
|
|
|
|
CheckedAt: checkedAt,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-05 15:34:53 +00:00
|
|
|
type TokenSetEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
|
|
|
|
TokenID string `json:"tokenID"`
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *TokenSetEvent) Payload() interface{} {
|
2023-05-05 15:34:53 +00:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *TokenSetEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2023-05-05 15:34:53 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewTokenSetEvent(
|
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
|
|
|
tokenID string,
|
|
|
|
) *TokenSetEvent {
|
|
|
|
return &TokenSetEvent{
|
|
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
TokenSetType,
|
|
|
|
),
|
|
|
|
TokenID: tokenID,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func TokenSetEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
2023-05-05 15:34:53 +00:00
|
|
|
added := &TokenSetEvent{
|
|
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
|
|
}
|
2023-10-19 10:19:10 +00:00
|
|
|
err := event.Unmarshal(added)
|
2023-05-05 15:34:53 +00:00
|
|
|
if err != nil {
|
2023-12-08 14:30:55 +00:00
|
|
|
return nil, zerrors.ThrowInternal(err, "SESSION-Sf3va", "unable to unmarshal token set")
|
2023-05-05 15:34:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return added, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type MetadataSetEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
|
|
|
|
Metadata map[string][]byte `json:"metadata"`
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *MetadataSetEvent) Payload() interface{} {
|
2023-05-05 15:34:53 +00:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *MetadataSetEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2023-05-05 15:34:53 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewMetadataSetEvent(
|
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
|
|
|
metadata map[string][]byte,
|
|
|
|
) *MetadataSetEvent {
|
|
|
|
return &MetadataSetEvent{
|
|
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
MetadataSetType,
|
|
|
|
),
|
|
|
|
Metadata: metadata,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func MetadataSetEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
2023-05-05 15:34:53 +00:00
|
|
|
added := &MetadataSetEvent{
|
|
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
|
|
}
|
2023-10-19 10:19:10 +00:00
|
|
|
err := event.Unmarshal(added)
|
2023-05-05 15:34:53 +00:00
|
|
|
if err != nil {
|
2023-12-08 14:30:55 +00:00
|
|
|
return nil, zerrors.ThrowInternal(err, "SESSION-BD21d", "unable to unmarshal metadata set")
|
2023-05-05 15:34:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return added, nil
|
|
|
|
}
|
|
|
|
|
2023-11-06 09:48:28 +00:00
|
|
|
type LifetimeSetEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
|
|
|
|
Lifetime time.Duration `json:"lifetime"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *LifetimeSetEvent) Payload() interface{} {
|
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *LifetimeSetEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *LifetimeSetEvent) SetBaseEvent(base *eventstore.BaseEvent) {
|
|
|
|
e.BaseEvent = *base
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewLifetimeSetEvent(
|
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
|
|
|
lifetime time.Duration,
|
|
|
|
) *LifetimeSetEvent {
|
|
|
|
return &LifetimeSetEvent{
|
|
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
LifetimeSetType,
|
|
|
|
),
|
|
|
|
Lifetime: lifetime,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-05 15:34:53 +00:00
|
|
|
type TerminateEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *TerminateEvent) Payload() interface{} {
|
2023-05-05 15:34:53 +00:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (e *TerminateEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
2023-05-05 15:34:53 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewTerminateEvent(
|
|
|
|
ctx context.Context,
|
|
|
|
aggregate *eventstore.Aggregate,
|
|
|
|
) *TerminateEvent {
|
|
|
|
return &TerminateEvent{
|
|
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
TerminateType,
|
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func TerminateEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
2023-05-05 15:34:53 +00:00
|
|
|
return &TerminateEvent{
|
|
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
|
|
}, nil
|
|
|
|
}
|