Skip to content

Role.id and Role.name mixup in resolving ACLs and Role.isInRole #984

Closed

Description

@marcuspl

The documentation for the ACL class states that the principalId for a Role should be "ID of the principal - such as appId, userId or roleId". When a role is resolved in ACL.checkAccessForContext we see that it is called with roleModel.isInRole(acl.principalId, ...
However, when looking at the documentation for Role.isInRole:

  /**
   * Check if a given principal is in the role
   *
   * @param {String} role The role name
   * @param {Object} context The context object
   * @callback {Function} callback
   * @param {Error} err
   * @param {Boolean} isInRole
   */
  Role.isInRole = function(role, context, callback)

And later on it is used as a name, not as an id: this.findOne({where: {name: role}} ...

I had hooked up all my ACLs to map on IDs, so I changed the code to use findById, and I could not find any other place that referred to it so that worked fine for me. Another option would be to change the calling code to use name, or have the find look for both name OR id.

As I don't know how you would like to have it, I figured I mention it to you guys without trying to provide a patch or something first.

Thanks for the great work and keep it up!

Activity

  1. bajtos commented on Jun 2, 2016

    @bajtos
    Member

    @raymondfeng you are more familiar with ACLs than I am. Could you PTAL?

  2. smartmouse commented on Feb 10, 2017

    @smartmouse

    @marcuspl Thank you for spotting this issue. We confirm with @raymondfeng that it should be role name. This should be a bug in code and not doc issue .

    So we should pass in the principalName instead of the principalId
    Do you want to provide a patch?
    Thanks

    
           // Check role matches
           if (acl.principalType === ACL.ROLE) {
             inRoleTasks.push(function(done) {
               roleModel.isInRole(acl.principalId, context,
                 function(err, inRole) {
                   if (!err && inRole) {
                     effectiveACLs.push(acl);
                   }
                   done(err, acl);
                 });
             });
    
    
  3. smartmouse commented on Feb 10, 2017

    @smartmouse

    I am removing the doc label as this is not really doc issue.

  4. crandmck commented on Feb 10, 2017

    @crandmck
    Contributor

    @superkhau Who should we ping/assign this to now to ensure it doesn't get lost?

  5. removed their assignment
    on Feb 10, 2017
  6. superkhau commented on Feb 10, 2017

    @superkhau
    Contributor

    @crandmck I believe @kjdelisle's team is on it according to the Slack convo's in their channel.

  7. superkhau commented on Feb 10, 2017

    @superkhau
    Contributor

    Another option would be to change the calling code to use name...

    @marcuspl Would you like to submit a patch instead? I can help get it landed quickly.

  8. bajtos commented on Feb 15, 2017

    @bajtos
    Member

    FWIW, this may be related to #2420 and #2975 /cc @ebarault.

  9. marcuspl commented on Feb 16, 2017

    @marcuspl
    Author

    @superkhau I moved on a long time ago, don't even think I could find it anymore. Thanks though.

  10. bajtos commented on Apr 26, 2018

    @bajtos
    Member

    I am closing this issue then. We can reopen it if we get more bug reports from our users.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions