You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ACL seems to not work when having multiple user models with a base UserModel #3829
I want to forbid everyone from accessing the model except Admins.
I tried reversing the order, change principalType to "ROLE" and principalId to "Admin", tried by changing the case (admin, ADMIN, Admin, etc...)
But whatever I do, when accessing the end point GET TaskItems as an Admin user I have a forbidden response.
Of course if I remove all the acls I have the results.
The pending pull request #3823 is offering the following fix, which seems to address the problems you are observing, but I am worried it may be breaking other things - I need to investigate this more.
diff --git a/lib/access-context.js b/lib/access-context.js
index 310e9bf2..99e66c9e 100644
--- a/lib/access-context.js+++ b/lib/access-context.js@@ -87,7 +87,7 @@ function AccessContext(context) {
var token = this.accessToken || {};
if (token.userId != null) {
- this.addPrincipal(Principal.USER, token.userId);+ this.addPrincipal(token.principalType || Principal.USER, token.userId);
}
if (token.appId != null) {
this.addPrincipal(Principal.APPLICATION, token.appId);
Yay, I sent a pull request to fix this issue - see #3835. @abouroubi could you please check if the patch fixes the problem for you (together with the change described in my comment above) and leave a comment in the pull request to let us know?
When assigning the role, it fixes the authentication.
But my original problem, was to control access based on principal type and not roles. Wonder if this is possible with the actual implementation ?
I added some code in the BaseUser, that assign role to the models that inherits from it (sets role to Admin when principal is Admin, and to Client when principal is Client). It fixes the problem, but it makes me duplicate code, cause in my case the role will always be the principal type.
But my original problem, was to control access based on principal type and not roles. Wonder if this is possible with the actual implementation ?
I added some code in the BaseUser, that assign role to the models that inherits from it (sets role to Admin when principal is Admin, and to Client when principal is Client). It fixes the problem, but it makes me duplicate code, cause in my case the role will always be the principal type.
@raymondfeng could you please help? I don't know our ACL/auth system enough to be able to answer this question.
Activity
bajtos commentedon Mar 20, 2018
Hello, thank you for the bug report and the loopbacktest repository. I managed to reproduce the problem you have described.
AFAICT, there are several causes:
1]
$everyonecannot be used as a user id, it's a role id. Here is the corrected ACL definition:2] You need to create "admin" role and assign your admin user to this role, as described in our docs.
Here is how I modified you
boot/root.jsscript:3] There is a bug in AccessContext where to incorrectly add USER instead of Admin/Client principal to the context, see
loopback/lib/access-context.js
Lines 80 to 91 in 6ddf268
The pending pull request #3823 is offering the following fix, which seems to address the problems you are observing, but I am worried it may be breaking other things - I need to investigate this more.
bajtos commentedon Mar 20, 2018
Yay, I sent a pull request to fix this issue - see #3835. @abouroubi could you please check if the patch fixes the problem for you (together with the change described in my comment above) and leave a comment in the pull request to let us know?
abouroubi commentedon Mar 20, 2018
Thanks for the reply.
When assigning the role, it fixes the authentication.
But my original problem, was to control access based on principal type and not roles. Wonder if this is possible with the actual implementation ?
I added some code in the BaseUser, that assign role to the models that inherits from it (sets role to Admin when principal is Admin, and to Client when principal is Client). It fixes the problem, but it makes me duplicate code, cause in my case the role will always be the principal type.
bajtos commentedon Mar 22, 2018
@raymondfeng could you please help? I don't know our ACL/auth system enough to be able to answer this question.