Set default IAM domain if none provided

This commit is contained in:
Ingo Oppermann
2023-06-21 09:08:25 +02:00
parent f0957e2815
commit 1f55c7d07e
2 changed files with 25 additions and 2 deletions

View File

@@ -32,6 +32,10 @@ func (a *policyAdapter) LoadPolicy(model model.Model) error {
domains := map[string]struct{}{}
for _, p := range policies.Policies {
if len(p.Domain) == 0 {
p.Domain = "$none"
}
rule := []string{
p.Name,
p.Domain,

View File

@@ -434,6 +434,10 @@ func (s *store) addIdentity(cmd CommandAddIdentity) error {
s.lock.Lock()
defer s.lock.Unlock()
if cmd.Identity.Name == "$anon" {
return fmt.Errorf("the identity with the name '%s' can't be created", cmd.Identity.Name)
}
_, ok := s.data.Users.Users[cmd.Identity.Name]
if ok {
return fmt.Errorf("the identity with the name '%s' already exists", cmd.Identity.Name)
@@ -449,6 +453,10 @@ func (s *store) updateIdentity(cmd CommandUpdateIdentity) error {
s.lock.Lock()
defer s.lock.Unlock()
if cmd.Name == "$anon" {
return fmt.Errorf("the identity with the name '%s' can't be updated", cmd.Name)
}
_, ok := s.data.Users.Users[cmd.Name]
if !ok {
return fmt.Errorf("the identity with the name '%s' doesn't exist", cmd.Name)
@@ -495,9 +503,20 @@ func (s *store) setPolicies(cmd CommandSetPolicies) error {
s.lock.Lock()
defer s.lock.Unlock()
if cmd.Name != "$anon" {
if _, ok := s.data.Users.Users[cmd.Name]; !ok {
return fmt.Errorf("the identity with the name '%s' doesn't exist", cmd.Name)
}
}
for i, p := range cmd.Policies {
if len(p.Domain) != 0 {
continue
}
p.Domain = "$none"
cmd.Policies[i] = p
}
delete(s.data.Policies.Policies, cmd.Name)
s.data.Policies.Policies[cmd.Name] = cmd.Policies