diff --git a/cmd/defaults.yaml b/cmd/defaults.yaml index baca5175e..2437a4ef3 100644 --- a/cmd/defaults.yaml +++ b/cmd/defaults.yaml @@ -906,7 +906,7 @@ AuditLogRetention: 0s # ZITADEL_AUDITLOGRETENTION InternalAuthZ: # Configure the RolePermissionMappings by environment variable using JSON notation: - # ZITADEL_INTERNALAUTHZ_ROLEPERMISSIONMAPPINGS='[{"role": "IAM_OWNER", "permissions": ["iam.read", "iam.write"]}]' + # ZITADEL_INTERNALAUTHZ_ROLEPERMISSIONMAPPINGS='[{"role": "IAM_OWNER", "permissions": ["iam.write"]}, {"role": "ORG_OWNER", "permissions": ["org.write"]}]' # Beware that if you configure the RolePermissionMappings by environment variable, all the default RolePermissionMappings are lost. RolePermissionMappings: - Role: "SYSTEM_OWNER" diff --git a/cmd/setup/config.go b/cmd/setup/config.go index 8c44f0b21..f5547d21c 100644 --- a/cmd/setup/config.go +++ b/cmd/setup/config.go @@ -69,6 +69,7 @@ func MustNewConfig(v *viper.Viper) *Config { hook.EnumHookFunc(authz.MemberTypeString), actions.HTTPConfigDecodeHook, hooks.MapTypeStringDecode[string, *authz.SystemAPIUser], + hooks.SliceTypeStringDecode[authz.RoleMapping], )), ) logging.OnError(err).Fatal("unable to read default config") diff --git a/cmd/start/config_test.go b/cmd/start/config_test.go index 9319e574d..90d4b9d2d 100644 --- a/cmd/start/config_test.go +++ b/cmd/start/config_test.go @@ -223,6 +223,52 @@ Actions: Greeting: "bar", }}) }, + }, { + name: "roles ok", + args: args{yaml: ` +InternalAuthZ: + RolePermissionMappings: + - Role: IAM_OWNER + Permissions: + - iam.write + - Role: ORG_OWNER + Permissions: + - org.write + - org.read +Log: + Level: info +Actions: + HTTP: + DenyList: [] +`}, + want: func(t *testing.T, config *Config) { + assert.Equal(t, config.InternalAuthZ, authz.Config{ + RolePermissionMappings: []authz.RoleMapping{ + {Role: "IAM_OWNER", Permissions: []string{"iam.write"}}, + {Role: "ORG_OWNER", Permissions: []string{"org.write", "org.read"}}, + }, + }) + }, + }, { + name: "roles string ok", + args: args{yaml: ` +InternalAuthZ: + RolePermissionMappings: > + [{"role": "IAM_OWNER", "permissions": ["iam.write"]}, {"role": "ORG_OWNER", "permissions": ["org.write", "org.read"]}] +Log: + Level: info +Actions: + HTTP: + DenyList: [] +`}, + want: func(t *testing.T, config *Config) { + assert.Equal(t, config.InternalAuthZ, authz.Config{ + RolePermissionMappings: []authz.RoleMapping{ + {Role: "IAM_OWNER", Permissions: []string{"iam.write"}}, + {Role: "ORG_OWNER", Permissions: []string{"org.write", "org.read"}}, + }, + }) + }, }} for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {