2020-05-18 09:32:16 +00:00
|
|
|
package setup
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-05-25 06:21:58 +00:00
|
|
|
|
2020-05-18 09:32:16 +00:00
|
|
|
"github.com/caos/logging"
|
2020-07-08 11:56:37 +00:00
|
|
|
|
|
|
|
"github.com/caos/zitadel/internal/api/authz"
|
2020-05-18 09:32:16 +00:00
|
|
|
"github.com/caos/zitadel/internal/config/systemdefaults"
|
|
|
|
caos_errs "github.com/caos/zitadel/internal/errors"
|
2020-08-18 08:04:56 +00:00
|
|
|
es_int "github.com/caos/zitadel/internal/eventstore"
|
2020-05-18 09:32:16 +00:00
|
|
|
"github.com/caos/zitadel/internal/eventstore/models"
|
|
|
|
iam_model "github.com/caos/zitadel/internal/iam/model"
|
2020-08-18 08:04:56 +00:00
|
|
|
es_iam "github.com/caos/zitadel/internal/iam/repository/eventsourcing"
|
2020-05-18 09:32:16 +00:00
|
|
|
iam_event "github.com/caos/zitadel/internal/iam/repository/eventsourcing"
|
|
|
|
org_model "github.com/caos/zitadel/internal/org/model"
|
2020-08-18 08:04:56 +00:00
|
|
|
es_org "github.com/caos/zitadel/internal/org/repository/eventsourcing"
|
2020-05-18 09:32:16 +00:00
|
|
|
org_event "github.com/caos/zitadel/internal/org/repository/eventsourcing"
|
2020-07-08 11:56:37 +00:00
|
|
|
policy_model "github.com/caos/zitadel/internal/policy/model"
|
2020-08-18 08:04:56 +00:00
|
|
|
es_policy "github.com/caos/zitadel/internal/policy/repository/eventsourcing"
|
2020-07-08 11:56:37 +00:00
|
|
|
policy_event "github.com/caos/zitadel/internal/policy/repository/eventsourcing"
|
2020-05-18 09:32:16 +00:00
|
|
|
proj_model "github.com/caos/zitadel/internal/project/model"
|
2020-08-18 08:04:56 +00:00
|
|
|
es_proj "github.com/caos/zitadel/internal/project/repository/eventsourcing"
|
2020-05-18 09:32:16 +00:00
|
|
|
proj_event "github.com/caos/zitadel/internal/project/repository/eventsourcing"
|
|
|
|
usr_model "github.com/caos/zitadel/internal/user/model"
|
2020-08-18 08:04:56 +00:00
|
|
|
es_usr "github.com/caos/zitadel/internal/user/repository/eventsourcing"
|
2020-05-18 09:32:16 +00:00
|
|
|
usr_event "github.com/caos/zitadel/internal/user/repository/eventsourcing"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Setup struct {
|
2020-08-18 08:04:56 +00:00
|
|
|
iamID string
|
2020-08-26 07:56:23 +00:00
|
|
|
IamEvents *iam_event.IAMEventstore
|
2020-05-18 09:32:16 +00:00
|
|
|
OrgEvents *org_event.OrgEventstore
|
|
|
|
UserEvents *usr_event.UserEventstore
|
|
|
|
ProjectEvents *proj_event.ProjectEventstore
|
2020-05-29 06:44:01 +00:00
|
|
|
PolicyEvents *policy_event.PolicyEventstore
|
2020-05-18 09:32:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type initializer struct {
|
|
|
|
*Setup
|
2020-05-29 06:44:01 +00:00
|
|
|
createdUsers map[string]*usr_model.User
|
|
|
|
createdOrgs map[string]*org_model.Org
|
|
|
|
createdProjects map[string]*proj_model.Project
|
|
|
|
pwComplexityPolicy *policy_model.PasswordComplexityPolicy
|
2020-05-18 09:32:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const (
|
2020-06-23 12:47:47 +00:00
|
|
|
OrgOwnerRole = "ORG_OWNER"
|
|
|
|
SetupUser = "SETUP"
|
|
|
|
OIDCResponseTypeCode = "CODE"
|
|
|
|
OIDCResponseTypeIDToken = "ID_TOKEN"
|
2020-07-09 13:52:20 +00:00
|
|
|
OIDCResponseTypeToken = "ID_TOKEN TOKEN"
|
2020-06-23 12:47:47 +00:00
|
|
|
OIDCGrantTypeAuthorizationCode = "AUTHORIZATION_CODE"
|
|
|
|
OIDCGrantTypeImplicit = "IMPLICIT"
|
|
|
|
OIDCGrantTypeRefreshToken = "REFRESH_TOKEN"
|
|
|
|
OIDCApplicationTypeNative = "NATIVE"
|
|
|
|
OIDCApplicationTypeUserAgent = "USER_AGENT"
|
|
|
|
OIDCApplicationTypeWeb = "WEB"
|
|
|
|
OIDCAuthMethodTypeNone = "NONE"
|
|
|
|
OIDCAuthMethodTypeBasic = "BASIC"
|
|
|
|
OIDCAuthMethodTypePost = "POST"
|
2020-05-18 09:32:16 +00:00
|
|
|
)
|
|
|
|
|
2020-08-18 08:04:56 +00:00
|
|
|
func StartSetup(esConfig es_int.Config, sd systemdefaults.SystemDefaults) (*Setup, error) {
|
|
|
|
setup := &Setup{
|
|
|
|
iamID: sd.IamID,
|
|
|
|
}
|
|
|
|
es, err := es_int.Start(esConfig)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2020-08-26 07:56:23 +00:00
|
|
|
setup.IamEvents, err = es_iam.StartIAM(es_iam.IAMConfig{
|
2020-08-18 08:04:56 +00:00
|
|
|
Eventstore: es,
|
|
|
|
Cache: esConfig.Cache,
|
|
|
|
}, sd)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
setup.OrgEvents = es_org.StartOrg(es_org.OrgConfig{Eventstore: es, IAMDomain: sd.Domain}, sd)
|
|
|
|
|
|
|
|
setup.ProjectEvents, err = es_proj.StartProject(es_proj.ProjectConfig{
|
|
|
|
Eventstore: es,
|
|
|
|
Cache: esConfig.Cache,
|
|
|
|
}, sd)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
setup.UserEvents, err = es_usr.StartUser(es_usr.UserConfig{
|
|
|
|
Eventstore: es,
|
|
|
|
Cache: esConfig.Cache,
|
|
|
|
}, sd)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
setup.PolicyEvents, err = es_policy.StartPolicy(es_policy.PolicyConfig{
|
|
|
|
Eventstore: es,
|
|
|
|
Cache: esConfig.Cache,
|
|
|
|
}, sd)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2020-05-18 09:32:16 +00:00
|
|
|
}
|
2020-08-18 08:04:56 +00:00
|
|
|
return setup, nil
|
2020-05-18 09:32:16 +00:00
|
|
|
}
|
|
|
|
|
2020-08-18 08:04:56 +00:00
|
|
|
func (s *Setup) Execute(ctx context.Context, setUpConfig IAMSetUp) error {
|
2020-08-26 07:56:23 +00:00
|
|
|
iam, err := s.IamEvents.IAMByID(ctx, s.iamID)
|
2020-05-18 09:32:16 +00:00
|
|
|
if err != nil && !caos_errs.IsNotFound(err) {
|
|
|
|
return err
|
|
|
|
}
|
2020-08-18 08:04:56 +00:00
|
|
|
if iam != nil && (iam.SetUpStarted || iam.SetUpDone) {
|
2020-05-18 09:32:16 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-05-25 06:21:58 +00:00
|
|
|
logging.Log("SETUP-hwG32").Info("starting setup")
|
|
|
|
ctx = setSetUpContextData(ctx, s.iamID)
|
2020-08-18 08:04:56 +00:00
|
|
|
iam, err = s.IamEvents.StartSetup(ctx, s.iamID)
|
2020-05-25 06:21:58 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2020-05-18 09:32:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
setUp := &initializer{
|
|
|
|
Setup: s,
|
|
|
|
createdUsers: make(map[string]*usr_model.User),
|
|
|
|
createdOrgs: make(map[string]*org_model.Org),
|
|
|
|
createdProjects: make(map[string]*proj_model.Project),
|
|
|
|
}
|
|
|
|
|
2020-08-26 07:56:23 +00:00
|
|
|
err = setUp.loginPolicy(ctx, setUpConfig.DefaultLoginPolicy)
|
|
|
|
if err != nil {
|
|
|
|
logging.Log("SETUP-Hdu8S").WithError(err).Error("unable to create login policy")
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-08-18 08:04:56 +00:00
|
|
|
pwComplexityPolicy, err := s.PolicyEvents.GetPasswordComplexityPolicy(ctx, policy_model.DefaultPolicy)
|
2020-05-29 06:44:01 +00:00
|
|
|
if err != nil {
|
|
|
|
logging.Log("SETUP-9osWF").WithError(err).Error("unable to read complexity policy")
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
setUp.pwComplexityPolicy = pwComplexityPolicy
|
|
|
|
|
2020-08-18 08:04:56 +00:00
|
|
|
err = setUp.orgs(ctx, setUpConfig.Orgs)
|
2020-05-18 09:32:16 +00:00
|
|
|
if err != nil {
|
|
|
|
logging.Log("SETUP-p4oWq").WithError(err).Error("unable to set up orgs")
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx = setSetUpContextData(ctx, s.iamID)
|
2020-08-18 08:04:56 +00:00
|
|
|
err = setUp.iamOwners(ctx, setUpConfig.Owners)
|
2020-05-18 09:32:16 +00:00
|
|
|
if err != nil {
|
|
|
|
logging.Log("SETUP-WHr01").WithError(err).Error("unable to set up iam owners")
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-08-18 08:04:56 +00:00
|
|
|
err = setUp.setGlobalOrg(ctx, setUpConfig.GlobalOrg)
|
2020-05-18 09:32:16 +00:00
|
|
|
if err != nil {
|
|
|
|
logging.Log("SETUP-0874m").WithError(err).Error("unable to set global org")
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-08-18 08:04:56 +00:00
|
|
|
err = setUp.setIamProject(ctx, setUpConfig.IAMProject)
|
2020-05-18 09:32:16 +00:00
|
|
|
if err != nil {
|
2020-06-05 05:50:04 +00:00
|
|
|
logging.Log("SETUP-kaWjq").WithError(err).Error("unable to set zitadel project")
|
2020-05-18 09:32:16 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-08-18 08:04:56 +00:00
|
|
|
iam, err = s.IamEvents.SetupDone(ctx, s.iamID)
|
2020-05-18 09:32:16 +00:00
|
|
|
if err != nil {
|
2020-05-25 06:21:58 +00:00
|
|
|
logging.Log("SETUP-de342").WithError(err).Error("unable to finish setup")
|
2020-05-18 09:32:16 +00:00
|
|
|
return err
|
|
|
|
}
|
2020-05-25 06:21:58 +00:00
|
|
|
logging.Log("SETUP-ds31h").Info("setup done")
|
2020-05-18 09:32:16 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-08-26 07:56:23 +00:00
|
|
|
func (setUp *initializer) loginPolicy(ctx context.Context, policy LoginPolicy) error {
|
|
|
|
logging.Log("SETUP-4djul").Info("setting up login policy")
|
|
|
|
loginPolicy := &iam_model.LoginPolicy{
|
|
|
|
ObjectRoot: models.ObjectRoot{
|
|
|
|
AggregateID: setUp.iamID,
|
|
|
|
},
|
|
|
|
AllowRegister: policy.AllowRegister,
|
|
|
|
AllowUsernamePassword: policy.AllowUsernamePassword,
|
|
|
|
AllowExternalIdp: policy.AllowExternalIdp,
|
|
|
|
}
|
|
|
|
_, err := setUp.IamEvents.AddLoginPolicy(ctx, loginPolicy)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-08-18 08:04:56 +00:00
|
|
|
func (setUp *initializer) orgs(ctx context.Context, orgs []Org) error {
|
2020-05-25 06:21:58 +00:00
|
|
|
logging.Log("SETUP-dsTh3").Info("setting up orgs")
|
2020-05-18 09:32:16 +00:00
|
|
|
for _, iamOrg := range orgs {
|
|
|
|
org, err := setUp.org(ctx, iamOrg)
|
|
|
|
if err != nil {
|
|
|
|
logging.LogWithFields("SETUP-IlLif", "Org", iamOrg.Name).WithError(err).Error("unable to create org")
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
setUp.createdOrgs[iamOrg.Name] = org
|
|
|
|
|
2020-08-26 07:56:23 +00:00
|
|
|
var policy *org_model.OrgIAMPolicy
|
2020-06-16 09:40:18 +00:00
|
|
|
if iamOrg.OrgIamPolicy {
|
|
|
|
policy, err = setUp.iamorgpolicy(ctx, org)
|
|
|
|
if err != nil {
|
2020-08-26 07:56:23 +00:00
|
|
|
logging.LogWithFields("SETUP-IlLif", "Org IAM Policy", iamOrg.Name).WithError(err).Error("unable to create iam org policy")
|
2020-06-16 09:40:18 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
} else {
|
2020-08-26 07:56:23 +00:00
|
|
|
policy, err = setUp.OrgEvents.GetOrgIAMPolicy(ctx, policy_model.DefaultPolicy)
|
2020-06-16 09:40:18 +00:00
|
|
|
if err != nil {
|
2020-08-26 07:56:23 +00:00
|
|
|
logging.LogWithFields("SETUP-IS8wS", "Org IAM Policy", iamOrg.Name).WithError(err).Error("unable to get default iam org policy")
|
2020-06-16 09:40:18 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-18 09:32:16 +00:00
|
|
|
ctx = setSetUpContextData(ctx, org.AggregateID)
|
2020-06-16 09:40:18 +00:00
|
|
|
err = setUp.users(ctx, iamOrg.Users, policy)
|
2020-05-18 09:32:16 +00:00
|
|
|
if err != nil {
|
|
|
|
logging.LogWithFields("SETUP-8zfwz", "Org", iamOrg.Name).WithError(err).Error("unable to set up org users")
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = setUp.orgOwners(ctx, org, iamOrg.Owners)
|
|
|
|
if err != nil {
|
|
|
|
logging.LogWithFields("SETUP-0874m", "Org", iamOrg.Name).WithError(err).Error("unable to set up org owners")
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-09-17 14:48:14 +00:00
|
|
|
err = setUp.projects(ctx, iamOrg.Projects, setUp.createdUsers[iamOrg.Owners[0]].AggregateID)
|
2020-05-18 09:32:16 +00:00
|
|
|
if err != nil {
|
|
|
|
logging.LogWithFields("SETUP-wUzqY", "Org", iamOrg.Name).WithError(err).Error("unable to set up org projects")
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2020-05-25 06:21:58 +00:00
|
|
|
logging.Log("SETUP-dgjT4").Info("orgs set up")
|
2020-05-18 09:32:16 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-08-18 08:04:56 +00:00
|
|
|
func (setUp *initializer) org(ctx context.Context, org Org) (*org_model.Org, error) {
|
2020-05-18 09:32:16 +00:00
|
|
|
ctx = setSetUpContextData(ctx, "")
|
|
|
|
createOrg := &org_model.Org{
|
2020-06-16 09:40:18 +00:00
|
|
|
Name: org.Name,
|
2020-07-08 11:56:37 +00:00
|
|
|
Domains: []*org_model.OrgDomain{{Domain: org.Domain}},
|
2020-05-18 09:32:16 +00:00
|
|
|
}
|
2020-08-18 08:04:56 +00:00
|
|
|
return setUp.OrgEvents.CreateOrg(ctx, createOrg, nil)
|
2020-05-18 09:32:16 +00:00
|
|
|
}
|
|
|
|
|
2020-08-26 07:56:23 +00:00
|
|
|
func (setUp *initializer) iamorgpolicy(ctx context.Context, org *org_model.Org) (*org_model.OrgIAMPolicy, error) {
|
2020-06-16 09:40:18 +00:00
|
|
|
ctx = setSetUpContextData(ctx, org.AggregateID)
|
2020-08-26 07:56:23 +00:00
|
|
|
policy := &org_model.OrgIAMPolicy{
|
2020-06-16 09:40:18 +00:00
|
|
|
ObjectRoot: models.ObjectRoot{AggregateID: org.AggregateID},
|
|
|
|
UserLoginMustBeDomain: false,
|
|
|
|
}
|
2020-08-26 07:56:23 +00:00
|
|
|
return setUp.OrgEvents.AddOrgIAMPolicy(ctx, policy)
|
2020-06-16 09:40:18 +00:00
|
|
|
}
|
|
|
|
|
2020-05-18 09:32:16 +00:00
|
|
|
func (setUp *initializer) iamOwners(ctx context.Context, owners []string) error {
|
2020-05-25 06:21:58 +00:00
|
|
|
logging.Log("SETUP-dtxfj").Info("setting iam owners")
|
2020-05-18 09:32:16 +00:00
|
|
|
for _, iamOwner := range owners {
|
|
|
|
user, ok := setUp.createdUsers[iamOwner]
|
|
|
|
if !ok {
|
|
|
|
logging.LogWithFields("SETUP-8siew", "Owner", iamOwner).Error("unable to add user to iam members")
|
|
|
|
return caos_errs.ThrowPreconditionFailedf(nil, "SETUP-su6L3", "unable to add user to iam members")
|
|
|
|
}
|
2020-08-26 07:56:23 +00:00
|
|
|
_, err := setUp.IamEvents.AddIAMMember(ctx, &iam_model.IAMMember{ObjectRoot: models.ObjectRoot{AggregateID: setUp.iamID}, UserID: user.AggregateID, Roles: []string{"IAM_OWNER"}})
|
2020-05-18 09:32:16 +00:00
|
|
|
if err != nil {
|
|
|
|
logging.Log("SETUP-LM7rI").WithError(err).Error("unable to add iam administrator to iam members as owner")
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2020-05-25 06:21:58 +00:00
|
|
|
logging.Log("SETUP-fg5aq").Info("iam owners set")
|
2020-05-18 09:32:16 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-08-18 08:04:56 +00:00
|
|
|
func (setUp *initializer) setGlobalOrg(ctx context.Context, globalOrgName string) error {
|
2020-05-25 06:21:58 +00:00
|
|
|
logging.Log("SETUP-dsj75").Info("setting global org")
|
2020-08-18 08:04:56 +00:00
|
|
|
globalOrg, ok := setUp.createdOrgs[globalOrgName]
|
2020-05-18 09:32:16 +00:00
|
|
|
if !ok {
|
2020-08-18 08:04:56 +00:00
|
|
|
logging.LogWithFields("SETUP-FBhs9", "GlobalOrg", globalOrgName).Error("global org not created")
|
|
|
|
return caos_errs.ThrowPreconditionFailedf(nil, "SETUP-4GwU7", "global org not created: %v", globalOrgName)
|
2020-05-18 09:32:16 +00:00
|
|
|
}
|
|
|
|
|
2020-08-18 08:04:56 +00:00
|
|
|
if _, err := setUp.IamEvents.SetGlobalOrg(ctx, setUp.iamID, globalOrg.AggregateID); err != nil {
|
2020-05-25 06:21:58 +00:00
|
|
|
logging.Log("SETUP-uGMA3").WithError(err).Error("unable to set global org on iam")
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
logging.Log("SETUP-d32h1").Info("global org set")
|
|
|
|
return nil
|
2020-05-18 09:32:16 +00:00
|
|
|
}
|
|
|
|
|
2020-08-18 08:04:56 +00:00
|
|
|
func (setUp *initializer) setIamProject(ctx context.Context, iamProjectName string) error {
|
2020-05-25 06:21:58 +00:00
|
|
|
logging.Log("SETUP-HE3qa").Info("setting iam project")
|
2020-08-18 08:04:56 +00:00
|
|
|
iamProject, ok := setUp.createdProjects[iamProjectName]
|
2020-05-18 09:32:16 +00:00
|
|
|
if !ok {
|
2020-08-26 07:56:23 +00:00
|
|
|
logging.LogWithFields("SETUP-SJFWP", "IAM Project", iamProjectName).Error("iam project created")
|
2020-08-18 08:04:56 +00:00
|
|
|
return caos_errs.ThrowPreconditionFailedf(nil, "SETUP-sGmQt", "iam project not created: %v", iamProjectName)
|
2020-05-18 09:32:16 +00:00
|
|
|
}
|
|
|
|
|
2020-08-26 07:56:23 +00:00
|
|
|
if _, err := setUp.IamEvents.SetIAMProject(ctx, setUp.iamID, iamProject.AggregateID); err != nil {
|
2020-05-25 06:21:58 +00:00
|
|
|
logging.Log("SETUP-i1pNh").WithError(err).Error("unable to set iam project on iam")
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
logging.Log("SETUP-d7WEU").Info("iam project set")
|
|
|
|
return nil
|
2020-05-18 09:32:16 +00:00
|
|
|
}
|
|
|
|
|
2020-08-26 07:56:23 +00:00
|
|
|
func (setUp *initializer) users(ctx context.Context, users []User, orgPolicy *org_model.OrgIAMPolicy) error {
|
2020-05-18 09:32:16 +00:00
|
|
|
for _, user := range users {
|
2020-06-16 09:40:18 +00:00
|
|
|
created, err := setUp.user(ctx, user, orgPolicy)
|
2020-05-18 09:32:16 +00:00
|
|
|
if err != nil {
|
|
|
|
logging.LogWithFields("SETUP-9soer", "Email", user.Email).WithError(err).Error("unable to create iam user")
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
setUp.createdUsers[user.Email] = created
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-08-26 07:56:23 +00:00
|
|
|
func (setUp *initializer) user(ctx context.Context, user User, orgPolicy *org_model.OrgIAMPolicy) (*usr_model.User, error) {
|
2020-05-18 09:32:16 +00:00
|
|
|
createUser := &usr_model.User{
|
feat: split users into human and machine (#470)
* feat(management): service accounts
* chore: current go version
* init
* refactor: apis
* feat(internal): start impl of service account
* chore: start impl of machine/human users
* code compiles
* fix: tests
* fix: tests
* fix: add new event types to switches
* chore: add cases to event types
* fix(management): definitive proto messages
* fix: machine/human
* fix: add missing tables as todos
* fix: remove unused permissions
* fix: refactoring
* fix: refactor
* fix: human registered
* fix: user id
* fix: logid
* fix: proto remove //equal
* chore(management): remove no comment
* fix: human mfas
* fix: user subobjects
* chore: rename existing to better name
* fix: username in user (#634)
* fix: username in user
* fix: username
* fix remove unused code
* fix add validations
* fix: use new user in all apis
* fix: regexp for username in api
* fix: fill user data for human and machine (#638)
* fix: fill Display name grant/member handlers
fix: add description to grant/member objects in api
fix: check if user is human in login
* fix: remove description from member and grant
* chore: remove todos
* feat: machine keys
* fix: implement missing parts
* feat: machine key management view
* fix: remove keys from machine view
* fix: set default expiration date
* fix: get key by ids
* feat: add machine keys in proto
* feat: machine keys
* fix: add migration
* fix: mig
* fix: correct method name
* feat: user search
* feat: user search
* fix: log ids
* fix partial authconfig prompt, domain c perm
* membership read check
* contributor refresh trigger, observe org write
* fix: migrations
* fix(console): machine build (#660)
* frontend 1
* fix html bindings
* trailing comma
* user permissions, project deactivate
* fix(console): human view (#661)
* fix search user view, user detail form
* rm log
* feat(console): user services list and create (#663)
* fix search user view, user detail form
* rm log
* machine list
* generic table component
* create user service
* proove table for undefined values
* tmp disable user link if machine
* lint
* lint styles
* user table lint
* Update console/src/assets/i18n/de.json
Co-authored-by: Florian Forster <florian@caos.ch>
* feat(console): service user detail view, keys cr_d, fix search user autocomplete (#664)
* service users for sidenav, routing
* i18n
* back routes
* machine detail form
* update machine detail, fix svc user grants
* keys table
* add key dialog, timestamp creation
* check permission on create, delete, fix selection
* lint ts, scss
* Update console/src/assets/i18n/de.json
* Apply suggestions from code review
Co-authored-by: Florian Forster <florian@caos.ch>
* allow user grants for project.write
* management service
* fix mgmt service
* feat: Machine keys (#655)
* fix: memberships (#633)
* feat: add iam members to memberships
* fix: search project grants
* fix: rename
* feat: idp and login policy configurations (#619)
* feat: oidc config
* fix: oidc configurations
* feat: oidc idp config
* feat: add oidc config test
* fix: tests
* fix: tests
* feat: translate new events
* feat: idp eventstore
* feat: idp eventstore
* fix: tests
* feat: command side idp
* feat: query side idp
* feat: idp config on org
* fix: tests
* feat: authz idp on org
* feat: org idps
* feat: login policy
* feat: login policy
* feat: login policy
* feat: add idp func on login policy
* feat: add validation to loginpolicy and idp provider
* feat: add default login policy
* feat: login policy on org
* feat: login policy on org
* fix: id config handlers
* fix: id config handlers
* fix: create idp on org
* fix: create idp on org
* fix: not existing idp config
* fix: default login policy
* fix: add login policy on org
* fix: idp provider search on org
* fix: test
* fix: remove idp on org
* fix: test
* fix: test
* fix: remove admin idp
* fix: logo src as byte
* fix: migration
* fix: tests
* Update internal/iam/repository/eventsourcing/iam.go
Co-authored-by: Silvan <silvan.reusser@gmail.com>
* Update internal/iam/repository/eventsourcing/iam_test.go
Co-authored-by: Silvan <silvan.reusser@gmail.com>
* Update internal/iam/repository/eventsourcing/iam_test.go
Co-authored-by: Silvan <silvan.reusser@gmail.com>
* Update internal/iam/repository/eventsourcing/model/login_policy.go
Co-authored-by: Silvan <silvan.reusser@gmail.com>
* Update internal/iam/repository/eventsourcing/model/login_policy.go
Co-authored-by: Silvan <silvan.reusser@gmail.com>
* Update internal/org/repository/eventsourcing/org_test.go
Co-authored-by: Silvan <silvan.reusser@gmail.com>
* Update internal/iam/repository/eventsourcing/model/login_policy_test.go
Co-authored-by: Silvan <silvan.reusser@gmail.com>
* Update internal/iam/repository/eventsourcing/model/login_policy_test.go
Co-authored-by: Silvan <silvan.reusser@gmail.com>
* fix: pr comments
* fix: tests
* Update types.go
* fix: merge request changes
* fix: reduce optimization
Co-authored-by: Silvan <silvan.reusser@gmail.com>
Co-authored-by: Livio Amstutz <livio.a@gmail.com>
* fix: reread user mfas, preferred loginname as otp account name (#636)
* fix: reread user mfas
* fix: use preferred login name as otp account name
* fix: tests
* fix: reduce (#635)
* fix: management reduce optimization
* fix: reduce optimization
* fix: reduce optimization
* fix: merge master
* chore(deps): bump github.com/gorilla/schema from 1.1.0 to 1.2.0 (#627)
Bumps [github.com/gorilla/schema](https://github.com/gorilla/schema) from 1.1.0 to 1.2.0.
- [Release notes](https://github.com/gorilla/schema/releases)
- [Commits](https://github.com/gorilla/schema/compare/v1.1.0...v1.2.0)
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* chore(deps): bump github.com/gorilla/mux from 1.7.4 to 1.8.0 (#624)
Bumps [github.com/gorilla/mux](https://github.com/gorilla/mux) from 1.7.4 to 1.8.0.
- [Release notes](https://github.com/gorilla/mux/releases)
- [Commits](https://github.com/gorilla/mux/compare/v1.7.4...v1.8.0)
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* chore(deps): bump github.com/DATA-DOG/go-sqlmock from 1.4.1 to 1.5.0 (#591)
Bumps [github.com/DATA-DOG/go-sqlmock](https://github.com/DATA-DOG/go-sqlmock) from 1.4.1 to 1.5.0.
- [Release notes](https://github.com/DATA-DOG/go-sqlmock/releases)
- [Commits](https://github.com/DATA-DOG/go-sqlmock/compare/v1.4.1...v1.5.0)
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* chore: auto assign issues and PR to ZTIADEL project board (#643)
* Create main.yml
* Update main.yml
Co-authored-by: Livio Amstutz <livio.a@gmail.com>
* fix(console): project grant members, update deps (#645)
* fix: searchprojectgrantmembers
* chore(deps-dev): bump @angular/cli from 10.0.6 to 10.0.7 in /console (#622)
Bumps [@angular/cli](https://github.com/angular/angular-cli) from 10.0.6 to 10.0.7.
- [Release notes](https://github.com/angular/angular-cli/releases)
- [Commits](https://github.com/angular/angular-cli/compare/v10.0.6...v10.0.7)
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* chore(deps-dev): bump @angular-devkit/build-angular in /console (#626)
Bumps [@angular-devkit/build-angular](https://github.com/angular/angular-cli) from 0.1000.6 to 0.1000.7.
- [Release notes](https://github.com/angular/angular-cli/releases)
- [Commits](https://github.com/angular/angular-cli/commits)
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Max Peintner <max@caos.ch>
* chore(deps-dev): bump @types/jasmine from 3.5.12 to 3.5.13 in /console (#623)
Bumps [@types/jasmine](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/jasmine) from 3.5.12 to 3.5.13.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/jasmine)
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* chore(deps-dev): bump ts-node from 8.10.2 to 9.0.0 in /console (#629)
Bumps [ts-node](https://github.com/TypeStrong/ts-node) from 8.10.2 to 9.0.0.
- [Release notes](https://github.com/TypeStrong/ts-node/releases)
- [Commits](https://github.com/TypeStrong/ts-node/compare/v8.10.2...v9.0.0)
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* update packlock
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* chore: delete main.yml (#648)
* fix: usergrant (#650)
* fix(console): mfa refresh after verification, member eventemitter (#651)
* refresh mfa
* fix: detail link from contributors
* lint
* feat: add domain verification notification (#649)
* fix: dont (re)generate client secret with auth type none
* fix(cors): allow Origin from request
* feat: add origin allow list and fix some core issues
* rename migration
* fix UserIDsByDomain
* feat: send email to users after domain claim
* username
* check origin on userinfo
* update oidc pkg
* fix: add migration 1.6
* change username
* change username
* remove unique email aggregate
* change username in mgmt
* search global user by login name
* fix test
* change user search in angular
* fix tests
* merge
* userview in angular
* fix merge
* Update pkg/grpc/management/proto/management.proto
Co-authored-by: Fabi <38692350+fgerschwiler@users.noreply.github.com>
* Update internal/notification/static/i18n/de.yaml
Co-authored-by: Fabi <38692350+fgerschwiler@users.noreply.github.com>
* fix
Co-authored-by: Fabi <38692350+fgerschwiler@users.noreply.github.com>
* fix: translation (#647)
* fix: translation
* fix: translation
* fix: translation
* fix: remove unused code
* fix: log err
* fix: migration numbers (#652)
* chore: issue / feature templates (#642)
* feat: machine keys
* fix: implement missing parts
* feat: machine key management view
* fix: remove keys from machine view
* feat: global org read (#657)
* fix: set default expiration date
* fix: get key by ids
* feat: add machine keys in proto
* feat: machine keys
* fix: add migration
* fix: mig
* fix: correct method name
* feat: user search
* feat: user search
* fix: log ids
* fix: migrations
* fix(console): machine build (#660)
* frontend 1
* fix html bindings
* trailing comma
* fix(console): human view (#661)
* fix search user view, user detail form
* rm log
* feat(console): user services list and create (#663)
* fix search user view, user detail form
* rm log
* machine list
* generic table component
* create user service
* proove table for undefined values
* tmp disable user link if machine
* lint
* lint styles
* user table lint
* Update console/src/assets/i18n/de.json
Co-authored-by: Florian Forster <florian@caos.ch>
* feat(console): service user detail view, keys cr_d, fix search user autocomplete (#664)
* service users for sidenav, routing
* i18n
* back routes
* machine detail form
* update machine detail, fix svc user grants
* keys table
* add key dialog, timestamp creation
* check permission on create, delete, fix selection
* lint ts, scss
* Update console/src/assets/i18n/de.json
* Apply suggestions from code review
Co-authored-by: Florian Forster <florian@caos.ch>
* refactor: protos
* fix(management): key expiration date
* fix: check if user is human
* fix: marshal key details
* fix: correct generate login names
* fix: logid
Co-authored-by: Fabi <38692350+fgerschwiler@users.noreply.github.com>
Co-authored-by: Livio Amstutz <livio.a@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Max Peintner <max@caos.ch>
Co-authored-by: Fabiennne <fabienne.gerschwiler@gmail.com>
Co-authored-by: Florian Forster <florian@caos.ch>
* fix: naming
* refactor: findings
* fix: username
* fix: mfa upper case
* fix: tests
* fix: add translations
* reactivatemyorg req typeö
* fix: projectType for console
* fix: user changes
* fix: translate events
* fix: event type translation
* fix: remove unused types
Co-authored-by: Fabiennne <fabienne.gerschwiler@gmail.com>
Co-authored-by: Max Peintner <max@caos.ch>
Co-authored-by: Florian Forster <florian@caos.ch>
Co-authored-by: Fabi <38692350+fgerschwiler@users.noreply.github.com>
Co-authored-by: Livio Amstutz <livio.a@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2020-08-31 15:48:01 +00:00
|
|
|
UserName: user.UserName,
|
|
|
|
Human: &usr_model.Human{
|
|
|
|
Profile: &usr_model.Profile{
|
|
|
|
FirstName: user.FirstName,
|
|
|
|
LastName: user.LastName,
|
|
|
|
},
|
|
|
|
Email: &usr_model.Email{
|
|
|
|
EmailAddress: user.Email,
|
|
|
|
IsEmailVerified: true,
|
|
|
|
},
|
|
|
|
Password: &usr_model.Password{
|
|
|
|
SecretString: user.Password,
|
|
|
|
},
|
2020-05-18 09:32:16 +00:00
|
|
|
},
|
|
|
|
}
|
2020-08-18 08:04:56 +00:00
|
|
|
return setUp.UserEvents.CreateUser(ctx, createUser, setUp.pwComplexityPolicy, orgPolicy)
|
2020-05-18 09:32:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (setUp *initializer) orgOwners(ctx context.Context, org *org_model.Org, owners []string) error {
|
|
|
|
for _, orgOwner := range owners {
|
|
|
|
user, ok := setUp.createdUsers[orgOwner]
|
|
|
|
if !ok {
|
|
|
|
logging.LogWithFields("SETUP-s9ilr", "Owner", orgOwner).Error("unable to add user to org members")
|
|
|
|
return caos_errs.ThrowPreconditionFailedf(nil, "SETUP-s0prs", "unable to add user to org members: %v", orgOwner)
|
|
|
|
}
|
|
|
|
err := setUp.orgOwner(ctx, org, user)
|
|
|
|
if err != nil {
|
|
|
|
logging.Log("SETUP-s90oe").WithError(err).Error("unable to add global org admin to members of global org")
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (setUp *initializer) orgOwner(ctx context.Context, org *org_model.Org, user *usr_model.User) error {
|
|
|
|
addMember := &org_model.OrgMember{
|
|
|
|
ObjectRoot: models.ObjectRoot{AggregateID: org.AggregateID},
|
|
|
|
UserID: user.AggregateID,
|
|
|
|
Roles: []string{OrgOwnerRole},
|
|
|
|
}
|
2020-08-18 08:04:56 +00:00
|
|
|
_, err := setUp.OrgEvents.AddOrgMember(ctx, addMember)
|
2020-05-18 09:32:16 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-09-17 14:48:14 +00:00
|
|
|
func (setUp *initializer) projects(ctx context.Context, projects []Project, ownerID string) error {
|
|
|
|
ctxData := authz.GetCtxData(ctx)
|
|
|
|
ctxData.UserID = ownerID
|
|
|
|
projectCtx := authz.SetCtxData(ctx, ctxData)
|
|
|
|
|
2020-05-18 09:32:16 +00:00
|
|
|
for _, project := range projects {
|
2020-09-17 14:48:14 +00:00
|
|
|
createdProject, err := setUp.project(projectCtx, project)
|
2020-05-18 09:32:16 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
setUp.createdProjects[createdProject.Name] = createdProject
|
|
|
|
for _, oidc := range project.OIDCApps {
|
2020-05-25 06:21:58 +00:00
|
|
|
app, err := setUp.oidcApp(ctx, createdProject, oidc)
|
2020-05-18 09:32:16 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-05-25 06:21:58 +00:00
|
|
|
logging.LogWithFields("SETUP-asd32f", "name", app.Name, "clientID", app.OIDCConfig.ClientID).Info("created OIDC application")
|
2020-05-18 09:32:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-08-18 08:04:56 +00:00
|
|
|
func (setUp *initializer) project(ctx context.Context, project Project) (*proj_model.Project, error) {
|
2020-05-18 09:32:16 +00:00
|
|
|
addProject := &proj_model.Project{
|
|
|
|
Name: project.Name,
|
|
|
|
}
|
2020-09-01 14:38:34 +00:00
|
|
|
return setUp.ProjectEvents.CreateProject(ctx, addProject, false)
|
2020-05-18 09:32:16 +00:00
|
|
|
}
|
|
|
|
|
2020-08-18 08:04:56 +00:00
|
|
|
func (setUp *initializer) oidcApp(ctx context.Context, project *proj_model.Project, oidc OIDCApp) (*proj_model.Application, error) {
|
2020-05-18 09:32:16 +00:00
|
|
|
addOIDCApp := &proj_model.Application{
|
|
|
|
ObjectRoot: models.ObjectRoot{AggregateID: project.AggregateID},
|
|
|
|
Name: oidc.Name,
|
|
|
|
OIDCConfig: &proj_model.OIDCConfig{
|
|
|
|
RedirectUris: oidc.RedirectUris,
|
|
|
|
ResponseTypes: getOIDCResponseTypes(oidc.ResponseTypes),
|
|
|
|
GrantTypes: getOIDCGrantTypes(oidc.GrantTypes),
|
|
|
|
ApplicationType: getOIDCApplicationType(oidc.ApplicationType),
|
|
|
|
AuthMethodType: getOIDCAuthMethod(oidc.AuthMethodType),
|
|
|
|
PostLogoutRedirectUris: oidc.PostLogoutRedirectUris,
|
2020-08-18 08:04:56 +00:00
|
|
|
DevMode: oidc.DevMode,
|
2020-05-18 09:32:16 +00:00
|
|
|
},
|
|
|
|
}
|
2020-08-18 08:04:56 +00:00
|
|
|
return setUp.ProjectEvents.AddApplication(ctx, addOIDCApp)
|
2020-05-18 09:32:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func getOIDCResponseTypes(responseTypes []string) []proj_model.OIDCResponseType {
|
|
|
|
types := make([]proj_model.OIDCResponseType, len(responseTypes))
|
|
|
|
for i, t := range responseTypes {
|
|
|
|
types[i] = getOIDCResponseType(t)
|
|
|
|
}
|
|
|
|
return types
|
|
|
|
}
|
|
|
|
|
|
|
|
func getOIDCResponseType(responseType string) proj_model.OIDCResponseType {
|
|
|
|
switch responseType {
|
2020-06-23 12:47:47 +00:00
|
|
|
case OIDCResponseTypeCode:
|
|
|
|
return proj_model.OIDCResponseTypeCode
|
|
|
|
case OIDCResponseTypeIDToken:
|
|
|
|
return proj_model.OIDCResponseTypeIDToken
|
|
|
|
case OIDCResponseTypeToken:
|
2020-07-09 13:52:20 +00:00
|
|
|
return proj_model.OIDCResponseTypeIDTokenToken
|
2020-06-23 12:47:47 +00:00
|
|
|
}
|
|
|
|
return proj_model.OIDCResponseTypeCode
|
2020-05-18 09:32:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func getOIDCGrantTypes(grantTypes []string) []proj_model.OIDCGrantType {
|
|
|
|
types := make([]proj_model.OIDCGrantType, len(grantTypes))
|
|
|
|
for i, t := range grantTypes {
|
|
|
|
types[i] = getOIDCGrantType(t)
|
|
|
|
}
|
|
|
|
return types
|
|
|
|
}
|
|
|
|
|
|
|
|
func getOIDCGrantType(grantTypes string) proj_model.OIDCGrantType {
|
|
|
|
switch grantTypes {
|
2020-06-23 12:47:47 +00:00
|
|
|
case OIDCGrantTypeAuthorizationCode:
|
|
|
|
return proj_model.OIDCGrantTypeAuthorizationCode
|
|
|
|
case OIDCGrantTypeImplicit:
|
|
|
|
return proj_model.OIDCGrantTypeImplicit
|
|
|
|
case OIDCGrantTypeRefreshToken:
|
|
|
|
return proj_model.OIDCGrantTypeRefreshToken
|
|
|
|
}
|
|
|
|
return proj_model.OIDCGrantTypeAuthorizationCode
|
2020-05-18 09:32:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func getOIDCApplicationType(appType string) proj_model.OIDCApplicationType {
|
|
|
|
switch appType {
|
2020-06-23 12:47:47 +00:00
|
|
|
case OIDCApplicationTypeNative:
|
|
|
|
return proj_model.OIDCApplicationTypeNative
|
|
|
|
case OIDCApplicationTypeUserAgent:
|
|
|
|
return proj_model.OIDCApplicationTypeUserAgent
|
|
|
|
case OIDCApplicationTypeWeb:
|
|
|
|
return proj_model.OIDCApplicationTypeWeb
|
|
|
|
}
|
|
|
|
return proj_model.OIDCApplicationTypeWeb
|
2020-05-18 09:32:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func getOIDCAuthMethod(authMethod string) proj_model.OIDCAuthMethodType {
|
|
|
|
switch authMethod {
|
2020-06-23 12:47:47 +00:00
|
|
|
case OIDCAuthMethodTypeNone:
|
|
|
|
return proj_model.OIDCAuthMethodTypeNone
|
|
|
|
case OIDCAuthMethodTypeBasic:
|
|
|
|
return proj_model.OIDCAuthMethodTypeBasic
|
|
|
|
case OIDCAuthMethodTypePost:
|
|
|
|
return proj_model.OIDCAuthMethodTypePost
|
|
|
|
}
|
2020-08-18 08:04:56 +00:00
|
|
|
return proj_model.OIDCAuthMethodTypeBasic
|
2020-05-18 09:32:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func setSetUpContextData(ctx context.Context, orgID string) context.Context {
|
2020-07-08 11:56:37 +00:00
|
|
|
return authz.SetCtxData(ctx, authz.CtxData{UserID: SetupUser, OrgID: orgID})
|
2020-05-18 09:32:16 +00:00
|
|
|
}
|