Built-in User Authentication and Authorization Configuration and Usage in HugeGraph
Overview
To facilitate authentication usage in different user scenarios, HugeGraph currently provides built-in authorization StandardAuthenticator mode,
which supports multi-user authentication and fine-grained access control. It adopts a 4-layer design based on “User-UserGroup-Operation-Resource” to
flexibly control user roles and permissions (supports multiple GraphServers).
Some key designs of the StandardAuthenticator mode include:
- During initialization, a super administrator (
admin) user is created. Subsequently, other users can be created by the super administrator. Once newly created users are assigned sufficient permissions, they can create or manage more users. - It supports dynamic creation of users, user groups, and resources, as well as dynamic allocation or revocation of permissions.
- Users can belong to one or multiple user groups. Each user group can have permissions to operate on any number of resources. The types of operations include read, write, delete, execute, and others.
- “Resource” describes the data in the graph database, such as vertices that meet certain criteria. Each resource consists of three elements:
type,label, andproperties. There are 18 types in total, with the ability to combine any label and properties. The internal condition of a resource is an AND relationship, while the condition between multiple resources is an OR relationship.
Here is an example to illustrate:
Configure User Authentication
By default, HugeGraph does not enable user authentication, and it needs to be enabled by modifying the configuration file.
Because the flexibility of graph query languages can introduce potential system security risks, do not expose Gremlin, Cypher, or other query endpoints directly to the public network. In production, enable authentication, an IP allowlist, and audit logging, and isolate the Server process with Docker or Kubernetes.
You need to modify the configuration file to enable this feature. HugeGraph provides built-in authentication mode: StandardAuthenticator. This mode supports multi-user authentication and fine-grained permission control. Additionally, developers can implement their own HugeAuthenticator interface to integrate with their existing authentication systems.
HugeGraph uses HTTP Basic Authentication. The value after
Basic is the Base64 encoding of username:password. With curl, pass the credentials directly through -u:
Warning: Versions of HugeGraph-Server prior to 1.5.0 have a JWT-related security vulnerability in the Auth mode.
Users are advised to update to a newer version or manually set the JWT token’s secretKey. It can be set in the rest-server.properties file by setting the auth.token_secret information:
You can also generate it with the following command:
Since 1.5.0 the option defaults to a key generated randomly at startup, so it does not have to be configured. Set it
explicitly when tokens have to survive a restart, or when more than one server must accept the same token. Tokens expire
after auth.token_expire seconds (default 86400).
StandardAuthenticator Mode
The StandardAuthenticator mode supports user authentication and permission control by storing user information in the database backend. This
implementation authenticates users based on their names and passwords (encrypted) stored in the database and controls user permissions based on their
roles. Below is the specific configuration process (requires service restart):
Configure the authenticator and its rest-server file path in the gremlin-server.yaml configuration file:
Configure the authenticator and the graph that stores authorization data in rest-server.properties:
In the above configuration, the graph_store option specifies which graph to use for storing user information. If there are multiple graphs, you can choose any of them.
In the hugegraph{n}.properties configuration file, configure the gremlin.graph information:
For authorization API usage, see the Authentication API documentation.
Custom User Authentication System
If you need to support a more flexible user system, you can customize the authenticator for extension.
Simply implement the org.apache.hugegraph.auth.HugeAuthenticator interface with your custom authenticator,
and then modify the authenticator configuration item in the configuration file to point to your implementation.
Switching authentication mode
When init-store.sh is run for the first time and the admin user does not yet exist, the command prompts for the
administrator password. For an initialized persistent backend, init-store.sh adds the system metadata required for
authentication without deleting existing graph data.
Use docker to enable authentication mode
For versions of the hugegraph/hugegraph image equal to or greater than 1.2.0, you can enable authentication mode while starting the Docker image.
The steps are as follows:
1. Use docker run
To enable authentication mode, add the environment variable PASSWORD=xxx (you can freely set the password) in the docker run command:
2. Use docker-compose
Use docker-compose and set the environment variable PASSWORD=xxx:
3. Enter the container to enable authentication mode
Enter the container first:
Then follow Switching authentication mode