mirror of
https://github.com/zitadel/zitadel.git
synced 2025-03-01 00:47:23 +00:00

* feat: add/ remove external idps * feat: external idp add /remove * fix: auth proto * fix: handle login * feat: loginpolicy on authrequest * feat: idp providers on login * feat: link external idp * fix: check login policy on check username * feat: add mapping fields for idp config * feat: use user org id if existing * feat: use user org id if existing * feat: register external user * feat: register external user * feat: user linking * feat: user linking * feat: design external login * feat: design external login * fix: tests * fix: regenerate login design * feat: next step test linking process * feat: next step test linking process * feat: cascade remove external idps on user * fix: tests * fix: tests * feat: external idp requsts on users * fix: generate protos * feat: login styles * feat: login styles * fix: link user * fix: register user on specifig org * fix: user linking * fix: register external, linking auto * fix: remove unnecessary request from proto * fix: tests * fix: new oidc package * fix: migration version * fix: policy permissions * Update internal/ui/login/static/i18n/en.yaml Co-authored-by: Livio Amstutz <livio.a@gmail.com> * Update internal/ui/login/static/i18n/en.yaml Co-authored-by: Livio Amstutz <livio.a@gmail.com> * Update internal/ui/login/handler/renderer.go Co-authored-by: Livio Amstutz <livio.a@gmail.com> * Update internal/ui/login/handler/renderer.go Co-authored-by: Livio Amstutz <livio.a@gmail.com> * fix: pr requests * Update internal/ui/login/handler/link_users_handler.go Co-authored-by: Livio Amstutz <livio.a@gmail.com> * fix: pr requests * fix: pr requests * fix: pr requests * fix: login name size * fix: profile image light * fix: colors * fix: pr requests * fix: remove redirect uri validator * fix: remove redirect uri validator Co-authored-by: Livio Amstutz <livio.a@gmail.com>
165 lines
5.7 KiB
Go
165 lines
5.7 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"flag"
|
|
|
|
"github.com/caos/logging"
|
|
admin_es "github.com/caos/zitadel/internal/admin/repository/eventsourcing"
|
|
"github.com/caos/zitadel/internal/api"
|
|
internal_authz "github.com/caos/zitadel/internal/api/authz"
|
|
"github.com/caos/zitadel/internal/api/grpc/admin"
|
|
"github.com/caos/zitadel/internal/api/grpc/auth"
|
|
"github.com/caos/zitadel/internal/api/grpc/management"
|
|
"github.com/caos/zitadel/internal/api/oidc"
|
|
auth_es "github.com/caos/zitadel/internal/auth/repository/eventsourcing"
|
|
"github.com/caos/zitadel/internal/authz"
|
|
authz_repo "github.com/caos/zitadel/internal/authz/repository/eventsourcing"
|
|
"github.com/caos/zitadel/internal/config"
|
|
sd "github.com/caos/zitadel/internal/config/systemdefaults"
|
|
es_int "github.com/caos/zitadel/internal/eventstore"
|
|
mgmt_es "github.com/caos/zitadel/internal/management/repository/eventsourcing"
|
|
"github.com/caos/zitadel/internal/notification"
|
|
"github.com/caos/zitadel/internal/setup"
|
|
tracing "github.com/caos/zitadel/internal/tracing/config"
|
|
"github.com/caos/zitadel/internal/ui"
|
|
"github.com/caos/zitadel/internal/ui/console"
|
|
"github.com/caos/zitadel/internal/ui/login"
|
|
)
|
|
|
|
type Config struct {
|
|
Log logging.Config
|
|
Tracing tracing.TracingConfig
|
|
InternalAuthZ internal_authz.Config
|
|
SystemDefaults sd.SystemDefaults
|
|
|
|
AuthZ authz.Config
|
|
Auth auth_es.Config
|
|
Admin admin_es.Config
|
|
Mgmt mgmt_es.Config
|
|
|
|
API api.Config
|
|
UI ui.Config
|
|
|
|
Notification notification.Config
|
|
}
|
|
|
|
type setupConfig struct {
|
|
Log logging.Config
|
|
|
|
Eventstore es_int.Config
|
|
SystemDefaults sd.SystemDefaults
|
|
SetUp setup.IAMSetUp
|
|
}
|
|
|
|
var (
|
|
configPaths = config.NewArrayFlags("authz.yaml", "startup.yaml", "system-defaults.yaml")
|
|
setupPaths = config.NewArrayFlags("system-defaults.yaml", "setup.yaml")
|
|
adminEnabled = flag.Bool("admin", true, "enable admin api")
|
|
managementEnabled = flag.Bool("management", true, "enable management api")
|
|
authEnabled = flag.Bool("auth", true, "enable auth api")
|
|
oidcEnabled = flag.Bool("oidc", true, "enable oidc api")
|
|
loginEnabled = flag.Bool("login", true, "enable login ui")
|
|
consoleEnabled = flag.Bool("console", true, "enable console ui")
|
|
notificationEnabled = flag.Bool("notification", true, "enable notification handler")
|
|
localDevMode = flag.Bool("localDevMode", false, "enable local development specific configs")
|
|
)
|
|
|
|
const (
|
|
cmdStart = "start"
|
|
cmdSetup = "setup"
|
|
)
|
|
|
|
func main() {
|
|
flag.Var(configPaths, "config-files", "paths to the config files")
|
|
flag.Var(configPaths, "setup-files", "paths to the setup files")
|
|
flag.Parse()
|
|
arg := flag.Arg(0)
|
|
switch arg {
|
|
case cmdStart:
|
|
startZitadel(configPaths.Values())
|
|
case cmdSetup:
|
|
startSetup(setupPaths.Values(), *localDevMode)
|
|
default:
|
|
logging.Log("MAIN-afEQ2").Fatal("please provide an valid argument [start, setup]")
|
|
}
|
|
}
|
|
|
|
func startZitadel(configPaths []string) {
|
|
conf := new(Config)
|
|
err := config.Read(conf, configPaths...)
|
|
logging.Log("MAIN-FaF2r").OnError(err).Fatal("cannot read config")
|
|
|
|
ctx := context.Background()
|
|
authZRepo, err := authz.Start(ctx, conf.AuthZ, conf.InternalAuthZ, conf.SystemDefaults)
|
|
logging.Log("MAIN-s9KOw").OnError(err).Fatal("error starting authz repo")
|
|
var authRepo *auth_es.EsRepository
|
|
if *authEnabled || *oidcEnabled || *loginEnabled {
|
|
authRepo, err = auth_es.Start(conf.Auth, conf.InternalAuthZ, conf.SystemDefaults, authZRepo)
|
|
logging.Log("MAIN-9oRw6").OnError(err).Fatal("error starting auth repo")
|
|
}
|
|
|
|
startAPI(ctx, conf, authZRepo, authRepo)
|
|
startUI(ctx, conf, authRepo)
|
|
|
|
if *notificationEnabled {
|
|
notification.Start(ctx, conf.Notification, conf.SystemDefaults)
|
|
}
|
|
|
|
<-ctx.Done()
|
|
logging.Log("MAIN-s8d2h").Info("stopping zitadel")
|
|
}
|
|
|
|
func startUI(ctx context.Context, conf *Config, authRepo *auth_es.EsRepository) {
|
|
uis := ui.Create(conf.UI)
|
|
if *loginEnabled {
|
|
login, prefix := login.Start(conf.UI.Login, authRepo, conf.SystemDefaults, *localDevMode)
|
|
uis.RegisterHandler(prefix, login.Handler())
|
|
}
|
|
if *consoleEnabled {
|
|
consoleHandler, prefix, err := console.Start(conf.UI.Console)
|
|
logging.Log("API-AGD1f").OnError(err).Fatal("error starting console")
|
|
uis.RegisterHandler(prefix, consoleHandler)
|
|
}
|
|
uis.Start(ctx)
|
|
}
|
|
|
|
func startAPI(ctx context.Context, conf *Config, authZRepo *authz_repo.EsRepository, authRepo *auth_es.EsRepository) {
|
|
apis := api.Create(conf.API, conf.InternalAuthZ, authZRepo, conf.SystemDefaults)
|
|
roles := make([]string, len(conf.InternalAuthZ.RolePermissionMappings))
|
|
for i, role := range conf.InternalAuthZ.RolePermissionMappings {
|
|
roles[i] = role.Role
|
|
}
|
|
if *adminEnabled {
|
|
adminRepo, err := admin_es.Start(ctx, conf.Admin, conf.SystemDefaults, roles)
|
|
logging.Log("API-D42tq").OnError(err).Fatal("error starting auth repo")
|
|
apis.RegisterServer(ctx, admin.CreateServer(adminRepo))
|
|
}
|
|
if *managementEnabled {
|
|
managementRepo, err := mgmt_es.Start(conf.Mgmt, conf.SystemDefaults, roles)
|
|
logging.Log("API-Gd2qq").OnError(err).Fatal("error starting management repo")
|
|
apis.RegisterServer(ctx, management.CreateServer(managementRepo, conf.SystemDefaults))
|
|
}
|
|
if *authEnabled {
|
|
apis.RegisterServer(ctx, auth.CreateServer(authRepo))
|
|
}
|
|
if *oidcEnabled {
|
|
op := oidc.NewProvider(ctx, conf.API.OIDC, authRepo, *localDevMode)
|
|
apis.RegisterHandler("/oauth/v2", op.HttpHandler())
|
|
}
|
|
apis.Start(ctx)
|
|
}
|
|
|
|
func startSetup(configPaths []string, localDevMode bool) {
|
|
conf := new(setupConfig)
|
|
err := config.Read(conf, configPaths...)
|
|
logging.Log("MAIN-FaF2r").OnError(err).Fatal("cannot read config")
|
|
|
|
ctx := context.Background()
|
|
|
|
setup, err := setup.StartSetup(conf.Eventstore, conf.SystemDefaults)
|
|
logging.Log("SERVE-fD252").OnError(err).Panic("failed to start setup")
|
|
err = setup.Execute(ctx, conf.SetUp)
|
|
logging.Log("SERVE-djs3R").OnError(err).Panic("failed to execute setup")
|
|
}
|