2021-03-15 12:51:15 +01:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2021-03-19 18:46:26 +01:00
|
|
|
"testing"
|
2023-08-11 16:19:14 +02:00
|
|
|
"time"
|
2021-03-19 18:46:26 +01:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2023-10-19 12:34:00 +02:00
|
|
|
openid "github.com/zitadel/oidc/v3/pkg/oidc"
|
2023-11-22 12:56:43 +02:00
|
|
|
"go.uber.org/mock/gomock"
|
2021-03-19 18:46:26 +01:00
|
|
|
"golang.org/x/text/language"
|
|
|
|
|
2022-04-27 01:01:45 +02:00
|
|
|
"github.com/zitadel/zitadel/internal/api/authz"
|
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 17:00:38 +02:00
|
|
|
http_util "github.com/zitadel/zitadel/internal/api/http"
|
2023-08-11 16:19:14 +02:00
|
|
|
"github.com/zitadel/zitadel/internal/crypto"
|
2022-04-27 01:01:45 +02:00
|
|
|
"github.com/zitadel/zitadel/internal/domain"
|
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
|
|
|
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
|
|
|
|
"github.com/zitadel/zitadel/internal/id"
|
|
|
|
id_mock "github.com/zitadel/zitadel/internal/id/mock"
|
|
|
|
"github.com/zitadel/zitadel/internal/repository/org"
|
2022-11-30 17:01:17 +01:00
|
|
|
"github.com/zitadel/zitadel/internal/repository/project"
|
2022-04-27 01:01:45 +02:00
|
|
|
"github.com/zitadel/zitadel/internal/repository/user"
|
2023-12-08 16:30:55 +02:00
|
|
|
"github.com/zitadel/zitadel/internal/zerrors"
|
2021-03-15 12:51:15 +01:00
|
|
|
)
|
|
|
|
|
2022-04-12 16:20:17 +02:00
|
|
|
func TestAddOrg(t *testing.T) {
|
|
|
|
type args struct {
|
|
|
|
a *org.Aggregate
|
|
|
|
name string
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx := context.Background()
|
2022-04-20 16:59:37 +02:00
|
|
|
agg := org.NewAggregate("test")
|
2022-04-12 16:20:17 +02:00
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
args args
|
|
|
|
want Want
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "invalid domain",
|
|
|
|
args: args{
|
|
|
|
a: agg,
|
|
|
|
name: "",
|
|
|
|
},
|
|
|
|
want: Want{
|
2023-12-08 16:30:55 +02:00
|
|
|
ValidationErr: zerrors.ThrowInvalidArgument(nil, "ORG-mruNY", "Errors.Invalid.Argument"),
|
2022-04-12 16:20:17 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "correct",
|
|
|
|
args: args{
|
|
|
|
a: agg,
|
|
|
|
name: "caos ag",
|
|
|
|
},
|
|
|
|
want: Want{
|
|
|
|
Commands: []eventstore.Command{
|
|
|
|
org.NewOrgAddedEvent(ctx, &agg.Aggregate, "caos ag"),
|
|
|
|
org.NewDomainAddedEvent(ctx, &agg.Aggregate, "caos-ag.localhost"),
|
|
|
|
org.NewDomainVerifiedEvent(ctx, &agg.Aggregate, "caos-ag.localhost"),
|
|
|
|
org.NewDomainPrimarySetEvent(ctx, &agg.Aggregate, "caos-ag.localhost"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
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 17:00:38 +02:00
|
|
|
AssertValidation(t, context.Background(), AddOrgCommand(http_util.WithRequestedHost(context.Background(), "localhost"), tt.args.a, tt.args.name), nil, tt.want)
|
2022-04-12 16:20:17 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-15 12:51:15 +01:00
|
|
|
func TestCommandSide_AddOrg(t *testing.T) {
|
|
|
|
type fields struct {
|
|
|
|
eventstore *eventstore.Eventstore
|
|
|
|
idGenerator id.Generator
|
|
|
|
zitadelRoles []authz.RoleMapping
|
|
|
|
}
|
|
|
|
type args struct {
|
2021-05-04 11:09:24 +02:00
|
|
|
ctx context.Context
|
|
|
|
name string
|
|
|
|
userID string
|
|
|
|
resourceOwner string
|
|
|
|
claimedUserIDs []string
|
2021-03-15 12:51:15 +01:00
|
|
|
}
|
|
|
|
type res struct {
|
|
|
|
want *domain.Org
|
|
|
|
err func(error) bool
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
args args
|
|
|
|
res res
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "invalid org, error",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
userID: "user1",
|
|
|
|
resourceOwner: "org1",
|
|
|
|
},
|
|
|
|
res: res{
|
2023-12-08 16:30:55 +02:00
|
|
|
err: zerrors.IsErrorInvalidArgument,
|
2021-03-15 12:51:15 +01:00
|
|
|
},
|
|
|
|
},
|
2022-08-19 15:00:14 +02:00
|
|
|
{
|
|
|
|
name: "invalid org (spaces), error",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
userID: "user1",
|
|
|
|
resourceOwner: "org1",
|
|
|
|
name: " ",
|
|
|
|
},
|
|
|
|
res: res{
|
2023-12-08 16:30:55 +02:00
|
|
|
err: zerrors.IsErrorInvalidArgument,
|
2022-08-19 15:00:14 +02:00
|
|
|
},
|
|
|
|
},
|
2021-03-15 12:51:15 +01:00
|
|
|
{
|
|
|
|
name: "user removed, error",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
expectFilterOrgDomainNotFound(),
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
user.NewHumanAddedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
|
|
|
"username1",
|
|
|
|
"firstname1",
|
|
|
|
"lastname1",
|
|
|
|
"nickname1",
|
|
|
|
"displayname1",
|
2023-12-05 12:12:01 +01:00
|
|
|
language.English,
|
2021-03-15 12:51:15 +01:00
|
|
|
domain.GenderMale,
|
|
|
|
"email1",
|
|
|
|
true,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
user.NewUserRemovedEvent(
|
|
|
|
context.Background(),
|
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
|
|
|
"username1",
|
2021-08-24 09:22:21 +02:00
|
|
|
nil,
|
2021-03-15 12:51:15 +01:00
|
|
|
true,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "org2"),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
name: "Org",
|
|
|
|
userID: "user1",
|
|
|
|
resourceOwner: "org1",
|
|
|
|
},
|
|
|
|
res: res{
|
2023-12-08 16:30:55 +02:00
|
|
|
err: zerrors.IsPreconditionFailed,
|
2021-03-15 12:51:15 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "push failed unique constraint, error",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
expectFilterOrgDomainNotFound(),
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
user.NewHumanAddedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
|
|
|
"username1",
|
|
|
|
"firstname1",
|
|
|
|
"lastname1",
|
|
|
|
"nickname1",
|
|
|
|
"displayname1",
|
2023-12-05 12:12:01 +01:00
|
|
|
language.English,
|
2021-03-15 12:51:15 +01:00
|
|
|
domain.GenderMale,
|
|
|
|
"email1",
|
|
|
|
true,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectFilterOrgMemberNotFound(),
|
2023-12-08 16:30:55 +02:00
|
|
|
expectPushFailed(zerrors.ThrowAlreadyExists(nil, "id", "internal"),
|
2023-10-19 12:19:10 +02:00
|
|
|
org.NewOrgAddedEvent(
|
|
|
|
context.Background(),
|
|
|
|
&org.NewAggregate("org2").Aggregate,
|
|
|
|
"Org",
|
|
|
|
),
|
|
|
|
org.NewDomainAddedEvent(
|
|
|
|
context.Background(),
|
|
|
|
&org.NewAggregate("org2").Aggregate,
|
|
|
|
"org.iam-domain",
|
|
|
|
),
|
|
|
|
org.NewDomainVerifiedEvent(
|
|
|
|
context.Background(),
|
|
|
|
&org.NewAggregate("org2").Aggregate,
|
|
|
|
"org.iam-domain",
|
|
|
|
),
|
|
|
|
org.NewDomainPrimarySetEvent(
|
|
|
|
context.Background(),
|
|
|
|
&org.NewAggregate("org2").Aggregate,
|
|
|
|
"org.iam-domain",
|
|
|
|
),
|
|
|
|
org.NewMemberAddedEvent(
|
|
|
|
context.Background(),
|
|
|
|
&org.NewAggregate("org2").Aggregate,
|
|
|
|
"user1", domain.RoleOrgOwner,
|
|
|
|
),
|
2021-03-15 12:51:15 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "org2"),
|
|
|
|
zitadelRoles: []authz.RoleMapping{
|
|
|
|
{
|
|
|
|
Role: "ORG_OWNER",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
args: args{
|
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 17:00:38 +02:00
|
|
|
ctx: http_util.WithRequestedHost(context.Background(), "iam-domain"),
|
2021-03-15 12:51:15 +01:00
|
|
|
name: "Org",
|
|
|
|
userID: "user1",
|
|
|
|
resourceOwner: "org1",
|
|
|
|
},
|
|
|
|
res: res{
|
2023-12-08 16:30:55 +02:00
|
|
|
err: zerrors.IsErrorAlreadyExists,
|
2021-03-15 12:51:15 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "push failed, error",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
expectFilterOrgDomainNotFound(),
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
user.NewHumanAddedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
|
|
|
"username1",
|
|
|
|
"firstname1",
|
|
|
|
"lastname1",
|
|
|
|
"nickname1",
|
|
|
|
"displayname1",
|
2023-12-05 12:12:01 +01:00
|
|
|
language.English,
|
2021-03-15 12:51:15 +01:00
|
|
|
domain.GenderMale,
|
|
|
|
"email1",
|
|
|
|
true,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectFilterOrgMemberNotFound(),
|
2023-12-08 16:30:55 +02:00
|
|
|
expectPushFailed(zerrors.ThrowInternal(nil, "id", "internal"),
|
2023-10-19 12:19:10 +02:00
|
|
|
org.NewOrgAddedEvent(
|
|
|
|
context.Background(),
|
|
|
|
&org.NewAggregate("org2").Aggregate,
|
|
|
|
"Org",
|
|
|
|
),
|
|
|
|
org.NewDomainAddedEvent(
|
|
|
|
context.Background(),
|
|
|
|
&org.NewAggregate("org2").Aggregate,
|
|
|
|
"org.iam-domain",
|
|
|
|
),
|
|
|
|
org.NewDomainVerifiedEvent(
|
|
|
|
context.Background(),
|
|
|
|
&org.NewAggregate("org2").Aggregate,
|
|
|
|
"org.iam-domain",
|
|
|
|
),
|
|
|
|
org.NewDomainPrimarySetEvent(
|
|
|
|
context.Background(),
|
|
|
|
&org.NewAggregate("org2").Aggregate,
|
|
|
|
"org.iam-domain",
|
|
|
|
),
|
|
|
|
org.NewMemberAddedEvent(
|
|
|
|
context.Background(),
|
|
|
|
&org.NewAggregate("org2").Aggregate,
|
|
|
|
"user1", domain.RoleOrgOwner,
|
|
|
|
),
|
2021-03-15 12:51:15 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "org2"),
|
|
|
|
zitadelRoles: []authz.RoleMapping{
|
|
|
|
{
|
|
|
|
Role: "ORG_OWNER",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
args: args{
|
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 17:00:38 +02:00
|
|
|
ctx: http_util.WithRequestedHost(context.Background(), "iam-domain"),
|
2021-03-15 12:51:15 +01:00
|
|
|
name: "Org",
|
|
|
|
userID: "user1",
|
|
|
|
resourceOwner: "org1",
|
|
|
|
},
|
|
|
|
res: res{
|
2023-12-08 16:30:55 +02:00
|
|
|
err: zerrors.IsInternal,
|
2021-03-15 12:51:15 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "add org, no error",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
expectFilterOrgDomainNotFound(),
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
user.NewHumanAddedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
|
|
|
"username1",
|
|
|
|
"firstname1",
|
|
|
|
"lastname1",
|
|
|
|
"nickname1",
|
|
|
|
"displayname1",
|
2023-12-05 12:12:01 +01:00
|
|
|
language.English,
|
2021-03-15 12:51:15 +01:00
|
|
|
domain.GenderMale,
|
|
|
|
"email1",
|
|
|
|
true,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectFilterOrgMemberNotFound(),
|
|
|
|
expectPush(
|
2023-10-19 12:19:10 +02:00
|
|
|
org.NewOrgAddedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org2").Aggregate,
|
|
|
|
"Org",
|
|
|
|
),
|
|
|
|
org.NewDomainAddedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org2").Aggregate, "org.iam-domain",
|
|
|
|
),
|
|
|
|
org.NewDomainVerifiedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org2").Aggregate,
|
|
|
|
"org.iam-domain",
|
|
|
|
),
|
|
|
|
org.NewDomainPrimarySetEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org2").Aggregate,
|
|
|
|
"org.iam-domain",
|
|
|
|
),
|
|
|
|
org.NewMemberAddedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org2").Aggregate,
|
|
|
|
"user1",
|
|
|
|
domain.RoleOrgOwner,
|
|
|
|
),
|
2021-03-15 12:51:15 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "org2"),
|
|
|
|
zitadelRoles: []authz.RoleMapping{
|
|
|
|
{
|
|
|
|
Role: "ORG_OWNER",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
args: args{
|
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 17:00:38 +02:00
|
|
|
ctx: http_util.WithRequestedHost(context.Background(), "iam-domain"),
|
2021-03-15 12:51:15 +01:00
|
|
|
name: "Org",
|
|
|
|
userID: "user1",
|
|
|
|
resourceOwner: "org1",
|
|
|
|
},
|
|
|
|
res: res{
|
|
|
|
want: &domain.Org{
|
|
|
|
ObjectRoot: models.ObjectRoot{
|
|
|
|
AggregateID: "org2",
|
|
|
|
ResourceOwner: "org2",
|
|
|
|
},
|
|
|
|
Name: "Org",
|
|
|
|
State: domain.OrgStateActive,
|
|
|
|
PrimaryDomain: "org.iam-domain",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-08-19 15:00:14 +02:00
|
|
|
{
|
|
|
|
name: "add org (remove spaces), no error",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
expectFilterOrgDomainNotFound(),
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
user.NewHumanAddedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
|
|
|
"username1",
|
|
|
|
"firstname1",
|
|
|
|
"lastname1",
|
|
|
|
"nickname1",
|
|
|
|
"displayname1",
|
2023-12-05 12:12:01 +01:00
|
|
|
language.English,
|
2022-08-19 15:00:14 +02:00
|
|
|
domain.GenderMale,
|
|
|
|
"email1",
|
|
|
|
true,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectFilterOrgMemberNotFound(),
|
|
|
|
expectPush(
|
2023-10-19 12:19:10 +02:00
|
|
|
org.NewOrgAddedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org2").Aggregate,
|
|
|
|
"Org",
|
|
|
|
),
|
|
|
|
org.NewDomainAddedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org2").Aggregate, "org.iam-domain",
|
|
|
|
),
|
|
|
|
org.NewDomainVerifiedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org2").Aggregate,
|
|
|
|
"org.iam-domain",
|
|
|
|
),
|
|
|
|
org.NewDomainPrimarySetEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org2").Aggregate,
|
|
|
|
"org.iam-domain",
|
|
|
|
),
|
|
|
|
org.NewMemberAddedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org2").Aggregate,
|
|
|
|
"user1",
|
|
|
|
domain.RoleOrgOwner,
|
|
|
|
),
|
2022-08-19 15:00:14 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "org2"),
|
|
|
|
zitadelRoles: []authz.RoleMapping{
|
|
|
|
{
|
|
|
|
Role: "ORG_OWNER",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
args: args{
|
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 17:00:38 +02:00
|
|
|
ctx: http_util.WithRequestedHost(context.Background(), "iam-domain"),
|
2022-08-19 15:00:14 +02:00
|
|
|
name: " Org ",
|
|
|
|
userID: "user1",
|
|
|
|
resourceOwner: "org1",
|
|
|
|
},
|
|
|
|
res: res{
|
|
|
|
want: &domain.Org{
|
|
|
|
ObjectRoot: models.ObjectRoot{
|
|
|
|
AggregateID: "org2",
|
|
|
|
ResourceOwner: "org2",
|
|
|
|
},
|
|
|
|
Name: "Org",
|
|
|
|
State: domain.OrgStateActive,
|
|
|
|
PrimaryDomain: "org.iam-domain",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-03-15 12:51:15 +01:00
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
r := &Commands{
|
|
|
|
eventstore: tt.fields.eventstore,
|
|
|
|
idGenerator: tt.fields.idGenerator,
|
|
|
|
zitadelRoles: tt.fields.zitadelRoles,
|
|
|
|
}
|
2021-05-04 11:09:24 +02:00
|
|
|
got, err := r.AddOrg(tt.args.ctx, tt.args.name, tt.args.userID, tt.args.resourceOwner, tt.args.claimedUserIDs)
|
2021-03-15 12:51:15 +01:00
|
|
|
if tt.res.err == nil {
|
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
|
|
|
if tt.res.err != nil && !tt.res.err(err) {
|
|
|
|
t.Errorf("got wrong err: %v ", err)
|
|
|
|
}
|
|
|
|
if tt.res.err == nil {
|
|
|
|
assert.Equal(t, tt.res.want, got)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-04 11:09:24 +02:00
|
|
|
func TestCommandSide_ChangeOrg(t *testing.T) {
|
|
|
|
type fields struct {
|
|
|
|
eventstore *eventstore.Eventstore
|
|
|
|
}
|
|
|
|
type args struct {
|
|
|
|
ctx context.Context
|
|
|
|
orgID string
|
|
|
|
name string
|
|
|
|
}
|
|
|
|
type res struct {
|
2022-08-19 15:00:14 +02:00
|
|
|
err func(error) bool
|
2021-05-04 11:09:24 +02:00
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
args args
|
|
|
|
res res
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "empty name, invalid argument error",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
|
|
|
},
|
|
|
|
res: res{
|
2023-12-08 16:30:55 +02:00
|
|
|
err: zerrors.IsErrorInvalidArgument,
|
2021-05-04 11:09:24 +02:00
|
|
|
},
|
|
|
|
},
|
2022-08-19 15:00:14 +02:00
|
|
|
{
|
|
|
|
name: "empty name (spaces), invalid argument error",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
|
|
|
name: " ",
|
|
|
|
},
|
|
|
|
res: res{
|
2023-12-08 16:30:55 +02:00
|
|
|
err: zerrors.IsErrorInvalidArgument,
|
2022-08-19 15:00:14 +02:00
|
|
|
},
|
|
|
|
},
|
2021-05-04 11:09:24 +02:00
|
|
|
{
|
|
|
|
name: "org not found, error",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
expectFilter(),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
|
|
|
name: "org",
|
|
|
|
},
|
|
|
|
res: res{
|
2023-12-08 16:30:55 +02:00
|
|
|
err: zerrors.IsNotFound,
|
2021-05-04 11:09:24 +02:00
|
|
|
},
|
|
|
|
},
|
2022-08-19 15:00:14 +02:00
|
|
|
{
|
|
|
|
name: "no change (spaces), error",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewOrgAddedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate,
|
|
|
|
"org"),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
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 17:00:38 +02:00
|
|
|
ctx: http_util.WithRequestedHost(context.Background(), "zitadel.ch"),
|
2022-08-19 15:00:14 +02:00
|
|
|
orgID: "org1",
|
|
|
|
name: " org ",
|
|
|
|
},
|
|
|
|
res: res{
|
2023-12-08 16:30:55 +02:00
|
|
|
err: zerrors.IsPreconditionFailed,
|
2022-08-19 15:00:14 +02:00
|
|
|
},
|
|
|
|
},
|
2021-05-04 11:09:24 +02:00
|
|
|
{
|
|
|
|
name: "push failed, error",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewOrgAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-05-04 11:09:24 +02:00
|
|
|
"org"),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectFilter(),
|
|
|
|
expectPushFailed(
|
2023-12-08 16:30:55 +02:00
|
|
|
zerrors.ThrowInternal(nil, "id", "message"),
|
2023-10-19 12:19:10 +02:00
|
|
|
org.NewOrgChangedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate, "org", "neworg",
|
|
|
|
),
|
2021-05-04 11:09:24 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
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 17:00:38 +02:00
|
|
|
ctx: http_util.WithRequestedHost(context.Background(), "zitadel.ch"),
|
2021-05-04 11:09:24 +02:00
|
|
|
orgID: "org1",
|
|
|
|
name: "neworg",
|
|
|
|
},
|
|
|
|
res: res{
|
2023-12-08 16:30:55 +02:00
|
|
|
err: zerrors.IsInternal,
|
2021-05-04 11:09:24 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "change org name verified, not primary",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewOrgAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-05-04 11:09:24 +02:00
|
|
|
"org"),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewOrgAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-05-04 11:09:24 +02:00
|
|
|
"org"),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-05-04 11:09:24 +02:00
|
|
|
"org.zitadel.ch"),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainVerifiedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-05-04 11:09:24 +02:00
|
|
|
"org.zitadel.ch"),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectPush(
|
2023-10-19 12:19:10 +02:00
|
|
|
org.NewOrgChangedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate, "org", "neworg",
|
|
|
|
),
|
|
|
|
org.NewDomainAddedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate, "neworg.zitadel.ch",
|
|
|
|
),
|
|
|
|
org.NewDomainVerifiedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate, "neworg.zitadel.ch",
|
|
|
|
),
|
|
|
|
org.NewDomainRemovedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate, "org.zitadel.ch", true,
|
|
|
|
),
|
2021-05-04 11:09:24 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
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 17:00:38 +02:00
|
|
|
ctx: http_util.WithRequestedHost(context.Background(), "zitadel.ch"),
|
2021-05-04 11:09:24 +02:00
|
|
|
orgID: "org1",
|
|
|
|
name: "neworg",
|
|
|
|
},
|
|
|
|
res: res{},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "change org name verified, with primary",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewOrgAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-05-04 11:09:24 +02:00
|
|
|
"org"),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewOrgAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-05-04 11:09:24 +02:00
|
|
|
"org"),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-05-04 11:09:24 +02:00
|
|
|
"org.zitadel.ch"),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainVerifiedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-05-04 11:09:24 +02:00
|
|
|
"org.zitadel.ch"),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainPrimarySetEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-05-04 11:09:24 +02:00
|
|
|
"org.zitadel.ch"),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectPush(
|
2023-10-19 12:19:10 +02:00
|
|
|
org.NewOrgChangedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate, "org", "neworg",
|
|
|
|
),
|
|
|
|
org.NewDomainAddedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate, "neworg.zitadel.ch",
|
|
|
|
),
|
|
|
|
org.NewDomainVerifiedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate, "neworg.zitadel.ch",
|
|
|
|
),
|
|
|
|
org.NewDomainPrimarySetEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate, "neworg.zitadel.ch",
|
|
|
|
),
|
|
|
|
org.NewDomainRemovedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate, "org.zitadel.ch", true,
|
|
|
|
),
|
2021-05-04 11:09:24 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
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 17:00:38 +02:00
|
|
|
ctx: http_util.WithRequestedHost(context.Background(), "zitadel.ch"),
|
2021-05-04 11:09:24 +02:00
|
|
|
orgID: "org1",
|
|
|
|
name: "neworg",
|
|
|
|
},
|
|
|
|
res: res{},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
r := &Commands{
|
|
|
|
eventstore: tt.fields.eventstore,
|
|
|
|
}
|
|
|
|
_, err := r.ChangeOrg(tt.args.ctx, tt.args.orgID, tt.args.name)
|
|
|
|
if tt.res.err == nil {
|
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
|
|
|
if tt.res.err != nil && !tt.res.err(err) {
|
|
|
|
t.Errorf("got wrong err: %v ", err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-15 12:51:15 +01:00
|
|
|
func TestCommandSide_DeactivateOrg(t *testing.T) {
|
|
|
|
type fields struct {
|
|
|
|
eventstore *eventstore.Eventstore
|
|
|
|
idGenerator id.Generator
|
|
|
|
iamDomain string
|
|
|
|
}
|
|
|
|
type args struct {
|
|
|
|
ctx context.Context
|
|
|
|
orgID string
|
|
|
|
}
|
|
|
|
type res struct {
|
|
|
|
want *domain.Org
|
|
|
|
err func(error) bool
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
args args
|
|
|
|
res res
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "org not found, error",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
expectFilter(),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
|
|
|
},
|
|
|
|
res: res{
|
2023-12-08 16:30:55 +02:00
|
|
|
err: zerrors.IsNotFound,
|
2021-03-15 12:51:15 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "org already inactive, error",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewOrgAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-03-15 12:51:15 +01:00
|
|
|
"org"),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewOrgDeactivatedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate),
|
2021-03-15 12:51:15 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
|
|
|
},
|
|
|
|
res: res{
|
2023-12-08 16:30:55 +02:00
|
|
|
err: zerrors.IsPreconditionFailed,
|
2021-03-15 12:51:15 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "push failed, error",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewOrgAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-03-15 12:51:15 +01:00
|
|
|
"org"),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectPushFailed(
|
2023-12-08 16:30:55 +02:00
|
|
|
zerrors.ThrowInternal(nil, "id", "message"),
|
2023-10-19 12:19:10 +02:00
|
|
|
org.NewOrgDeactivatedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate,
|
|
|
|
),
|
2021-03-15 12:51:15 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
|
|
|
},
|
|
|
|
res: res{
|
2023-12-08 16:30:55 +02:00
|
|
|
err: zerrors.IsInternal,
|
2021-03-15 12:51:15 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "deactivate org",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewOrgAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-03-15 12:51:15 +01:00
|
|
|
"org"),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectPush(
|
2023-10-19 12:19:10 +02:00
|
|
|
org.NewOrgDeactivatedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate,
|
|
|
|
),
|
2021-03-15 12:51:15 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
|
|
|
},
|
|
|
|
res: res{},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
r := &Commands{
|
|
|
|
eventstore: tt.fields.eventstore,
|
|
|
|
idGenerator: tt.fields.idGenerator,
|
|
|
|
}
|
|
|
|
_, err := r.DeactivateOrg(tt.args.ctx, tt.args.orgID)
|
|
|
|
if tt.res.err == nil {
|
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
|
|
|
if tt.res.err != nil && !tt.res.err(err) {
|
|
|
|
t.Errorf("got wrong err: %v ", err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2023-10-19 12:19:10 +02:00
|
|
|
|
2021-03-15 12:51:15 +01:00
|
|
|
func TestCommandSide_ReactivateOrg(t *testing.T) {
|
|
|
|
type fields struct {
|
|
|
|
eventstore *eventstore.Eventstore
|
|
|
|
idGenerator id.Generator
|
|
|
|
iamDomain string
|
|
|
|
}
|
|
|
|
type args struct {
|
|
|
|
ctx context.Context
|
|
|
|
orgID string
|
|
|
|
}
|
|
|
|
type res struct {
|
|
|
|
want *domain.Org
|
|
|
|
err func(error) bool
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
args args
|
|
|
|
res res
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "org not found, error",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
expectFilter(),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
|
|
|
},
|
|
|
|
res: res{
|
2023-12-08 16:30:55 +02:00
|
|
|
err: zerrors.IsNotFound,
|
2021-03-15 12:51:15 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "org already active, error",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewOrgAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-03-15 12:51:15 +01:00
|
|
|
"org"),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
|
|
|
},
|
|
|
|
res: res{
|
2023-12-08 16:30:55 +02:00
|
|
|
err: zerrors.IsPreconditionFailed,
|
2021-03-15 12:51:15 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "push failed, error",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewOrgAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-03-15 12:51:15 +01:00
|
|
|
"org"),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewOrgDeactivatedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-03-15 12:51:15 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectPushFailed(
|
2023-12-08 16:30:55 +02:00
|
|
|
zerrors.ThrowInternal(nil, "id", "message"),
|
2023-10-19 12:19:10 +02:00
|
|
|
org.NewOrgReactivatedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate,
|
|
|
|
),
|
2021-03-15 12:51:15 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
|
|
|
},
|
|
|
|
res: res{
|
2023-12-08 16:30:55 +02:00
|
|
|
err: zerrors.IsInternal,
|
2021-03-15 12:51:15 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "reactivate org",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewOrgAddedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2021-03-15 12:51:15 +01:00
|
|
|
"org"),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewOrgDeactivatedEvent(context.Background(),
|
2022-04-20 16:59:37 +02:00
|
|
|
&org.NewAggregate("org1").Aggregate),
|
2021-03-15 12:51:15 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
expectPush(
|
2023-10-19 12:19:10 +02:00
|
|
|
org.NewOrgReactivatedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate,
|
|
|
|
),
|
2021-03-15 12:51:15 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
|
|
|
},
|
|
|
|
res: res{},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
r := &Commands{
|
|
|
|
eventstore: tt.fields.eventstore,
|
|
|
|
idGenerator: tt.fields.idGenerator,
|
|
|
|
}
|
|
|
|
_, err := r.ReactivateOrg(tt.args.ctx, tt.args.orgID)
|
|
|
|
if tt.res.err == nil {
|
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
|
|
|
if tt.res.err != nil && !tt.res.err(err) {
|
|
|
|
t.Errorf("got wrong err: %v ", err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2022-11-30 17:01:17 +01:00
|
|
|
|
|
|
|
func TestCommandSide_RemoveOrg(t *testing.T) {
|
|
|
|
type fields struct {
|
|
|
|
eventstore *eventstore.Eventstore
|
|
|
|
idGenerator id.Generator
|
|
|
|
}
|
|
|
|
type args struct {
|
|
|
|
ctx context.Context
|
|
|
|
orgID string
|
|
|
|
}
|
|
|
|
type res struct {
|
|
|
|
err func(error) bool
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
args args
|
|
|
|
res res
|
|
|
|
}{
|
2022-12-14 11:44:43 +01:00
|
|
|
{
|
|
|
|
name: "default org, error",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: authz.WithInstance(context.Background(), &mockInstance{}),
|
|
|
|
orgID: "defaultOrgID",
|
|
|
|
},
|
|
|
|
res: res{
|
2023-12-08 16:30:55 +02:00
|
|
|
err: zerrors.IsPreconditionFailed,
|
2022-12-14 11:44:43 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "zitadel org, error",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
project.NewProjectAddedEvent(context.Background(),
|
|
|
|
&project.NewAggregate("projectID", "org1").Aggregate,
|
|
|
|
"ZITADEL",
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
domain.PrivateLabelingSettingUnspecified,
|
|
|
|
),
|
|
|
|
)),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
|
|
|
},
|
|
|
|
res: res{
|
2023-12-08 16:30:55 +02:00
|
|
|
err: zerrors.IsPreconditionFailed,
|
2022-12-14 11:44:43 +01:00
|
|
|
},
|
|
|
|
},
|
2022-11-30 17:01:17 +01:00
|
|
|
{
|
|
|
|
name: "org not found, error",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
2022-12-14 11:44:43 +01:00
|
|
|
expectFilter(), // zitadel project check
|
2022-11-30 17:01:17 +01:00
|
|
|
expectFilter(),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
|
|
|
},
|
|
|
|
res: res{
|
2023-12-08 16:30:55 +02:00
|
|
|
err: zerrors.IsNotFound,
|
2022-11-30 17:01:17 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "push failed, error",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
2022-12-14 11:44:43 +01:00
|
|
|
expectFilter(), // zitadel project check
|
2022-11-30 17:01:17 +01:00
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewOrgAddedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate,
|
|
|
|
"org"),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainPolicyAddedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectFilter(),
|
|
|
|
expectFilter(),
|
|
|
|
expectFilter(),
|
|
|
|
expectFilter(),
|
|
|
|
expectPushFailed(
|
2023-12-08 16:30:55 +02:00
|
|
|
zerrors.ThrowInternal(nil, "id", "message"),
|
2023-10-19 12:19:10 +02:00
|
|
|
org.NewOrgRemovedEvent(
|
|
|
|
context.Background(), &org.NewAggregate("org1").Aggregate, "org", []string{}, false, []string{}, []*domain.UserIDPLink{}, []string{},
|
|
|
|
),
|
2022-11-30 17:01:17 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
|
|
|
},
|
|
|
|
res: res{
|
2023-12-08 16:30:55 +02:00
|
|
|
err: zerrors.IsInternal,
|
2022-11-30 17:01:17 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "remove org",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
2022-12-14 11:44:43 +01:00
|
|
|
expectFilter(), // zitadel project check
|
2022-11-30 17:01:17 +01:00
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewOrgAddedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate,
|
|
|
|
"org"),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainPolicyAddedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectFilter(),
|
|
|
|
expectFilter(),
|
|
|
|
expectFilter(),
|
|
|
|
expectFilter(),
|
|
|
|
expectPush(
|
2023-10-19 12:19:10 +02:00
|
|
|
org.NewOrgRemovedEvent(
|
|
|
|
context.Background(), &org.NewAggregate("org1").Aggregate, "org", []string{}, false, []string{}, []*domain.UserIDPLink{}, []string{},
|
|
|
|
),
|
2022-11-30 17:01:17 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
|
|
|
},
|
|
|
|
res: res{},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "remove org with usernames and domains",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: eventstoreExpect(
|
|
|
|
t,
|
2022-12-14 11:44:43 +01:00
|
|
|
expectFilter(), // zitadel project check
|
2022-11-30 17:01:17 +01:00
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewOrgAddedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate,
|
|
|
|
"org"),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainPolicyAddedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("org1").Aggregate,
|
2023-10-19 12:19:10 +02:00
|
|
|
false,
|
2022-11-30 17:01:17 +01:00
|
|
|
true,
|
|
|
|
true,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
user.NewHumanAddedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "org1").Aggregate,
|
|
|
|
"user1",
|
|
|
|
"firstname1",
|
|
|
|
"lastname1",
|
|
|
|
"nickname1",
|
|
|
|
"displayname1",
|
2023-12-05 12:12:01 +01:00
|
|
|
language.English,
|
2022-11-30 17:01:17 +01:00
|
|
|
domain.GenderMale,
|
|
|
|
"email1",
|
2023-10-19 12:19:10 +02:00
|
|
|
false,
|
2022-11-30 17:01:17 +01:00
|
|
|
),
|
|
|
|
), eventFromEventPusher(
|
|
|
|
user.NewMachineAddedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user2", "org1").Aggregate,
|
|
|
|
"user2",
|
|
|
|
"name",
|
|
|
|
"description",
|
2023-10-19 12:19:10 +02:00
|
|
|
false,
|
2023-02-08 09:06:34 +01:00
|
|
|
domain.OIDCTokenTypeBearer,
|
2022-11-30 17:01:17 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainVerifiedEvent(context.Background(), &org.NewAggregate("org1").Aggregate, "domain1"),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainVerifiedEvent(context.Background(), &org.NewAggregate("org1").Aggregate, "domain2"),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
user.NewUserIDPLinkAddedEvent(context.Background(), &user.NewAggregate("user1", "org1").Aggregate, "config1", "display1", "id1"),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
user.NewUserIDPLinkAddedEvent(context.Background(), &user.NewAggregate("user2", "org1").Aggregate, "config2", "display2", "id2"),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
project.NewSAMLConfigAddedEvent(context.Background(), &project.NewAggregate("project1", "org1").Aggregate, "app1", "entity1", []byte{}, ""),
|
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
project.NewSAMLConfigAddedEvent(context.Background(), &project.NewAggregate("project2", "org1").Aggregate, "app2", "entity2", []byte{}, ""),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectPush(
|
2023-10-19 12:19:10 +02:00
|
|
|
org.NewOrgRemovedEvent(context.Background(), &org.NewAggregate("org1").Aggregate, "org",
|
|
|
|
[]string{"user1", "user2"},
|
|
|
|
false,
|
|
|
|
[]string{"domain1", "domain2"},
|
|
|
|
[]*domain.UserIDPLink{{IDPConfigID: "config1", ExternalUserID: "id1", DisplayName: "display1"}, {IDPConfigID: "config2", ExternalUserID: "id2", DisplayName: "display2"}},
|
|
|
|
[]string{"entity1", "entity2"},
|
|
|
|
),
|
2022-11-30 17:01:17 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
ctx: context.Background(),
|
|
|
|
orgID: "org1",
|
|
|
|
},
|
|
|
|
res: res{},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
r := &Commands{
|
|
|
|
eventstore: tt.fields.eventstore,
|
|
|
|
idGenerator: tt.fields.idGenerator,
|
|
|
|
}
|
|
|
|
_, err := r.RemoveOrg(tt.args.ctx, tt.args.orgID)
|
|
|
|
if tt.res.err == nil {
|
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
|
|
|
if tt.res.err != nil && !tt.res.err(err) {
|
|
|
|
t.Errorf("got wrong err: %v ", err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2023-08-11 16:19:14 +02:00
|
|
|
|
|
|
|
func TestCommandSide_SetUpOrg(t *testing.T) {
|
|
|
|
type fields struct {
|
|
|
|
eventstore func(t *testing.T) *eventstore.Eventstore
|
|
|
|
idGenerator id.Generator
|
2024-04-05 12:35:49 +03:00
|
|
|
newCode encrypedCodeFunc
|
2023-08-11 16:19:14 +02:00
|
|
|
keyAlgorithm crypto.EncryptionAlgorithm
|
|
|
|
}
|
|
|
|
type args struct {
|
|
|
|
ctx context.Context
|
|
|
|
setupOrg *OrgSetup
|
|
|
|
allowInitialMail bool
|
|
|
|
userIDs []string
|
|
|
|
}
|
|
|
|
type res struct {
|
|
|
|
createdOrg *CreatedOrg
|
|
|
|
err error
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
args args
|
|
|
|
res res
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "org name empty, error",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: expectEventstore(),
|
|
|
|
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "orgID"),
|
|
|
|
},
|
|
|
|
args: args{
|
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 17:00:38 +02:00
|
|
|
ctx: http_util.WithRequestedHost(context.Background(), "iam-domain"),
|
2023-08-11 16:19:14 +02:00
|
|
|
setupOrg: &OrgSetup{
|
|
|
|
Name: "",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
res: res{
|
2023-12-08 16:30:55 +02:00
|
|
|
err: zerrors.ThrowInvalidArgument(nil, "ORG-mruNY", "Errors.Invalid.Argument"),
|
2023-08-11 16:19:14 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "userID not existing, error",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: expectEventstore(
|
|
|
|
expectFilter(),
|
|
|
|
),
|
|
|
|
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "orgID"),
|
|
|
|
},
|
|
|
|
args: args{
|
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 17:00:38 +02:00
|
|
|
ctx: http_util.WithRequestedHost(context.Background(), "iam-domain"),
|
2023-08-11 16:19:14 +02:00
|
|
|
setupOrg: &OrgSetup{
|
|
|
|
Name: "Org",
|
|
|
|
Admins: []*OrgSetupAdmin{
|
|
|
|
{
|
|
|
|
ID: "userID",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
res: res{
|
2023-12-08 16:30:55 +02:00
|
|
|
err: zerrors.ThrowPreconditionFailed(nil, "ORG-GoXOn", "Errors.User.NotFound"),
|
2023-08-11 16:19:14 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "human invalid, error",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: expectEventstore(),
|
|
|
|
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "orgID", "userID"),
|
|
|
|
},
|
|
|
|
args: args{
|
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 17:00:38 +02:00
|
|
|
ctx: http_util.WithRequestedHost(context.Background(), "iam-domain"),
|
2023-08-11 16:19:14 +02:00
|
|
|
setupOrg: &OrgSetup{
|
|
|
|
Name: "Org",
|
|
|
|
Admins: []*OrgSetupAdmin{
|
|
|
|
{
|
|
|
|
Human: &AddHuman{
|
|
|
|
Username: "",
|
|
|
|
FirstName: "firstname",
|
|
|
|
LastName: "lastname",
|
|
|
|
Email: Email{
|
|
|
|
Address: "email@test.ch",
|
|
|
|
Verified: true,
|
|
|
|
},
|
|
|
|
PreferredLanguage: language.English,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
allowInitialMail: true,
|
|
|
|
},
|
|
|
|
res: res{
|
2023-12-08 16:30:55 +02:00
|
|
|
err: zerrors.ThrowInvalidArgument(nil, "V2-zzad3", "Errors.Invalid.Argument"),
|
2023-08-11 16:19:14 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "human added with initial mail",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: expectEventstore(
|
|
|
|
expectFilter(), // add human exists check
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainPolicyAddedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("userID", "orgID").Aggregate,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectFilter(), // org member check
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
user.NewHumanAddedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "orgID").Aggregate,
|
|
|
|
"username",
|
|
|
|
"firstname",
|
|
|
|
"lastname",
|
|
|
|
"",
|
|
|
|
"firstname lastname",
|
|
|
|
language.English,
|
|
|
|
domain.GenderUnspecified,
|
|
|
|
"email@test.ch",
|
|
|
|
true,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectPush(
|
2023-10-19 12:19:10 +02:00
|
|
|
eventFromEventPusher(org.NewOrgAddedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("orgID").Aggregate,
|
|
|
|
"Org",
|
|
|
|
)),
|
|
|
|
eventFromEventPusher(org.NewDomainAddedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("orgID").Aggregate, "org.iam-domain",
|
|
|
|
)),
|
|
|
|
eventFromEventPusher(org.NewDomainVerifiedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("orgID").Aggregate,
|
|
|
|
"org.iam-domain",
|
|
|
|
)),
|
|
|
|
eventFromEventPusher(org.NewDomainPrimarySetEvent(context.Background(),
|
|
|
|
&org.NewAggregate("orgID").Aggregate,
|
|
|
|
"org.iam-domain",
|
|
|
|
)),
|
|
|
|
eventFromEventPusher(
|
|
|
|
user.NewHumanAddedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("userID", "orgID").Aggregate,
|
|
|
|
"username",
|
|
|
|
"firstname",
|
|
|
|
"lastname",
|
|
|
|
"",
|
|
|
|
"firstname lastname",
|
|
|
|
language.English,
|
|
|
|
domain.GenderUnspecified,
|
|
|
|
"email@test.ch",
|
|
|
|
true,
|
2023-08-11 16:19:14 +02:00
|
|
|
),
|
2023-10-19 12:19:10 +02:00
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
user.NewHumanEmailVerifiedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("userID", "orgID").Aggregate,
|
2023-08-11 16:19:14 +02:00
|
|
|
),
|
2023-10-19 12:19:10 +02:00
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
user.NewHumanInitialCodeAddedEvent(
|
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 17:00:38 +02:00
|
|
|
http_util.WithRequestedHost(context.Background(), "iam-domain"),
|
2023-10-19 12:19:10 +02:00
|
|
|
&user.NewAggregate("userID", "orgID").Aggregate,
|
|
|
|
&crypto.CryptoValue{
|
|
|
|
CryptoType: crypto.TypeEncryption,
|
|
|
|
Algorithm: "enc",
|
|
|
|
KeyID: "id",
|
|
|
|
Crypted: []byte("userinit"),
|
|
|
|
},
|
|
|
|
1*time.Hour,
|
2024-04-24 17:50:58 +02:00
|
|
|
"",
|
2023-08-11 16:19:14 +02:00
|
|
|
),
|
2023-10-19 12:19:10 +02:00
|
|
|
),
|
|
|
|
eventFromEventPusher(org.NewMemberAddedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("orgID").Aggregate,
|
|
|
|
"userID",
|
|
|
|
domain.RoleOrgOwner,
|
|
|
|
)),
|
2023-08-11 16:19:14 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "orgID", "userID"),
|
2024-04-05 12:35:49 +03:00
|
|
|
newCode: mockEncryptedCode("userinit", time.Hour),
|
2023-08-11 16:19:14 +02:00
|
|
|
},
|
|
|
|
args: args{
|
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 17:00:38 +02:00
|
|
|
ctx: http_util.WithRequestedHost(context.Background(), "iam-domain"),
|
2023-08-11 16:19:14 +02:00
|
|
|
setupOrg: &OrgSetup{
|
|
|
|
Name: "Org",
|
|
|
|
Admins: []*OrgSetupAdmin{
|
|
|
|
{
|
|
|
|
Human: &AddHuman{
|
|
|
|
Username: "username",
|
|
|
|
FirstName: "firstname",
|
|
|
|
LastName: "lastname",
|
|
|
|
Email: Email{
|
|
|
|
Address: "email@test.ch",
|
|
|
|
Verified: true,
|
|
|
|
},
|
|
|
|
PreferredLanguage: language.English,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
allowInitialMail: true,
|
|
|
|
},
|
|
|
|
res: res{
|
|
|
|
createdOrg: &CreatedOrg{
|
|
|
|
ObjectDetails: &domain.ObjectDetails{
|
|
|
|
ResourceOwner: "orgID",
|
|
|
|
},
|
|
|
|
CreatedAdmins: []*CreatedOrgAdmin{
|
|
|
|
{
|
|
|
|
ID: "userID",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "existing human added",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: expectEventstore(
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
user.NewHumanAddedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "orgID").Aggregate,
|
|
|
|
"username",
|
|
|
|
"firstname",
|
|
|
|
"lastname",
|
|
|
|
"",
|
|
|
|
"firstname lastname",
|
|
|
|
language.English,
|
|
|
|
domain.GenderUnspecified,
|
|
|
|
"email@test.ch",
|
|
|
|
true,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectFilter(), // org member check
|
|
|
|
expectPush(
|
2023-10-19 12:19:10 +02:00
|
|
|
eventFromEventPusher(org.NewOrgAddedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("orgID").Aggregate,
|
|
|
|
"Org",
|
|
|
|
)),
|
|
|
|
eventFromEventPusher(org.NewDomainAddedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("orgID").Aggregate, "org.iam-domain",
|
|
|
|
)),
|
|
|
|
eventFromEventPusher(org.NewDomainVerifiedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("orgID").Aggregate,
|
|
|
|
"org.iam-domain",
|
|
|
|
)),
|
|
|
|
eventFromEventPusher(org.NewDomainPrimarySetEvent(context.Background(),
|
|
|
|
&org.NewAggregate("orgID").Aggregate,
|
|
|
|
"org.iam-domain",
|
|
|
|
)),
|
|
|
|
eventFromEventPusher(org.NewMemberAddedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("orgID").Aggregate,
|
|
|
|
"userID",
|
|
|
|
domain.RoleOrgOwner,
|
|
|
|
)),
|
2023-08-11 16:19:14 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "orgID"),
|
|
|
|
},
|
|
|
|
args: args{
|
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 17:00:38 +02:00
|
|
|
ctx: http_util.WithRequestedHost(context.Background(), "iam-domain"),
|
2023-08-11 16:19:14 +02:00
|
|
|
setupOrg: &OrgSetup{
|
|
|
|
Name: "Org",
|
|
|
|
Admins: []*OrgSetupAdmin{
|
|
|
|
{
|
|
|
|
ID: "userID",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
allowInitialMail: true,
|
|
|
|
},
|
|
|
|
res: res{
|
|
|
|
createdOrg: &CreatedOrg{
|
|
|
|
ObjectDetails: &domain.ObjectDetails{
|
|
|
|
ResourceOwner: "orgID",
|
|
|
|
},
|
|
|
|
CreatedAdmins: []*CreatedOrgAdmin{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "machine added with pat",
|
|
|
|
fields: fields{
|
|
|
|
eventstore: expectEventstore(
|
|
|
|
expectFilter(), // add machine exists check
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
org.NewDomainPolicyAddedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("userID", "orgID").Aggregate,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectFilter(),
|
|
|
|
expectFilter(),
|
|
|
|
expectFilter(), // org member check
|
|
|
|
expectFilter(
|
|
|
|
eventFromEventPusher(
|
|
|
|
user.NewHumanAddedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("user1", "orgID").Aggregate,
|
|
|
|
"username",
|
|
|
|
"firstname",
|
|
|
|
"lastname",
|
|
|
|
"",
|
|
|
|
"firstname lastname",
|
|
|
|
language.English,
|
|
|
|
domain.GenderUnspecified,
|
|
|
|
"email@test.ch",
|
|
|
|
true,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expectPush(
|
2023-10-19 12:19:10 +02:00
|
|
|
eventFromEventPusher(org.NewOrgAddedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("orgID").Aggregate,
|
|
|
|
"Org",
|
|
|
|
)),
|
|
|
|
eventFromEventPusher(org.NewDomainAddedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("orgID").Aggregate, "org.iam-domain",
|
|
|
|
)),
|
|
|
|
eventFromEventPusher(org.NewDomainVerifiedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("orgID").Aggregate,
|
|
|
|
"org.iam-domain",
|
|
|
|
)),
|
|
|
|
eventFromEventPusher(org.NewDomainPrimarySetEvent(context.Background(),
|
|
|
|
&org.NewAggregate("orgID").Aggregate,
|
|
|
|
"org.iam-domain",
|
|
|
|
)),
|
|
|
|
eventFromEventPusher(
|
|
|
|
user.NewMachineAddedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("userID", "orgID").Aggregate,
|
|
|
|
"username",
|
|
|
|
"name",
|
|
|
|
"description",
|
|
|
|
true,
|
|
|
|
domain.OIDCTokenTypeBearer,
|
2023-08-11 16:19:14 +02:00
|
|
|
),
|
2023-10-19 12:19:10 +02:00
|
|
|
),
|
|
|
|
eventFromEventPusher(
|
|
|
|
user.NewPersonalAccessTokenAddedEvent(context.Background(),
|
|
|
|
&user.NewAggregate("userID", "orgID").Aggregate,
|
|
|
|
"tokenID",
|
|
|
|
testNow.Add(time.Hour),
|
|
|
|
[]string{openid.ScopeOpenID},
|
2023-08-11 16:19:14 +02:00
|
|
|
),
|
2023-10-19 12:19:10 +02:00
|
|
|
),
|
|
|
|
eventFromEventPusher(org.NewMemberAddedEvent(context.Background(),
|
|
|
|
&org.NewAggregate("orgID").Aggregate,
|
|
|
|
"userID",
|
|
|
|
domain.RoleOrgOwner,
|
|
|
|
)),
|
2023-08-11 16:19:14 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
idGenerator: id_mock.NewIDGeneratorExpectIDs(t, "orgID", "userID", "tokenID"),
|
2024-04-05 12:35:49 +03:00
|
|
|
newCode: mockEncryptedCode("userinit", time.Hour),
|
2023-08-11 16:19:14 +02:00
|
|
|
keyAlgorithm: crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
|
|
|
|
},
|
|
|
|
args: args{
|
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 17:00:38 +02:00
|
|
|
ctx: http_util.WithRequestedHost(context.Background(), "iam-domain"),
|
2023-08-11 16:19:14 +02:00
|
|
|
setupOrg: &OrgSetup{
|
|
|
|
Name: "Org",
|
|
|
|
Admins: []*OrgSetupAdmin{
|
|
|
|
{
|
|
|
|
Machine: &AddMachine{
|
|
|
|
Machine: &Machine{
|
|
|
|
Username: "username",
|
|
|
|
Name: "name",
|
|
|
|
Description: "description",
|
|
|
|
AccessTokenType: domain.OIDCTokenTypeBearer,
|
|
|
|
},
|
|
|
|
Pat: &AddPat{
|
|
|
|
ExpirationDate: testNow.Add(time.Hour),
|
|
|
|
Scopes: []string{openid.ScopeOpenID},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
res: res{
|
|
|
|
createdOrg: &CreatedOrg{
|
|
|
|
ObjectDetails: &domain.ObjectDetails{
|
|
|
|
ResourceOwner: "orgID",
|
|
|
|
},
|
|
|
|
CreatedAdmins: []*CreatedOrgAdmin{
|
|
|
|
{
|
|
|
|
ID: "userID",
|
|
|
|
PAT: &PersonalAccessToken{
|
|
|
|
ObjectRoot: models.ObjectRoot{
|
|
|
|
AggregateID: "userID",
|
|
|
|
ResourceOwner: "orgID",
|
|
|
|
},
|
|
|
|
ExpirationDate: testNow.Add(time.Hour),
|
|
|
|
Scopes: []string{openid.ScopeOpenID},
|
|
|
|
AllowedUserType: domain.UserTypeMachine,
|
|
|
|
TokenID: "tokenID",
|
|
|
|
Token: "dG9rZW5JRDp1c2VySUQ", // token
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
r := &Commands{
|
2024-04-05 12:35:49 +03:00
|
|
|
eventstore: tt.fields.eventstore(t),
|
|
|
|
idGenerator: tt.fields.idGenerator,
|
|
|
|
newEncryptedCode: tt.fields.newCode,
|
|
|
|
keyAlgorithm: tt.fields.keyAlgorithm,
|
2023-08-11 16:19:14 +02:00
|
|
|
zitadelRoles: []authz.RoleMapping{
|
|
|
|
{
|
|
|
|
Role: domain.RoleOrgOwner,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
got, err := r.SetUpOrg(tt.args.ctx, tt.args.setupOrg, tt.args.allowInitialMail, tt.args.userIDs...)
|
|
|
|
assert.ErrorIs(t, err, tt.res.err)
|
|
|
|
assert.Equal(t, tt.res.createdOrg, got)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|