mirror of
https://github.com/andwati/zitadel.git
synced 2026-10-23 16:02:14 +00:00
feat: impersonation roles (#7442)
* partial work done * test IAM membership roles * org membership tests * console :(, translations and docs * fix integration test * fix tests * add EnableImpersonation to security policy API * fix integration test timestamp checking * add security policy tests and fix projections * add impersonation setting in console * add security settings to the settings v2 API * fix typo * move impersonation to instance --------- Co-authored-by: Livio Spring <[email protected]>
This commit is contained in:
co-authored by
Livio Spring
parent
68af4f59c9
commit
062d153cfe
@@ -10,9 +10,15 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
)
|
||||
|
||||
func (c *Commands) SetSecurityPolicy(ctx context.Context, enabled bool, allowedOrigins []string) (*domain.ObjectDetails, error) {
|
||||
type SecurityPolicy struct {
|
||||
EnableIframeEmbedding bool
|
||||
AllowedOrigins []string
|
||||
EnableImpersonation bool
|
||||
}
|
||||
|
||||
func (c *Commands) SetSecurityPolicy(ctx context.Context, policy *SecurityPolicy) (*domain.ObjectDetails, error) {
|
||||
instanceAgg := instance.NewAggregate(authz.GetInstance(ctx).InstanceID())
|
||||
validation := c.prepareSetSecurityPolicy(instanceAgg, enabled, allowedOrigins)
|
||||
validation := c.prepareSetSecurityPolicy(instanceAgg, policy)
|
||||
cmds, err := preparation.PrepareCommands(ctx, c.eventstore.Filter, validation)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -28,14 +34,14 @@ func (c *Commands) SetSecurityPolicy(ctx context.Context, enabled bool, allowedO
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c *Commands) prepareSetSecurityPolicy(a *instance.Aggregate, enabled bool, allowedOrigins []string) preparation.Validation {
|
||||
func (c *Commands) prepareSetSecurityPolicy(a *instance.Aggregate, policy *SecurityPolicy) preparation.Validation {
|
||||
return func() (preparation.CreateCommands, error) {
|
||||
return func(ctx context.Context, filter preparation.FilterToQueryReducer) ([]eventstore.Command, error) {
|
||||
writeModel, err := c.getSecurityPolicyWriteModel(ctx, filter)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cmd, err := writeModel.NewSetEvent(ctx, &a.Aggregate, enabled, allowedOrigins)
|
||||
cmd, err := writeModel.NewSetEvent(ctx, &a.Aggregate, policy)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package command
|
||||
|
||||
import (
|
||||
"context"
|
||||
"reflect"
|
||||
"slices"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/api/authz"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
@@ -11,9 +11,7 @@ import (
|
||||
|
||||
type InstanceSecurityPolicyWriteModel struct {
|
||||
eventstore.WriteModel
|
||||
|
||||
Enabled bool
|
||||
AllowedOrigins []string
|
||||
SecurityPolicy
|
||||
}
|
||||
|
||||
func NewInstanceSecurityPolicyWriteModel(ctx context.Context) *InstanceSecurityPolicyWriteModel {
|
||||
@@ -28,8 +26,11 @@ func NewInstanceSecurityPolicyWriteModel(ctx context.Context) *InstanceSecurityP
|
||||
func (wm *InstanceSecurityPolicyWriteModel) Reduce() error {
|
||||
for _, event := range wm.Events {
|
||||
if e, ok := event.(*instance.SecurityPolicySetEvent); ok {
|
||||
if e.Enabled != nil {
|
||||
wm.Enabled = *e.Enabled
|
||||
|
||||
if e.EnableIframeEmbedding != nil {
|
||||
wm.EnableIframeEmbedding = *e.EnableIframeEmbedding
|
||||
} else if e.Enabled != nil {
|
||||
wm.EnableIframeEmbedding = *e.Enabled
|
||||
}
|
||||
if e.AllowedOrigins != nil {
|
||||
wm.AllowedOrigins = *e.AllowedOrigins
|
||||
@@ -53,17 +54,19 @@ func (wm *InstanceSecurityPolicyWriteModel) Query() *eventstore.SearchQueryBuild
|
||||
func (wm *InstanceSecurityPolicyWriteModel) NewSetEvent(
|
||||
ctx context.Context,
|
||||
aggregate *eventstore.Aggregate,
|
||||
enabled bool,
|
||||
allowedOrigins []string,
|
||||
policy *SecurityPolicy,
|
||||
) (*instance.SecurityPolicySetEvent, error) {
|
||||
changes := make([]instance.SecurityPolicyChanges, 0, 2)
|
||||
var err error
|
||||
|
||||
if wm.Enabled != enabled {
|
||||
changes = append(changes, instance.ChangeSecurityPolicyEnabled(enabled))
|
||||
if wm.EnableIframeEmbedding != policy.EnableIframeEmbedding {
|
||||
changes = append(changes, instance.ChangeSecurityPolicyEnableIframeEmbedding(policy.EnableIframeEmbedding))
|
||||
}
|
||||
if enabled && !reflect.DeepEqual(wm.AllowedOrigins, allowedOrigins) {
|
||||
changes = append(changes, instance.ChangeSecurityPolicyAllowedOrigins(allowedOrigins))
|
||||
if !slices.Equal(wm.AllowedOrigins, policy.AllowedOrigins) {
|
||||
changes = append(changes, instance.ChangeSecurityPolicyAllowedOrigins(policy.AllowedOrigins))
|
||||
}
|
||||
if wm.EnableImpersonation != policy.EnableImpersonation {
|
||||
changes = append(changes, instance.ChangeSecurityPolicyEnableImpersonation(policy.EnableImpersonation))
|
||||
}
|
||||
changeEvent, err := instance.NewSecurityPolicySetEvent(ctx, aggregate, changes)
|
||||
if err != nil {
|
||||
|
||||
@@ -216,6 +216,10 @@ func (m *mockInstance) SecurityPolicyAllowedOrigins() []string {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *mockInstance) EnableImpersonation() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (m *mockInstance) Features() feature.Features {
|
||||
return feature.Features{}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user