Difference between revisions of "User Management"

From BaseX Documentation
Jump to navigation Jump to search
(db:create → user:create)
(23 intermediate revisions by one other user not shown)
Line 1: Line 1:
This article is part of the [[Advanced User's Guide]].
+
This article is part of the [[Advanced User's Guide]]. The user management defines which permissions are required by a user to perform a database command or XQuery expression.
The user management defines which permissions are required
 
by a user to perform a database command or XQuery expression.
 
  
Permissions are mostly relevant in the client/server architecture, as the
+
Permissions are mostly relevant in the client/server architecture, as the [[GUI]] and the [[Command-Line Client]] is run with admin permissions. There are a few exceptions such as the [[XQuery Module#xquery:eval|xquery:eval]] function: Its execution scope can also be limited by specifying a permission.
[[Standalone Mode]] and the [[GUI]] is run with admin permissions.
 
There are a few exceptions such as the [[XQuery Module#xquery:eval|xquery:eval]] function:
 
its execution scope can also be limited by specifying a permission.
 
  
With {{Version|8.0}}, the user management has been reworked:
+
Please take care of usual security measures: ensure that your password will not end up in your bash history, avoid sending passwords via ordinary REST requests, etc.
 
 
* Permissions can now be manually edited, as they are stored as XML.
 
* The permission file has been moved from the home directory to the database directory. It was renamed from {{Code|.basexperm}} to {{Code|users.xml}}.
 
* Local permissions are now defined for database glob patterns instead of single databases. Both local and global permissions are stored in the same file.
 
* A new [[User Module]] is available, which allows user management via XQuery.
 
  
 
==Rules==
 
==Rules==
Line 25: Line 15:
 
and override global permissions.
 
and override global permissions.
  
[[File:perms.png|none|thumb|403px|Permissions hierarchy]]
+
[[File:perms.png|Permissions hierarchy]]
  
 
User names must follow the [[Valid Names|valid names constraints]], and the database patterns must follow the [[Commands#Glob_Syntax|Glob Syntax]].
 
User names must follow the [[Valid Names|valid names constraints]], and the database patterns must follow the [[Commands#Glob_Syntax|Glob Syntax]].
  
==Commands==
+
==Operations==
  
Admin permissions are required to execute all of the following commands:
+
For all operations, admin permissions are required:
 +
 
 +
=Commands=
  
 
'''Create user 'test' (password will be entered on command line). By default, the user will have no permissions ('none'):
 
'''Create user 'test' (password will be entered on command line). By default, the user will have no permissions ('none'):
Line 53: Line 45:
  
 
<code>&gt; SHOW USERS</code>  
 
<code>&gt; SHOW USERS</code>  
 
'''Show detailed information about user 'test' via XQuery:'''
 
  
<code>&gt; XQUERY user:list-details()[@name = 'test']</code>
+
==XQuery==
 +
 
 +
The available user functions are listed in the [[User Module]]:
 +
 
 +
'''Create user 'test' with no permissions:'''
 +
 
 +
<code>user:create('test', 'top-secret')</code>
 +
 
 +
'''Show detailed information about user 'test':'''
 +
 
 +
<code>user:list-details()[@name = 'test']</code>
 +
 
 +
'''Drop user 'test':'''
 +
 
 +
<code>user:drop('test')</code>
  
'''Drop of user 'test' via XQuery:'''
+
=Storage=
  
<code>&gt; XQUERY user:drop('test')</code>
+
The permission file {{Code|users.xml}} is stored in the database directory. This file can be manually edited; it will be parsed once when BaseX is started.
  
[[Category:Server]]
+
Salted SHA256 hashes are used for authentication (the current timestamp will be used as salt). Additionally, digest hashes are used in the client/server architecture and the [[Clients|Language Bindings]], and in the [[Web Application|HTTP Context]] if {{Option|AUTHMETHOD}} is set to {{Code|Digest}}.
[[Category:Internals]]
 
  
 
=Changelog=
 
=Changelog=
  
 
Revised in Version 8.0.
 
Revised in Version 8.0.

Revision as of 08:30, 3 February 2021

This article is part of the Advanced User's Guide. The user management defines which permissions are required by a user to perform a database command or XQuery expression.

Permissions are mostly relevant in the client/server architecture, as the GUI and the Command-Line Client is run with admin permissions. There are a few exceptions such as the xquery:eval function: Its execution scope can also be limited by specifying a permission.

Please take care of usual security measures: ensure that your password will not end up in your bash history, avoid sending passwords via ordinary REST requests, etc.

Rules

In the permission hierarchy below, the existing permissions are illustrated. A higher permission includes all lower permissions. For example, all users who have the write permission assigned will also be able to execute commands requiring read permission.

Local permissions are applied to databases. They have a higher precedence and override global permissions.

Permissions hierarchy

User names must follow the valid names constraints, and the database patterns must follow the Glob Syntax.

Operations

For all operations, admin permissions are required:

Commands

Create user 'test' (password will be entered on command line). By default, the user will have no permissions ('none'):

> CREATE USER test

Change password of user 'test' to '71x343sd#':

> ALTER PASSWORD test 71x343sd#

Grant local write permissions to user 'test':

> GRANT write ON unit* TO test

Note: Local permissions overwrite global permissions. As a consequence, the 'test' user will only be allowed to access (i.e., read and write) database starting with the letters 'unit'. If no local permissions are set, the global rights are inherited.

Show global permissions:

> SHOW USERS

XQuery

The available user functions are listed in the User Module:

Create user 'test' with no permissions:

user:create('test', 'top-secret')

Show detailed information about user 'test':

user:list-details()[@name = 'test']

Drop user 'test':

user:drop('test')

Storage

The permission file users.xml is stored in the database directory. This file can be manually edited; it will be parsed once when BaseX is started.

Salted SHA256 hashes are used for authentication (the current timestamp will be used as salt). Additionally, digest hashes are used in the client/server architecture and the Language Bindings, and in the HTTP Context if AUTHMETHOD is set to Digest.

Changelog

Revised in Version 8.0.