2022-02-09 14:01:19 +00:00
|
|
|
package start
|
|
|
|
|
|
|
|
import (
|
2022-02-14 16:22:30 +00:00
|
|
|
"context"
|
2022-06-24 12:38:22 +00:00
|
|
|
"crypto/tls"
|
2022-02-09 14:01:19 +00:00
|
|
|
_ "embed"
|
2022-02-14 16:22:30 +00:00
|
|
|
"fmt"
|
2023-05-11 07:24:44 +00:00
|
|
|
"math"
|
2022-02-14 16:22:30 +00:00
|
|
|
"net/http"
|
|
|
|
"os"
|
|
|
|
"os/signal"
|
2024-02-26 10:49:43 +00:00
|
|
|
"slices"
|
2022-02-14 16:22:30 +00:00
|
|
|
"syscall"
|
|
|
|
"time"
|
2022-02-09 14:01:19 +00:00
|
|
|
|
2023-02-15 01:52:11 +00:00
|
|
|
clockpkg "github.com/benbjohnson/clock"
|
2023-07-12 17:46:50 +00:00
|
|
|
"github.com/common-nighthawk/go-figure"
|
|
|
|
"github.com/fatih/color"
|
2022-02-14 16:22:30 +00:00
|
|
|
"github.com/gorilla/mux"
|
2022-02-09 14:01:19 +00:00
|
|
|
"github.com/spf13/cobra"
|
2022-02-14 16:22:30 +00:00
|
|
|
"github.com/spf13/viper"
|
2022-04-26 23:01:45 +00:00
|
|
|
"github.com/zitadel/logging"
|
2023-10-19 10:34:00 +00:00
|
|
|
"github.com/zitadel/oidc/v3/pkg/op"
|
2023-04-19 08:46:02 +00:00
|
|
|
"github.com/zitadel/saml/pkg/provider"
|
2022-02-14 16:22:30 +00:00
|
|
|
"golang.org/x/net/http2"
|
|
|
|
"golang.org/x/net/http2/h2c"
|
|
|
|
|
2023-07-12 17:46:50 +00:00
|
|
|
"github.com/zitadel/zitadel/cmd/build"
|
2024-01-25 16:28:20 +00:00
|
|
|
"github.com/zitadel/zitadel/cmd/encryption"
|
2022-06-27 10:32:34 +00:00
|
|
|
"github.com/zitadel/zitadel/cmd/key"
|
|
|
|
cmd_tls "github.com/zitadel/zitadel/cmd/tls"
|
2023-02-15 01:52:11 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/actions"
|
2022-04-26 23:01:45 +00:00
|
|
|
admin_es "github.com/zitadel/zitadel/internal/admin/repository/eventsourcing"
|
|
|
|
"github.com/zitadel/zitadel/internal/api"
|
|
|
|
"github.com/zitadel/zitadel/internal/api/assets"
|
|
|
|
internal_authz "github.com/zitadel/zitadel/internal/api/authz"
|
|
|
|
"github.com/zitadel/zitadel/internal/api/grpc/admin"
|
|
|
|
"github.com/zitadel/zitadel/internal/api/grpc/auth"
|
2024-07-26 20:39:55 +00:00
|
|
|
feature_v2 "github.com/zitadel/zitadel/internal/api/grpc/feature/v2"
|
|
|
|
feature_v2beta "github.com/zitadel/zitadel/internal/api/grpc/feature/v2beta"
|
2024-08-14 18:18:29 +00:00
|
|
|
idp_v2 "github.com/zitadel/zitadel/internal/api/grpc/idp/v2"
|
2022-04-26 23:01:45 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/api/grpc/management"
|
2023-07-10 13:27:00 +00:00
|
|
|
oidc_v2 "github.com/zitadel/zitadel/internal/api/grpc/oidc/v2"
|
2024-07-26 20:39:55 +00:00
|
|
|
oidc_v2beta "github.com/zitadel/zitadel/internal/api/grpc/oidc/v2beta"
|
|
|
|
org_v2 "github.com/zitadel/zitadel/internal/api/grpc/org/v2"
|
|
|
|
org_v2beta "github.com/zitadel/zitadel/internal/api/grpc/org/v2beta"
|
2024-07-31 12:42:12 +00:00
|
|
|
action_v3_alpha "github.com/zitadel/zitadel/internal/api/grpc/resources/action/v3alpha"
|
2024-09-11 08:24:00 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/api/grpc/resources/debug_events/debug_events"
|
2024-08-28 19:46:45 +00:00
|
|
|
user_v3_alpha "github.com/zitadel/zitadel/internal/api/grpc/resources/user/v3alpha"
|
|
|
|
userschema_v3_alpha "github.com/zitadel/zitadel/internal/api/grpc/resources/userschema/v3alpha"
|
2024-08-14 14:18:14 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/api/grpc/resources/webkey/v3"
|
2024-07-26 20:39:55 +00:00
|
|
|
session_v2 "github.com/zitadel/zitadel/internal/api/grpc/session/v2"
|
|
|
|
session_v2beta "github.com/zitadel/zitadel/internal/api/grpc/session/v2beta"
|
|
|
|
settings_v2 "github.com/zitadel/zitadel/internal/api/grpc/settings/v2"
|
|
|
|
settings_v2beta "github.com/zitadel/zitadel/internal/api/grpc/settings/v2beta"
|
2022-04-26 23:01:45 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/api/grpc/system"
|
2023-09-29 09:26:14 +00:00
|
|
|
user_v2 "github.com/zitadel/zitadel/internal/api/grpc/user/v2"
|
2024-07-26 20:39:55 +00:00
|
|
|
user_v2beta "github.com/zitadel/zitadel/internal/api/grpc/user/v2beta"
|
2022-05-31 11:11:49 +00:00
|
|
|
http_util "github.com/zitadel/zitadel/internal/api/http"
|
2022-04-26 23:01:45 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/api/http/middleware"
|
2023-05-24 18:29:58 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/api/idp"
|
2022-04-26 23:01:45 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/api/oidc"
|
2023-05-05 08:25:02 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/api/robots_txt"
|
2023-02-15 01:52:11 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/api/saml"
|
2022-04-26 23:01:45 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/api/ui/console"
|
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
|
|
|
"github.com/zitadel/zitadel/internal/api/ui/console/path"
|
2022-04-26 23:01:45 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/api/ui/login"
|
|
|
|
auth_es "github.com/zitadel/zitadel/internal/auth/repository/eventsourcing"
|
|
|
|
"github.com/zitadel/zitadel/internal/authz"
|
|
|
|
authz_repo "github.com/zitadel/zitadel/internal/authz/repository"
|
2023-06-20 16:23:28 +00:00
|
|
|
authz_es "github.com/zitadel/zitadel/internal/authz/repository/eventsourcing/eventstore"
|
2022-04-26 23:01:45 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/command"
|
2023-04-24 17:40:31 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/crypto"
|
2022-04-26 23:01:45 +00:00
|
|
|
cryptoDB "github.com/zitadel/zitadel/internal/crypto/database"
|
|
|
|
"github.com/zitadel/zitadel/internal/database"
|
2023-12-20 16:13:04 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/database/dialect"
|
2023-05-05 15:34:53 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/domain"
|
2022-04-26 23:01:45 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
2023-10-19 10:19:10 +00:00
|
|
|
old_es "github.com/zitadel/zitadel/internal/eventstore/repository/sql"
|
|
|
|
new_es "github.com/zitadel/zitadel/internal/eventstore/v3"
|
2023-12-05 11:12:01 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/i18n"
|
2022-04-26 23:01:45 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/id"
|
2024-09-06 12:47:57 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/integration/sink"
|
2023-02-15 01:52:11 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/logstore"
|
|
|
|
"github.com/zitadel/zitadel/internal/logstore/emitters/access"
|
|
|
|
"github.com/zitadel/zitadel/internal/logstore/emitters/execution"
|
|
|
|
"github.com/zitadel/zitadel/internal/logstore/emitters/stdout"
|
2023-09-15 14:58:45 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/logstore/record"
|
|
|
|
"github.com/zitadel/zitadel/internal/net"
|
2022-04-26 23:01:45 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/notification"
|
|
|
|
"github.com/zitadel/zitadel/internal/query"
|
|
|
|
"github.com/zitadel/zitadel/internal/static"
|
2024-05-30 09:35:30 +00:00
|
|
|
es_v4 "github.com/zitadel/zitadel/internal/v2/eventstore"
|
|
|
|
es_v4_pg "github.com/zitadel/zitadel/internal/v2/eventstore/postgres"
|
2022-04-26 23:01:45 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/webauthn"
|
|
|
|
"github.com/zitadel/zitadel/openapi"
|
2022-02-09 14:01:19 +00:00
|
|
|
)
|
|
|
|
|
2023-04-24 17:40:31 +00:00
|
|
|
func New(server chan<- *Server) *cobra.Command {
|
2022-02-14 16:22:30 +00:00
|
|
|
start := &cobra.Command{
|
2022-02-09 14:01:19 +00:00
|
|
|
Use: "start",
|
|
|
|
Short: "starts ZITADEL instance",
|
|
|
|
Long: `starts ZITADEL.
|
|
|
|
Requirements:
|
|
|
|
- cockroachdb`,
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2022-06-24 12:38:22 +00:00
|
|
|
err := cmd_tls.ModeFromFlag(cmd)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-03-28 08:05:09 +00:00
|
|
|
config := MustNewConfig(viper.GetViper())
|
2022-04-04 08:10:57 +00:00
|
|
|
masterKey, err := key.MasterKey(cmd)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2024-01-04 16:12:20 +00:00
|
|
|
return startZitadel(cmd.Context(), config, masterKey, server)
|
2022-02-09 14:01:19 +00:00
|
|
|
},
|
|
|
|
}
|
2022-02-14 16:22:30 +00:00
|
|
|
|
2022-03-28 08:05:09 +00:00
|
|
|
startFlags(start)
|
2022-03-14 06:55:09 +00:00
|
|
|
|
2022-02-14 16:22:30 +00:00
|
|
|
return start
|
|
|
|
}
|
|
|
|
|
2023-04-24 17:40:31 +00:00
|
|
|
type Server struct {
|
|
|
|
Config *Config
|
|
|
|
DB *database.DB
|
|
|
|
KeyStorage crypto.KeyStorage
|
2024-01-25 16:28:20 +00:00
|
|
|
Keys *encryption.EncryptionKeys
|
2023-04-24 17:40:31 +00:00
|
|
|
Eventstore *eventstore.Eventstore
|
|
|
|
Queries *query.Queries
|
|
|
|
AuthzRepo authz_repo.Repository
|
|
|
|
Storage static.Storage
|
|
|
|
Commands *command.Commands
|
|
|
|
Router *mux.Router
|
|
|
|
TLSConfig *tls.Config
|
|
|
|
Shutdown chan<- os.Signal
|
|
|
|
}
|
|
|
|
|
2024-01-04 16:12:20 +00:00
|
|
|
func startZitadel(ctx context.Context, config *Config, masterKey string, server chan<- *Server) error {
|
2023-07-12 17:46:50 +00:00
|
|
|
showBasicInformation(config)
|
|
|
|
|
2024-09-06 12:47:57 +00:00
|
|
|
// sink Server is stubbed out in production builds, see function's godoc.
|
|
|
|
closeSink := sink.StartServer()
|
|
|
|
defer closeSink()
|
|
|
|
|
2023-12-05 11:12:01 +00:00
|
|
|
i18n.MustLoadSupportedLanguagesFromDir()
|
|
|
|
|
2023-12-20 16:13:04 +00:00
|
|
|
queryDBClient, err := database.Connect(config.Database, false, dialect.DBPurposeQuery)
|
2023-10-19 10:19:10 +00:00
|
|
|
if err != nil {
|
2023-12-20 16:13:04 +00:00
|
|
|
return fmt.Errorf("cannot start DB client for queries: %w", err)
|
2023-10-19 10:19:10 +00:00
|
|
|
}
|
2023-12-20 16:13:04 +00:00
|
|
|
esPusherDBClient, err := database.Connect(config.Database, false, dialect.DBPurposeEventPusher)
|
2022-02-14 16:22:30 +00:00
|
|
|
if err != nil {
|
2023-12-20 16:13:04 +00:00
|
|
|
return fmt.Errorf("cannot start client for event store pusher: %w", err)
|
|
|
|
}
|
|
|
|
projectionDBClient, err := database.Connect(config.Database, false, dialect.DBPurposeProjectionSpooler)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("cannot start client for projection spooler: %w", err)
|
2022-02-14 16:22:30 +00:00
|
|
|
}
|
2022-03-14 06:55:09 +00:00
|
|
|
|
2023-12-20 16:13:04 +00:00
|
|
|
keyStorage, err := cryptoDB.NewKeyStorage(queryDBClient, masterKey)
|
2022-03-14 06:55:09 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("cannot start key storage: %w", err)
|
|
|
|
}
|
2024-01-25 16:28:20 +00:00
|
|
|
keys, err := encryption.EnsureEncryptionKeys(ctx, config.EncryptionKeys, keyStorage)
|
2022-03-14 06:55:09 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
config.Eventstore.Pusher = new_es.NewEventstore(esPusherDBClient)
|
2024-07-03 15:00:56 +00:00
|
|
|
config.Eventstore.Searcher = new_es.NewEventstore(queryDBClient)
|
2023-12-20 16:13:04 +00:00
|
|
|
config.Eventstore.Querier = old_es.NewCRDB(queryDBClient)
|
2023-10-19 10:19:10 +00:00
|
|
|
eventstoreClient := eventstore.NewEventstore(config.Eventstore)
|
2024-05-30 09:35:30 +00:00
|
|
|
eventstoreV4 := es_v4.NewEventstoreFromOne(es_v4_pg.New(queryDBClient, &es_v4_pg.Config{
|
|
|
|
MaxRetries: config.Eventstore.MaxRetries,
|
|
|
|
}))
|
2022-02-16 15:49:17 +00:00
|
|
|
|
2023-05-05 15:34:53 +00:00
|
|
|
sessionTokenVerifier := internal_authz.SessionTokenVerifier(keys.OIDC)
|
|
|
|
|
|
|
|
queries, err := query.StartQueries(
|
|
|
|
ctx,
|
|
|
|
eventstoreClient,
|
2024-05-30 09:35:30 +00:00
|
|
|
eventstoreV4.Querier,
|
2023-12-20 16:13:04 +00:00
|
|
|
queryDBClient,
|
|
|
|
projectionDBClient,
|
2023-05-05 15:34:53 +00:00
|
|
|
config.Projections,
|
|
|
|
config.SystemDefaults,
|
|
|
|
keys.IDPConfig,
|
|
|
|
keys.OTP,
|
|
|
|
keys.OIDC,
|
|
|
|
keys.SAML,
|
|
|
|
config.InternalAuthZ.RolePermissionMappings,
|
|
|
|
sessionTokenVerifier,
|
2023-06-20 16:23:28 +00:00
|
|
|
func(q *query.Queries) domain.PermissionCheck {
|
|
|
|
return func(ctx context.Context, permission, orgID, resourceID string) (err error) {
|
|
|
|
return internal_authz.CheckPermission(ctx, &authz_es.UserMembershipRepo{Queries: q}, config.InternalAuthZ.RolePermissionMappings, permission, orgID, resourceID)
|
|
|
|
}
|
|
|
|
},
|
2023-10-25 11:42:00 +00:00
|
|
|
config.AuditLogRetention,
|
2023-10-19 10:19:10 +00:00
|
|
|
config.SystemAPIUsers,
|
2024-01-25 16:28:20 +00:00
|
|
|
true,
|
2023-05-05 15:34:53 +00:00
|
|
|
)
|
2022-02-14 16:22:30 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("cannot start queries: %w", err)
|
|
|
|
}
|
|
|
|
|
2023-12-20 16:13:04 +00:00
|
|
|
authZRepo, err := authz.Start(queries, eventstoreClient, queryDBClient, keys.OIDC, config.ExternalSecure)
|
2022-02-14 16:22:30 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("error starting authz repo: %w", err)
|
|
|
|
}
|
2023-05-05 15:34:53 +00:00
|
|
|
permissionCheck := func(ctx context.Context, permission, orgID, resourceID string) (err error) {
|
|
|
|
return internal_authz.CheckPermission(ctx, authZRepo, config.InternalAuthZ.RolePermissionMappings, permission, orgID, resourceID)
|
|
|
|
}
|
2022-04-06 06:13:40 +00:00
|
|
|
|
2023-12-20 16:13:04 +00:00
|
|
|
storage, err := config.AssetStorage.NewStorage(queryDBClient.DB)
|
2022-04-06 06:13:40 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("cannot start asset storage client: %w", err)
|
|
|
|
}
|
2022-04-25 08:01:17 +00:00
|
|
|
webAuthNConfig := &webauthn.Config{
|
|
|
|
DisplayName: config.WebAuthNName,
|
|
|
|
ExternalSecure: config.ExternalSecure,
|
2022-02-14 16:22:30 +00:00
|
|
|
}
|
2022-04-25 09:16:36 +00:00
|
|
|
commands, err := command.StartCommands(
|
|
|
|
eventstoreClient,
|
|
|
|
config.SystemDefaults,
|
|
|
|
config.InternalAuthZ.RolePermissionMappings,
|
|
|
|
storage,
|
|
|
|
webAuthNConfig,
|
2022-04-28 08:30:41 +00:00
|
|
|
config.ExternalDomain,
|
2022-04-25 09:16:36 +00:00
|
|
|
config.ExternalSecure,
|
|
|
|
config.ExternalPort,
|
|
|
|
keys.IDPConfig,
|
|
|
|
keys.OTP,
|
|
|
|
keys.SMTP,
|
|
|
|
keys.SMS,
|
|
|
|
keys.User,
|
|
|
|
keys.DomainVerification,
|
|
|
|
keys.OIDC,
|
2022-09-12 16:18:08 +00:00
|
|
|
keys.SAML,
|
|
|
|
&http.Client{},
|
2023-05-05 15:34:53 +00:00
|
|
|
permissionCheck,
|
|
|
|
sessionTokenVerifier,
|
2023-07-10 13:27:00 +00:00
|
|
|
config.OIDC.DefaultAccessTokenLifetime,
|
|
|
|
config.OIDC.DefaultRefreshTokenExpiration,
|
|
|
|
config.OIDC.DefaultRefreshTokenIdleExpiration,
|
2023-08-23 08:04:29 +00:00
|
|
|
config.DefaultInstance.SecretGenerators,
|
2022-04-25 09:16:36 +00:00
|
|
|
)
|
2022-02-14 16:22:30 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("cannot start commands: %w", err)
|
|
|
|
}
|
2023-12-05 17:01:03 +00:00
|
|
|
defer commands.Close(ctx) // wait for background jobs
|
2022-02-14 16:22:30 +00:00
|
|
|
|
2023-02-15 01:52:11 +00:00
|
|
|
clock := clockpkg.New()
|
2023-09-15 14:58:45 +00:00
|
|
|
actionsExecutionStdoutEmitter, err := logstore.NewEmitter[*record.ExecutionLog](ctx, clock, &logstore.EmitterConfig{Enabled: config.LogStore.Execution.Stdout.Enabled}, stdout.NewStdoutEmitter[*record.ExecutionLog]())
|
2023-02-15 01:52:11 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-12-20 16:13:04 +00:00
|
|
|
actionsExecutionDBEmitter, err := logstore.NewEmitter[*record.ExecutionLog](ctx, clock, config.Quotas.Execution, execution.NewDatabaseLogStorage(queryDBClient, commands, queries))
|
2023-02-15 01:52:11 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-09-15 14:58:45 +00:00
|
|
|
actionsLogstoreSvc := logstore.New(queries, actionsExecutionDBEmitter, actionsExecutionStdoutEmitter)
|
2023-02-15 01:52:11 +00:00
|
|
|
actions.SetLogstoreService(actionsLogstoreSvc)
|
|
|
|
|
2024-01-25 16:28:20 +00:00
|
|
|
notification.Register(
|
2023-08-24 09:41:52 +00:00
|
|
|
ctx,
|
|
|
|
config.Projections.Customizations["notifications"],
|
|
|
|
config.Projections.Customizations["notificationsquotas"],
|
|
|
|
config.Projections.Customizations["telemetry"],
|
|
|
|
*config.Telemetry,
|
|
|
|
config.ExternalDomain,
|
|
|
|
config.ExternalPort,
|
|
|
|
config.ExternalSecure,
|
|
|
|
commands,
|
|
|
|
queries,
|
|
|
|
eventstoreClient,
|
|
|
|
config.Login.DefaultOTPEmailURLV2,
|
|
|
|
config.SystemDefaults.Notifications.FileSystemPath,
|
|
|
|
keys.User,
|
|
|
|
keys.SMTP,
|
|
|
|
keys.SMS,
|
|
|
|
)
|
2024-01-25 16:28:20 +00:00
|
|
|
notification.Start(ctx)
|
2022-02-14 16:22:30 +00:00
|
|
|
|
|
|
|
router := mux.NewRouter()
|
2022-06-24 12:38:22 +00:00
|
|
|
tlsConfig, err := config.TLS.Config()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2024-02-26 10:49:43 +00:00
|
|
|
api, err := startAPIs(
|
2023-05-05 15:34:53 +00:00
|
|
|
ctx,
|
|
|
|
clock,
|
|
|
|
router,
|
|
|
|
commands,
|
|
|
|
queries,
|
|
|
|
eventstoreClient,
|
2023-12-20 16:13:04 +00:00
|
|
|
queryDBClient,
|
2023-05-05 15:34:53 +00:00
|
|
|
config,
|
|
|
|
storage,
|
|
|
|
authZRepo,
|
|
|
|
keys,
|
|
|
|
permissionCheck,
|
|
|
|
)
|
2022-02-14 16:22:30 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2024-02-26 10:49:43 +00:00
|
|
|
commands.GrpcMethodExisting = checkExisting(api.ListGrpcMethods())
|
|
|
|
commands.GrpcServiceExisting = checkExisting(api.ListGrpcServices())
|
2023-04-24 17:40:31 +00:00
|
|
|
|
|
|
|
shutdown := make(chan os.Signal, 1)
|
|
|
|
signal.Notify(shutdown, os.Interrupt, syscall.SIGTERM)
|
|
|
|
|
|
|
|
if server != nil {
|
|
|
|
server <- &Server{
|
|
|
|
Config: config,
|
2023-12-20 16:13:04 +00:00
|
|
|
DB: queryDBClient,
|
2023-04-24 17:40:31 +00:00
|
|
|
KeyStorage: keyStorage,
|
|
|
|
Keys: keys,
|
|
|
|
Eventstore: eventstoreClient,
|
|
|
|
Queries: queries,
|
|
|
|
AuthzRepo: authZRepo,
|
|
|
|
Storage: storage,
|
|
|
|
Commands: commands,
|
|
|
|
Router: router,
|
|
|
|
TLSConfig: tlsConfig,
|
|
|
|
Shutdown: shutdown,
|
|
|
|
}
|
|
|
|
close(server)
|
|
|
|
}
|
|
|
|
|
|
|
|
return listen(ctx, router, config.Port, tlsConfig, shutdown)
|
2022-02-14 16:22:30 +00:00
|
|
|
}
|
|
|
|
|
2023-02-15 01:52:11 +00:00
|
|
|
func startAPIs(
|
|
|
|
ctx context.Context,
|
|
|
|
clock clockpkg.Clock,
|
|
|
|
router *mux.Router,
|
|
|
|
commands *command.Commands,
|
|
|
|
queries *query.Queries,
|
|
|
|
eventstore *eventstore.Eventstore,
|
2023-02-27 21:36:43 +00:00
|
|
|
dbClient *database.DB,
|
2023-02-15 01:52:11 +00:00
|
|
|
config *Config,
|
|
|
|
store static.Storage,
|
|
|
|
authZRepo authz_repo.Repository,
|
2024-01-25 16:28:20 +00:00
|
|
|
keys *encryption.EncryptionKeys,
|
2023-05-05 15:34:53 +00:00
|
|
|
permissionCheck domain.PermissionCheck,
|
2024-02-26 10:49:43 +00:00
|
|
|
) (*api.API, error) {
|
2022-02-14 16:22:30 +00:00
|
|
|
repo := struct {
|
|
|
|
authz_repo.Repository
|
|
|
|
*query.Queries
|
|
|
|
}{
|
|
|
|
authZRepo,
|
|
|
|
queries,
|
|
|
|
}
|
2023-10-25 12:09:15 +00:00
|
|
|
oidcPrefixes := []string{"/.well-known/openid-configuration", "/oidc/v1", "/oauth/v2"}
|
2023-10-10 13:20:53 +00:00
|
|
|
// always set the origin in the context if available in the http headers, no matter for what protocol
|
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
|
|
|
router.Use(middleware.WithOrigin(config.ExternalSecure, config.HTTP1HostHeader, config.HTTP2HostHeader, config.InstanceHostHeaders, config.PublicHostHeaders))
|
2023-10-25 15:10:45 +00:00
|
|
|
systemTokenVerifier, err := internal_authz.StartSystemTokenVerifierFromConfig(http_util.BuildHTTP(config.ExternalDomain, config.ExternalPort, config.ExternalSecure), config.SystemAPIUsers)
|
|
|
|
if err != nil {
|
2024-02-26 10:49:43 +00:00
|
|
|
return nil, err
|
2023-10-25 15:10:45 +00:00
|
|
|
}
|
|
|
|
accessTokenVerifer := internal_authz.StartAccessTokenVerifierFromRepo(repo)
|
|
|
|
verifier := internal_authz.StartAPITokenVerifier(repo, accessTokenVerifer, systemTokenVerifier)
|
2022-06-24 12:38:22 +00:00
|
|
|
tlsConfig, err := config.TLS.Config()
|
|
|
|
if err != nil {
|
2024-02-26 10:49:43 +00:00
|
|
|
return nil, err
|
2022-06-24 12:38:22 +00:00
|
|
|
}
|
2023-02-15 01:52:11 +00:00
|
|
|
|
2023-09-15 14:58:45 +00:00
|
|
|
accessStdoutEmitter, err := logstore.NewEmitter[*record.AccessLog](ctx, clock, &logstore.EmitterConfig{Enabled: config.LogStore.Access.Stdout.Enabled}, stdout.NewStdoutEmitter[*record.AccessLog]())
|
2023-02-15 01:52:11 +00:00
|
|
|
if err != nil {
|
2024-02-26 10:49:43 +00:00
|
|
|
return nil, err
|
2023-02-15 01:52:11 +00:00
|
|
|
}
|
2023-09-15 14:58:45 +00:00
|
|
|
accessDBEmitter, err := logstore.NewEmitter[*record.AccessLog](ctx, clock, &config.Quotas.Access.EmitterConfig, access.NewDatabaseLogStorage(dbClient, commands, queries))
|
2023-02-15 01:52:11 +00:00
|
|
|
if err != nil {
|
2024-02-26 10:49:43 +00:00
|
|
|
return nil, err
|
2023-02-15 01:52:11 +00:00
|
|
|
}
|
|
|
|
|
2023-09-15 14:58:45 +00:00
|
|
|
accessSvc := logstore.New[*record.AccessLog](queries, accessDBEmitter, accessStdoutEmitter)
|
2023-05-11 07:24:44 +00:00
|
|
|
exhaustedCookieHandler := http_util.NewCookieHandler(
|
|
|
|
http_util.WithUnsecure(),
|
|
|
|
http_util.WithNonHttpOnly(),
|
|
|
|
http_util.WithMaxAge(int(math.Floor(config.Quotas.Access.ExhaustedCookieMaxAge.Seconds()))),
|
|
|
|
)
|
2023-09-15 14:58:45 +00:00
|
|
|
limitingAccessInterceptor := middleware.NewAccessInterceptor(accessSvc, exhaustedCookieHandler, &config.Quotas.Access.AccessConfig)
|
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
|
|
|
apis, err := api.New(ctx, config.Port, router, queries, verifier, config.InternalAuthZ, tlsConfig, config.ExternalDomain, append(config.InstanceHostHeaders, config.PublicHostHeaders...), limitingAccessInterceptor)
|
2023-04-11 13:37:42 +00:00
|
|
|
if err != nil {
|
2024-02-26 10:49:43 +00:00
|
|
|
return nil, fmt.Errorf("error creating api %w", err)
|
2023-04-11 13:37:42 +00:00
|
|
|
}
|
2023-10-19 10:19:10 +00:00
|
|
|
|
|
|
|
config.Auth.Spooler.Client = dbClient
|
|
|
|
config.Auth.Spooler.Eventstore = eventstore
|
|
|
|
authRepo, err := auth_es.Start(ctx, config.Auth, config.SystemDefaults, commands, queries, dbClient, eventstore, keys.OIDC, keys.User)
|
2022-02-14 16:22:30 +00:00
|
|
|
if err != nil {
|
2024-02-26 10:49:43 +00:00
|
|
|
return nil, fmt.Errorf("error starting auth repo: %w", err)
|
2022-02-14 16:22:30 +00:00
|
|
|
}
|
2023-10-19 10:19:10 +00:00
|
|
|
|
|
|
|
config.Admin.Spooler.Client = dbClient
|
|
|
|
config.Admin.Spooler.Eventstore = eventstore
|
|
|
|
err = admin_es.Start(ctx, config.Admin, store, dbClient)
|
2022-02-14 16:22:30 +00:00
|
|
|
if err != nil {
|
2024-02-26 10:49:43 +00:00
|
|
|
return nil, fmt.Errorf("error starting admin repo: %w", err)
|
2022-02-14 16:22:30 +00:00
|
|
|
}
|
2023-10-19 10:19:10 +00:00
|
|
|
|
2023-11-09 10:30:15 +00:00
|
|
|
if err := apis.RegisterServer(ctx, system.CreateServer(commands, queries, config.Database.DatabaseName(), config.DefaultInstance, config.ExternalDomain), tlsConfig); err != nil {
|
2024-02-26 10:49:43 +00:00
|
|
|
return nil, err
|
2022-02-14 16:22:30 +00:00
|
|
|
}
|
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
|
|
|
if err := apis.RegisterServer(ctx, admin.CreateServer(config.Database.DatabaseName(), commands, queries, keys.User, config.AuditLogRetention), tlsConfig); err != nil {
|
2024-02-26 10:49:43 +00:00
|
|
|
return nil, err
|
2022-02-14 16:22:30 +00:00
|
|
|
}
|
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
|
|
|
if err := apis.RegisterServer(ctx, management.CreateServer(commands, queries, config.SystemDefaults, keys.User), tlsConfig); err != nil {
|
2024-02-26 10:49:43 +00:00
|
|
|
return nil, err
|
2022-04-21 10:37:39 +00:00
|
|
|
}
|
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
|
|
|
if err := apis.RegisterServer(ctx, auth.CreateServer(commands, queries, authRepo, config.SystemDefaults, keys.User), tlsConfig); err != nil {
|
2024-02-26 10:49:43 +00:00
|
|
|
return nil, err
|
2022-02-14 16:22:30 +00:00
|
|
|
}
|
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
|
|
|
if err := apis.RegisterService(ctx, user_v2beta.CreateServer(commands, queries, keys.User, keys.IDPConfig, idp.CallbackURL(), idp.SAMLRootURL(), assets.AssetAPI(), permissionCheck)); err != nil {
|
2024-07-26 20:39:55 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
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
|
|
|
if err := apis.RegisterService(ctx, user_v2.CreateServer(commands, queries, keys.User, keys.IDPConfig, idp.CallbackURL(), idp.SAMLRootURL(), assets.AssetAPI(), permissionCheck)); err != nil {
|
2024-02-26 10:49:43 +00:00
|
|
|
return nil, err
|
2023-04-11 13:37:42 +00:00
|
|
|
}
|
2024-07-26 20:39:55 +00:00
|
|
|
if err := apis.RegisterService(ctx, session_v2beta.CreateServer(commands, queries)); err != nil {
|
2024-02-26 10:49:43 +00:00
|
|
|
return nil, err
|
2023-04-11 13:37:42 +00:00
|
|
|
}
|
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
|
|
|
if err := apis.RegisterService(ctx, settings_v2beta.CreateServer(commands, queries)); err != nil {
|
2024-07-26 20:39:55 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if err := apis.RegisterService(ctx, org_v2beta.CreateServer(commands, queries, permissionCheck)); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if err := apis.RegisterService(ctx, feature_v2beta.CreateServer(commands, queries)); err != nil {
|
2024-02-26 10:49:43 +00:00
|
|
|
return nil, err
|
2023-05-11 09:23:40 +00:00
|
|
|
}
|
2024-07-26 20:39:55 +00:00
|
|
|
if err := apis.RegisterService(ctx, session_v2.CreateServer(commands, queries)); err != nil {
|
2024-02-26 10:49:43 +00:00
|
|
|
return nil, err
|
2023-08-11 14:19:14 +00:00
|
|
|
}
|
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
|
|
|
if err := apis.RegisterService(ctx, settings_v2.CreateServer(commands, queries)); err != nil {
|
2024-07-26 20:39:55 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if err := apis.RegisterService(ctx, org_v2.CreateServer(commands, queries, permissionCheck)); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if err := apis.RegisterService(ctx, feature_v2.CreateServer(commands, queries)); err != nil {
|
2024-02-28 08:55:54 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
2024-08-14 18:18:29 +00:00
|
|
|
if err := apis.RegisterService(ctx, idp_v2.CreateServer(commands, queries, permissionCheck)); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2024-08-12 20:32:01 +00:00
|
|
|
if err := apis.RegisterService(ctx, action_v3_alpha.CreateServer(config.SystemDefaults, commands, queries, domain.AllFunctions, apis.ListGrpcMethods, apis.ListGrpcServices)); err != nil {
|
2024-02-26 10:49:43 +00:00
|
|
|
return nil, err
|
2024-02-15 05:39:10 +00:00
|
|
|
}
|
2024-08-28 19:46:45 +00:00
|
|
|
if err := apis.RegisterService(ctx, userschema_v3_alpha.CreateServer(config.SystemDefaults, commands, queries)); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2024-09-25 13:31:31 +00:00
|
|
|
if err := apis.RegisterService(ctx, user_v3_alpha.CreateServer(commands)); err != nil {
|
2024-03-12 13:50:13 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
2024-08-14 14:18:14 +00:00
|
|
|
if err := apis.RegisterService(ctx, webkey.CreateServer(commands, queries)); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2024-09-11 08:24:00 +00:00
|
|
|
if err := apis.RegisterService(ctx, debug_events.CreateServer(commands, queries)); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
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
|
|
|
instanceInterceptor := middleware.InstanceInterceptor(queries, config.ExternalDomain, login.IgnoreInstanceEndpoints...)
|
2022-08-16 05:04:36 +00:00
|
|
|
assetsCache := middleware.AssetsCacheInterceptor(config.AssetStorage.Cache.MaxAge, config.AssetStorage.Cache.SharedMaxAge)
|
2023-05-11 07:24:44 +00:00
|
|
|
apis.RegisterHandlerOnPrefix(assets.HandlerPrefix, assets.NewHandler(commands, verifier, config.InternalAuthZ, id.SonyFlakeGenerator(), store, queries, middleware.CallDurationHandler, instanceInterceptor.Handler, assetsCache.Handler, limitingAccessInterceptor.Handle))
|
2022-02-14 16:22:30 +00:00
|
|
|
|
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
|
|
|
apis.RegisterHandlerOnPrefix(idp.HandlerPrefix, idp.NewHandler(commands, queries, keys.IDPConfig, instanceInterceptor.Handler))
|
2024-07-24 12:29:05 +00:00
|
|
|
|
2023-09-29 09:26:14 +00:00
|
|
|
userAgentInterceptor, err := middleware.NewUserAgentHandler(config.UserAgentCookie, keys.UserAgentCookieKey, id.SonyFlakeGenerator(), config.ExternalSecure, login.EndpointResources, login.EndpointExternalLoginCallbackFormPost, login.EndpointSAMLACS)
|
2022-02-14 16:22:30 +00:00
|
|
|
if err != nil {
|
2024-02-26 10:49:43 +00:00
|
|
|
return nil, err
|
2022-02-14 16:22:30 +00:00
|
|
|
}
|
|
|
|
|
2023-05-05 08:25:02 +00:00
|
|
|
// robots.txt handler
|
|
|
|
robotsTxtHandler, err := robots_txt.Start()
|
|
|
|
if err != nil {
|
2024-02-26 10:49:43 +00:00
|
|
|
return nil, fmt.Errorf("unable to start robots txt handler: %w", err)
|
2023-05-05 08:25:02 +00:00
|
|
|
}
|
|
|
|
apis.RegisterHandlerOnPrefix(robots_txt.HandlerPrefix, robotsTxtHandler)
|
|
|
|
|
2023-02-15 01:52:11 +00:00
|
|
|
// TODO: Record openapi access logs?
|
2022-02-14 16:22:30 +00:00
|
|
|
openAPIHandler, err := openapi.Start()
|
|
|
|
if err != nil {
|
2024-02-26 10:49:43 +00:00
|
|
|
return nil, fmt.Errorf("unable to start openapi handler: %w", err)
|
2022-02-14 16:22:30 +00:00
|
|
|
}
|
2023-04-11 13:37:42 +00:00
|
|
|
apis.RegisterHandlerOnPrefix(openapi.HandlerPrefix, openAPIHandler)
|
2022-02-14 16:22:30 +00:00
|
|
|
|
2024-04-05 09:35:49 +00:00
|
|
|
oidcServer, err := oidc.NewServer(ctx, config.OIDC, login.DefaultLoggedOutPath, config.ExternalSecure, commands, queries, authRepo, keys.OIDC, keys.OIDCKey, eventstore, dbClient, userAgentInterceptor, instanceInterceptor.Handler, limitingAccessInterceptor, config.Log.Slog(), config.SystemDefaults.SecretHasher)
|
2022-06-07 08:04:51 +00:00
|
|
|
if err != nil {
|
2024-02-26 10:49:43 +00:00
|
|
|
return nil, fmt.Errorf("unable to start oidc provider: %w", err)
|
2022-06-07 08:04:51 +00:00
|
|
|
}
|
2023-10-25 15:44:05 +00:00
|
|
|
apis.RegisterHandlerPrefixes(oidcServer, oidcPrefixes...)
|
2022-06-07 08:04:51 +00:00
|
|
|
|
2023-09-15 14:58:45 +00:00
|
|
|
samlProvider, err := saml.NewProvider(config.SAML, config.ExternalSecure, commands, queries, authRepo, keys.OIDC, keys.SAML, eventstore, dbClient, instanceInterceptor.Handler, userAgentInterceptor, limitingAccessInterceptor)
|
2022-09-12 16:18:08 +00:00
|
|
|
if err != nil {
|
2024-02-26 10:49:43 +00:00
|
|
|
return nil, fmt.Errorf("unable to start saml provider: %w", err)
|
2022-09-12 16:18:08 +00:00
|
|
|
}
|
2023-04-11 13:37:42 +00:00
|
|
|
apis.RegisterHandlerOnPrefix(saml.HandlerPrefix, samlProvider.HttpHandler())
|
2022-09-12 16:18:08 +00:00
|
|
|
|
2023-10-25 15:44:05 +00:00
|
|
|
c, err := console.Start(config.Console, config.ExternalSecure, oidcServer.IssuerFromRequest, middleware.CallDurationHandler, instanceInterceptor.Handler, limitingAccessInterceptor, config.CustomerPortal)
|
2022-02-14 16:22:30 +00:00
|
|
|
if err != nil {
|
2024-02-26 10:49:43 +00:00
|
|
|
return nil, fmt.Errorf("unable to start console: %w", err)
|
2022-02-14 16:22:30 +00:00
|
|
|
}
|
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
|
|
|
apis.RegisterHandlerOnPrefix(path.HandlerPrefix, c)
|
|
|
|
consolePath := path.HandlerPrefix + "/"
|
2023-09-29 08:21:32 +00:00
|
|
|
l, err := login.CreateLogin(
|
|
|
|
config.Login,
|
|
|
|
commands,
|
|
|
|
queries,
|
|
|
|
authRepo,
|
|
|
|
store,
|
2024-01-17 10:16:48 +00:00
|
|
|
consolePath,
|
2023-10-25 15:44:05 +00:00
|
|
|
oidcServer.AuthCallbackURL(),
|
2023-09-29 08:21:32 +00:00
|
|
|
provider.AuthCallbackURL(samlProvider),
|
|
|
|
config.ExternalSecure,
|
|
|
|
userAgentInterceptor,
|
2023-10-25 15:44:05 +00:00
|
|
|
op.NewIssuerInterceptor(oidcServer.IssuerFromRequest).Handler,
|
2023-09-29 08:21:32 +00:00
|
|
|
provider.NewIssuerInterceptor(samlProvider.IssuerFromRequest).Handler,
|
|
|
|
instanceInterceptor.Handler,
|
|
|
|
assetsCache.Handler,
|
2024-01-17 10:16:48 +00:00
|
|
|
limitingAccessInterceptor.WithRedirect(consolePath).Handle,
|
2023-09-29 08:21:32 +00:00
|
|
|
keys.User,
|
|
|
|
keys.IDPConfig,
|
|
|
|
keys.CSRFCookieKey,
|
|
|
|
)
|
2022-02-14 16:22:30 +00:00
|
|
|
if err != nil {
|
2024-02-26 10:49:43 +00:00
|
|
|
return nil, fmt.Errorf("unable to start login: %w", err)
|
2022-02-14 16:22:30 +00:00
|
|
|
}
|
2023-04-11 13:37:42 +00:00
|
|
|
apis.RegisterHandlerOnPrefix(login.HandlerPrefix, l.Handler())
|
2023-04-19 08:46:02 +00:00
|
|
|
apis.HandleFunc(login.EndpointDeviceAuth, login.RedirectDeviceAuthToPrefix)
|
2022-02-14 16:22:30 +00:00
|
|
|
|
2023-07-10 13:27:00 +00:00
|
|
|
// After OIDC provider so that the callback endpoint can be used
|
2024-07-26 20:39:55 +00:00
|
|
|
if err := apis.RegisterService(ctx, oidc_v2beta.CreateServer(commands, queries, oidcServer, config.ExternalSecure)); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2023-10-25 15:44:05 +00:00
|
|
|
if err := apis.RegisterService(ctx, oidc_v2.CreateServer(commands, queries, oidcServer, config.ExternalSecure)); err != nil {
|
2024-02-26 10:49:43 +00:00
|
|
|
return nil, err
|
2023-07-10 13:27:00 +00:00
|
|
|
}
|
2023-04-11 13:37:42 +00:00
|
|
|
// handle grpc at last to be able to handle the root, because grpc and gateway require a lot of different prefixes
|
|
|
|
apis.RouteGRPC()
|
2024-02-26 10:49:43 +00:00
|
|
|
return apis, nil
|
2022-02-14 16:22:30 +00:00
|
|
|
}
|
|
|
|
|
2023-04-24 17:40:31 +00:00
|
|
|
func listen(ctx context.Context, router *mux.Router, port uint16, tlsConfig *tls.Config, shutdown <-chan os.Signal) error {
|
2022-02-14 16:22:30 +00:00
|
|
|
http2Server := &http2.Server{}
|
2022-06-24 12:38:22 +00:00
|
|
|
http1Server := &http.Server{Handler: h2c.NewHandler(router, http2Server), TLSConfig: tlsConfig}
|
2023-05-02 16:24:24 +00:00
|
|
|
|
2023-09-15 14:58:45 +00:00
|
|
|
lc := net.ListenConfig()
|
2023-05-02 16:24:24 +00:00
|
|
|
lis, err := lc.Listen(ctx, "tcp", fmt.Sprintf(":%d", port))
|
2022-02-14 16:22:30 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("tcp listener on %d failed: %w", port, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
errCh := make(chan error)
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
logging.Infof("server is listening on %s", lis.Addr().String())
|
2022-06-24 12:38:22 +00:00
|
|
|
if tlsConfig != nil {
|
|
|
|
//we don't need to pass the files here, because we already initialized the TLS config on the server
|
|
|
|
errCh <- http1Server.ServeTLS(lis, "", "")
|
|
|
|
} else {
|
|
|
|
errCh <- http1Server.Serve(lis)
|
|
|
|
}
|
2022-02-14 16:22:30 +00:00
|
|
|
}()
|
|
|
|
|
|
|
|
select {
|
|
|
|
case err := <-errCh:
|
|
|
|
return fmt.Errorf("error starting server: %w", err)
|
|
|
|
case <-shutdown:
|
|
|
|
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
|
|
|
|
defer cancel()
|
|
|
|
return shutdownServer(ctx, http1Server)
|
|
|
|
case <-ctx.Done():
|
|
|
|
return shutdownServer(ctx, http1Server)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func shutdownServer(ctx context.Context, server *http.Server) error {
|
|
|
|
err := server.Shutdown(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("could not shutdown gracefully: %w", err)
|
|
|
|
}
|
|
|
|
logging.New().Info("server shutdown gracefully")
|
|
|
|
return nil
|
|
|
|
}
|
2023-07-12 17:46:50 +00:00
|
|
|
|
|
|
|
func showBasicInformation(startConfig *Config) {
|
2023-07-25 05:12:13 +00:00
|
|
|
fmt.Println(color.MagentaString(figure.NewFigure("ZITADEL", "", true).String()))
|
2023-07-12 17:46:50 +00:00
|
|
|
http := "http"
|
|
|
|
if startConfig.TLS.Enabled || startConfig.ExternalSecure {
|
|
|
|
http = "https"
|
|
|
|
}
|
|
|
|
|
|
|
|
consoleURL := fmt.Sprintf("%s://%s:%v/ui/console\n", http, startConfig.ExternalDomain, startConfig.ExternalPort)
|
|
|
|
healthCheckURL := fmt.Sprintf("%s://%s:%v/debug/healthz\n", http, startConfig.ExternalDomain, startConfig.ExternalPort)
|
2024-07-16 09:53:57 +00:00
|
|
|
machineIdMethod := id.MachineIdentificationMethod()
|
2023-07-12 17:46:50 +00:00
|
|
|
|
|
|
|
insecure := !startConfig.TLS.Enabled && !startConfig.ExternalSecure
|
|
|
|
|
|
|
|
fmt.Printf(" ===============================================================\n\n")
|
2024-07-16 09:53:57 +00:00
|
|
|
fmt.Printf(" Version : %s\n", build.Version())
|
|
|
|
fmt.Printf(" TLS enabled : %v\n", startConfig.TLS.Enabled)
|
|
|
|
fmt.Printf(" External Secure : %v\n", startConfig.ExternalSecure)
|
|
|
|
fmt.Printf(" Machine Id Method : %v\n", machineIdMethod)
|
|
|
|
fmt.Printf(" Console URL : %s", color.BlueString(consoleURL))
|
|
|
|
fmt.Printf(" Health Check URL : %s", color.BlueString(healthCheckURL))
|
2023-07-12 17:46:50 +00:00
|
|
|
if insecure {
|
|
|
|
fmt.Printf("\n %s: you're using plain http without TLS. Be aware this is \n", color.RedString("Warning"))
|
|
|
|
fmt.Printf(" not a secure setup and should only be used for test systems. \n")
|
|
|
|
fmt.Printf(" Visit: %s \n", color.CyanString("https://zitadel.com/docs/self-hosting/manage/tls_modes"))
|
|
|
|
}
|
|
|
|
fmt.Printf("\n ===============================================================\n\n")
|
|
|
|
}
|
2024-02-26 10:49:43 +00:00
|
|
|
|
|
|
|
func checkExisting(values []string) func(string) bool {
|
|
|
|
return func(value string) bool {
|
|
|
|
return slices.Contains(values, value)
|
|
|
|
}
|
|
|
|
}
|