OrientDB authorization model can not be used as application level authorization
See original GitHub issueSuch features as record level security encourage user to use OrientDB authorization as application level authorization. In other words, use OUser
class as a main class for application user.
However there are some significant design issues in binary network protocol.
I suppose users would like to use approach similar to following
- Application opens several sockets to database.
- For each user connected to the application a db session is opened.
- OPEN_DATABASE command is used to authorize user.
- SessionID or similar entity is used as auth token.
Issues with concurrent requests
ODatabaseDocumentTx
is not thread safe. And in binary network protocol each client session holds its instance of ODatabaseDocumentTx
.
Thus session can not be used by several connections from different sockets because they can be handled in different server threads.
As a result we can not reuse session in different client threads.
This means that we have to open a new session for each user * each application thread. That leads to a need to reauthorize user in db for each thread. And as soon as user request can be handled by several application thread we have to store username and password at application layer.
Memory consumption
Having a thousands of active users may lead to thousands of opened connections in client connection manager. This could be memory consuming.
Possible memory leaks
If user is not logged out and socket was reused by other user, its session may remain in client connection manager forever. It won’t be closed automatically as soon as socket still alive and used by application to handle another user sessions.
Session Id shouldn’t be used as auth token
Session Id is serial, so it is not really safe to use it as a auth token.
No native way to make users rememberable
As soon as OrientDB supports only user/password authorization, “Remember me” feature could be implemented only by workarounds.
Automatic shutdown of session
Automatic shutdown of sessions that associated to broken connections are not designed for sessions that could be used by several connections.
So some session that is closed in such way may still be used by some other thread.
Issue Analytics
- State:
- Created 9 years ago
- Comments:73 (58 by maintainers)
Top GitHub Comments
@lvca I’ve put together a working implementation for token based authentication in orientdb. It isn’t perfect and requires some work to ensure proper security. However, I wanted to share with you so you could, if you wanted, test out whether this type of mechanism is appropriate for OrientDb.
All my changes are in my local repo: https://github.com/emrul/orientdb/commit/c15c979331767e897ecc489d3c390a61766c7b51
Obtaining a token
There is a new endpoint /token/<db_name> that will return an authentication token. In the example below there is a database named ‘TestTokenAuth’ with user ‘emrul@emrul.com’ and password ‘password’: The request parameters conform to the OAuth2 specification
This returns a JSON structure including the access_token and expires_in information. This is consistent with the OAuth2 specification but not complete:
You can copy & paste the access token over at jwt.io, it looks like this:
The access token isn’t as I would prefer for a full implementation but contains the minimum needed to demonstrate the functionality.
Using a token for authentication
You pass the token as an bearer token in the Authorisation header. For example:
Current implementation notes
Summary
Any thoughts are welcome.
Emanuele will continue documentation and tests in #3155