Skip to content

ACL for models extending User Model is not working #2270

Closed

Description

@jannyHou
  1. slc loopback to create a new lb app
  2. slc loopback:model to create a model extends User model
  3. node . and open explorer
  4. Try endpoint Post/ myusers/ :

Result:

{
  "username": "string",
  "email": "aaa@gmail.com",
  "id": 1
}

Try endpoint Get/ myusers/ :
Result:

[
  {
    "username": "string",
    "email": "aaa@gmail.com",
    "id": 1
  }
]

By default, people should not be able to Get /myusers without login.

Activity

  1. bajtos commented on May 2, 2016

    @bajtos
    Member

    I think ACLs are not inherited when extending a model. See #157 for more details.

  2. bajtos commented on May 2, 2016

    @bajtos
    Member

    I think there is one catch: ACL is represented as a list of access-control entries and AFAIK we don't have a declarative way for clearing this list from model JSON file. This means that when a child model inherits ACL from the parent, it is not possible to drop parent's ACL and build a new ACL from scratch.

    We should find a solution for that while working on the fix for this issue.

    Since this was discovered when extending a built-in model, I think it relates to #397 A better way for customizing built-in models and models from components

  3. cfjedimaster commented on May 2, 2016

    @cfjedimaster

    @bajtos Are you saying this is a bug everywhere, or that it wasn't intended to work in the first place?

    To your second point - what if the logic was this: Given Child extends Parent - if my child.json file has no acls property, then it inherits. If it has "acls":[], that means "I'm not inheriting Parent, I'm setting acls to an empty array."

    That may not be backwards compat though.

  4. sahilanguralla commented on May 3, 2016

    @sahilanguralla

    I am in middle of something and I need it. please fix it ASAP. Also please suggest any workaround for the time being, if possible. Thanks in advance.

  5. bajtos commented on May 3, 2016

    @bajtos
    Member

    Are you saying this is a bug everywhere, or that it wasn't intended to work in the first place?

    I believe that we have never implemented inheritance of ACL. I don't think it was an intentional decision, just the result of the way how we implemented the feature.

    To your second point - what if the logic was this: Given Child extends Parent - if my child.json file has no acls property, then it inherits. If it has "acls":[], that means "I'm not inheriting Parent, I'm setting acls to an empty array."

    I think the typical scenario would be to built a custom ACL in the JSON file, which would not be supported if you had to specify "acls":[].

    Here are few other ideas of what can be done:

    1. When "acls" is not defined, or set to a special value like "inherit" (notice it's a string, not an array as usually), the model will inherit "acls" from the parent. If "acls" is set, parent ACL will be discarded and the ACL provided in the child model will be used instead.
    // inherits from parent
    {
      "base": "User",
      "acls": "inherit" 
    }
    
    // defines custom ACL
    {
      "base": "User",
      "acls": [
        {
          "principalType": "ROLE",
          "principalId": "$everyone",
          "permission": "DENY"
        },
        {
          "principalType": "ROLE",
          "principalId": "admin",
          "permission": "ALLOW",
        }
      ]
    }
    1. Another approach is to create a special ACL entry to clear the inherited list:
    // defines custom ACL
    {
      "base": "User",
      "acls": [
        "reset",
        {
          "principalType": "ROLE",
          "principalId": "$everyone",
          "permission": "DENY"
        },
        {
          "principalType": "ROLE",
          "principalId": "admin",
          "permission": "ALLOW",
        }
      ]
    }
    1. I think the cleanest option is to add a model setting specifying whether parent ACL should be inherited:
    {
      "base": "User",
      "inheritAcls": false, // true by default
      "acls": []
    }

    The last option looks best to me.

    @raymondfeng @ritch @superkhau thoughts?

  6. bajtos commented on May 3, 2016

    @bajtos
    Member

    Also if we add a setting inheritAcls, then we can implement it in 2.x and modify model generator to set the flag to true. That way we get backwards compatibility for existing codebase and still have the benefit of doing things the right way for newly created models.

  7. 27 remaining items

  8. ebarault commented on Apr 4, 2017

    @ebarault
    Contributor

    there's currently no clean one i'm afraid, the best i see is to create you own User base model, reusing the code from the built-in model and removing the incriminated ACLs from this custom User base model

  9. maziarz commented on Apr 4, 2017

    @maziarz

    @ebarault I do not want to point fingers, but i just came from Django REST framework and getting a bit cold feet, especially since LB encourages extending the base model to create a custom User model, it does not seem to extend the ACL methodology quite well. I am just crossing my fingers that i do not fall over more weird design defects. Sorry if i sound rude, it was not intentional.

  10. ebarault commented on Apr 4, 2017

    @ebarault
    Contributor

    @maziarz: no offense taken. I'm a community maintainer, doing my best to sort some problems out, one at a time. Community is doing a great job here so does the Strongloop team (now joined by IBM). The framework is nearly extensible to the infinite and everyone expects a tone from it OOTB, which is fine :-) but it just take some time and/or your joined efforts to contribute in fixing the issues that matter most to you.

  11. maziarz commented on Apr 4, 2017

    @maziarz

    @ebarault you are doing a good job as far as i can see! I will eat the default ACL's for now until juggler gets released with new shoes :-)

  12. assigned and unassigned on Apr 13, 2017
  13. kodepareek commented on Apr 18, 2017

    @kodepareek

    A new version of Datasource juggler seems to have been published 18 hours ago. But doesn't look like it fixed the issue.

    Yup the PR above has not been merged yet.

  14. rashmihunt commented on Jun 30, 2017

    @rashmihunt
    Contributor

    Fix is merged through this PR loopbackio/loopback-datasource-juggler#1289 Closing this issue.

  15. cfjedimaster commented on Jun 30, 2017

    @cfjedimaster

    So to be clear, the fix is that all ACLS for models extending others should work now? I just want to be clear on what/how it was corrected.

  16. rashmihunt commented on Jul 10, 2017

    @rashmihunt
    Contributor

    @bajtos @raymondfeng - since you have reviewed the community PR loopbackio/loopback-datasource-juggler#1289, can you please answer @cfjedimaster 's above question?

  17. bajtos commented on Jul 11, 2017

    @bajtos
    Member

    I re-read the discussion in loopbackio/loopback-datasource-juggler#1289 to refresh my memory. I believe that when a child model is created, ACLs defined by the parent model are merged with ACLs defined by the child model in such way that child model ACL entries take precedence. So yes, all ACLs for models extending others should work now.

  18. pbourdu commented on Oct 4, 2018

    @pbourdu

    @bajtos - I'am implementing this case in my project, child model ACL entries have no effects, only parent's ACL are applied. I'm using loopback 3.22.2.

    "loopback": "^3.22.2", "loopback-boot": "^2.27.1", "loopback-component-explorer": "^4.3.1", "loopback-component-logger": "^1.0.0", "loopback-connector-mongodb": "^3.6.0",

  19. bajtos commented on Oct 9, 2018

    @bajtos
    Member

    @pbourdu I see. Please create a small app reproducing the problem (see Reporting bugs), open a new issue and then post a link to that new issue here.

  20. eyoma commented on Nov 27, 2018

    @eyoma

    @bajtos - I'am implementing this case in my project, child model ACL entries have no effects, only parent's ACL are applied. I'm using loopback 3.22.2.

    "loopback": "^3.22.2", "loopback-boot": "^2.27.1", "loopback-component-explorer": "^4.3.1", "loopback-component-logger": "^1.0.0", "loopback-connector-mongodb": "^3.6.0",

    Same issue:
    STEPS:
    Create a new loopback app
    Create new Model e.g "Appuser" using "User" as base model
    Set ACLs on "Appuser" to grant everyone access
    => ACLs for the child model has not effect

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions