ACL does not work for multiple loopback apps on the same server
Hi everyone and sorry for my bad english!
I'm trying to create a 2 loopback applications on the same server, each app is reached by specific url like app1.domain.com and app2.domain.com
I used the vhost middleware and I followed the suggestions of @bajtos in the following post http://stackoverflow.com/questions/22678387/how-to-run-multiple-strongloop-loopback-apps-on-the-same-server and I implemented this application:
var root = loopback();
root.set('port', process.env.PORT || 3000);
var app1Host = 'app1.domain.com';
var app2Host = 'app2.domain.com';
var app1 = require('./app1/server');
var app2 = require('./app2/server');
root.use(vhost(app1Host, app1));
root.use(vhost(app2Host, app2));
root.listen(function () {
console.log('\nWeb server listening at: %s', root.get('url'));
app1.emit('started');
app2.emit('started');
});
The application apparently worked but I found strange behaviors which I attribute to the fact that the applications share some models (including the built-in models) and other models have the same name. Analyzing loopback source code I assumed the problem is both applications uses a global registry. In the code I found the possibility of providing options for creating loopback applications (localRegistry & loadBuiltinModels) and I have tried to create all 3 applications (app1, app2 and root) with these options.
loopback ({localRegistry: true, loadBuiltinModels: true});
It seems to be much better, no "anomalous" behaviors but... ACL rules have been lost! In the acl.js is used...
loopback.findModel(...)
https://github.com/strongloop/loopback/blob/master/common/models/acl.js#L271
and I think this method works on the global registry (empty now).
If I try...
ACL.app.registry.findModel(...)
I get the correct model.
I don't know if it's a Bug or I'm doing something else wrong. localRegistry & loadBuiltinModels are undocumented options, is a work-in-progress function?
Thanks
This morning I've found this! #1056 from @ritch
localRegistry & loadBuiltinModels are undocumented options, is a work-in-progress function?
Your guess is correct. We got only as far as we needed for isolating unit tests and running multiple isomorphic clients in the same webpage.
ACL rules have been lost! I don't know if it's a Bug or I'm doing something else wrong.
This is looks like a bug to me. Would you like to contribute the fix yourself? I am happy to guide you along the way.
Yes! Ok! I have already signed the "Contributor license"
@diegobent hello, is this issue still relevant?
@bajtos hello! yes it is! Now I'm using different models with the same base model (for common settings) and each model works on the same MongoDB collection and has different ACLs. At the moment it works but I think this is a little bit tricky.
I think the original issue should have been fixed by https://github.com/strongloop/loopback/commit/98816217c951bdc0a357e427f987ae491e5e3384 in LoopBack 3.0.0. Could you please check?
Now I'm using different models with the same base model (for common settings) and each model works on the same MongoDB collection and has different ACLs. At the moment it works but I think this is a little bit tricky.
I find it difficult to build a mental image of what you are trying to accomplish. Could you perhaps create a small application showing your use case, per our bug-reporting instructions? Which part do you find "a little bit tricky"?
I am sorry if this is a dumb question, but I'm wondering if this is relevant for developing two l loopback apps completely separately on the same machine? They are created in entirely different folders. In the first app I have ACLs set to disallow all endpoints. In the second, I have no ACLs set or permissions at all (it is a brand new app from running lb on command line), but now am seeing 401 forbidden when trying to access any endpoint on that dev server.
@kristojorg If the applications are executed in a separate Node.js processes, then the problem you are experiencing is not related to this issue.
Is it perhaps possible that both of your applications are listening on the same port and you may end up with connecting to the wrong one, depending on which app has started first?