kuzzleio / kuzzle

Open-source Back-end, self-hostable & ready to use - Real-time, storage, advanced search - Web, Apps, Mobile, IoT -
https://kuzzle.io
Apache License 2.0
1.43k stars 123 forks source link

Broken rights while using profiles with same role and distinc restrictions #1136

Closed ballinette closed 6 years ago

ballinette commented 6 years ago

Given we have 2 profiles using the same role, with different restrictions:

roles = {
  'admin': {
    'controllers': {
        '*': {
           actions: {'*': true}
        }
     }
  }
}

profiles = {
  superadmin: {
    policies: [
      {
        roleId: 'admin'
      }
    ]
  },
  restrictedadmin: {
    policies: [
      {
        roleId: 'admin',
        restrictedTo: [
          {index: 'foo', collections: '*'},
          {index: 'bar': collections: ['baz']}
        ]
      }
    ]
  }
}

Expected Behavior

users with profile superadmin should be allowed to do any actions without any restriction users with profile restrictedadmin should be allowed to do any actions, but only on foo and bar indexes

Current Behavior

We have an inconsistent behaviour, restrictions for one profile override those for the other one, depending in which order they are loaded.

Possible Solution

Improve the way profiles load roles and their restrictions: https://github.com/kuzzleio/kuzzle/blob/master/lib/api/core/models/security/role.js

Steps to Reproduce

scottinet commented 6 years ago

Fixed and released in Kuzzle 1.3.1: https://github.com/kuzzleio/kuzzle/releases/tag/1.3.1