Client authentication can be achieved by using the Authorization HTTP header in client requests. ArangoDB supports authentication via the following:

Authentication is enabled by default for all internal database APIs but disabled for custom Foxx apps. To toggle authentication for incoming requests to the internal database APIs, use the --server.authentication startup option. This option is enabled by default so authentication is required for the database APIs. If you turn it off, the access requirements stated for the endpoints, including the need for a superuser JWT, generally don’t apply. Any client that can reach the server has full access.

Security:

Requests using the HTTP OPTIONS method are answered by ArangoDB in any case, even if no authentication data is sent by the client or if the authentication data is wrong. This is required for handling CORS preflight requests (see Cross Origin Resource Sharing requests). The response to an HTTP OPTIONS request is generic and doesn’t expose any private data.

There is an additional option to control authentication for custom Foxx apps. The --server.authentication-system-only startup option controls whether authentication is required only for requests to the internal database APIs and the admin interface. It is turned on by default, meaning that other APIs (this includes custom Foxx apps) do not require authentication.

The default values allow exposing a public custom Foxx API built with ArangoDB to the outside world without the need for HTTP authentication, but still protecting the usage of the internal database APIs (i.e. /_api/, /_admin/) with HTTP authentication.

If the server is started with the --server.authentication-system-only option set to false, all incoming requests need HTTP authentication if the server is configured to require HTTP authentication (i.e. --server.authentication true). Setting the option to true makes the server require authentication only for requests to the internal database APIs and allows unauthenticated requests to all other URLs.

Here is a short summary:

  • --server.authentication true --server.authentication-system-only true: This requires authentication for all requests to the internal database APIs but not custom Foxx apps. This is the default setting.
  • --server.authentication true --server.authentication-system-only false: This requires authentication for all requests (including custom Foxx apps).
  • --server.authentication false: Authentication is disabled for all requests.

Whenever authentication is required and the client has not yet authenticated, ArangoDB returns HTTP 401 (Unauthorized). It also sends the Www-Authenticate response header, indicating that the client should prompt the user for username and password if supported. If the client is a browser, then sending back this header normally triggers the display of the browser-side HTTP authentication dialog. As showing the browser HTTP authentication dialog is undesired in AJAX requests, ArangoDB can be told to not send the Www-Authenticate header back to the client. Whenever a client sends the X-Omit-Www-Authenticate HTTP header (with an arbitrary value) to the server, ArangoDB only sends status code 401, but no Www-Authenticate header. This allows clients to implement credentials handling and bypassing the browser’s built-in dialog.

HTTP Basic Authentication

ArangoDB supports basic authentication with a user name and password. The name and the password of an ArangoDB user account need to be separated by a colon and the entire string needs to be Base64-encoded. The resulting value can be used in the Authorization header of an HTTP request, indicating that the authorization scheme is Basic.

For example, if the name is user and the password pass, the temporary string that needs to be encoded is user:pass. The Base64-encoded value is dXNlcjpwYXNz (e.g. using the btoa() JavaScript function in a browser). The HTTP request header to authenticate is a follows:

Authorization: Basic dXNlcjpwYXNz

If you use a tool like cURL, you can manually specify this header as follows:

curl -H 'Authorization: Basic dXNlcjpwYXNz' ...

However, cURL can also take care of the authentication and specifically the encoding of the credentials for you:

curl -u user:pass ...
Security:

Encoding credentials using the Base64 scheme does not encrypt them. Base64-encoded strings can easily be decoded. Be careful not to expose the encoded credentials by accident. It is recommended to secure connections with ArangoDB servers using TLS for encryption in transit.

Bearer Token Authentication

ArangoDB supports authentication with JSON Web Tokens (JWT). For more information on JWT, please consult RFC 7519 and jwt.io.

To authenticate via JWT, send the token in the Authorization HTTP header of your requests:

Authorization: Bearer eyJhbGciOiJIUzI1NiI..x6EfI

The server signs tokens with its active JWT secret. You can set the JWT secrets on server startup in one of the following ways:

  • Set --server.jwt-secret-keyfile to let the server read the JWT secret from the specified file.
  • Set --server.jwt-secret-folder to specify a path and let the server read JWT secrets from multiple files (only one is used for signing). This option is only available in the Enterprise Edition.
  • Not specify either option to let the server generate a random JWT secret.
  • Don’t use the deprecated --server.jwt-secret startup option to set a JWT secret directly, as this may leak the secret (e.g. via the process list).

The JWT secret is a shared secret with a length of up to 64 bytes. Tokens are signed via HMAC with SHA-256 (HS256).

JWT types

ArangoDB distinguishes the following kinds of JWTs:

TypeHow to obtainAuthenticates asExpiry time
Session tokenRequest it from the server with a username and password. No JWT secret is needed.The user, with the user’s permissionsAlways, after one hour by default
User tokenGenerate and sign it yourself using the active JWT secret.The user, with the user’s permissionsOptional, usually none
Superuser tokenGenerate and sign it yourself using the active JWT secret.No user, with full access including internal APIsOptional, usually none

The decoded payload of a JWT can contain the following fields (claims):

ClaimDescription
issRequired. Must be the string "arangodb".
preferred_usernameThe name of the user account to authenticate as. Session tokens and user tokens contain it. The user account must exist.
server_idAn arbitrary string identifier. Required if preferred_username is not set, which makes the token a superuser token.
expThe expiry time as Unix timestamp in seconds. Optional, but session tokens always have it.
iatThe time the token has been issued as Unix timestamp in seconds. Optional.
allowed_pathsAn array of request paths that the token can be used for, without the /_db/<database-name> prefix, like "/_api/version". Requests to other paths are rejected. Optional.

If you generate tokens yourself, set the alg field in the JWT header to HS256.

Validity and revocation of JWTs

JWTs are stateless: the server doesn’t store the tokens it issues. It accepts every token with a valid signature, and it cannot revoke individual tokens. A JWT is valid until one of the following happens:

  • It reaches its expiry time (exp), if it has one.
  • The server no longer has a JWT secret that can verify the token. If you rotate the secret using the --server.jwt-secret-folder startup option, tokens signed with a previous secret remain valid as long as the folder contains that secret as a passive secret. Any of the JWT secrets can verify tokens, but only the active one signs them. You can hot-reload the JWT secrets without a restart.
  • For session tokens and user tokens, no active user account exists for the username in the token’s preferred_username field. This is the case if the account has been removed.

Changing the password of a user account doesn’t invalidate tokens that have already been issued for it. Tokens also aren’t bound to a particular user account instance, only to the username: if you remove a user account and later create a new account with the same username, previously issued tokens for that username become valid again, regardless of the new account’s password. User tokens and superuser tokens without an expiry time stay valid until the JWT secret that signed them is removed, so treat them as sensitive as the JWT secrets themselves.

JWT session tokens

A session token is a JWT that the server issues for a user account. You don’t need to know the JWT secret, only the credentials of the user account. The web interface uses session tokens, for example.

To obtain a session token, send a POST request to the following endpoint:

POST /_open/auth

The request body needs to contain the username and password JSON-encoded like so:

{
  "username": "root",
  "password": "rootPassword"
}

On success, the endpoint returns a 200 OK and an answer containing the JWT in a JSON-encoded object like so:

{ "jwt": "eyJhbGciOiJIUzI1NiI..x6EfI" }

This JWT should then be used within the Authorization HTTP header in subsequent requests:

Authorization: Bearer eyJhbGciOiJIUzI1NiI..x6EfI
Security:

The JWT token expires after one hour by default and needs to be updated. You can configure the token lifetime via the --server.session-timeout startup option.

You can find the expiration date of the JWT token in the exp field, encoded as Unix timestamp in seconds. As an example, the decoded JWT body of a session token looks like this:

{
  "exp": 1540381557,
  "iat": 1540377957,
  "iss": "arangodb",
  "preferred_username": "root"
}

Create a JWT session token

POST http://<EXTERNAL_ENDPOINT>:8529/_open/auth

Obtain a JSON Web Token (JWT) from the credentials of an ArangoDB user account. You can use the JWT in the Authorization HTTP header as a Bearer token to authenticate requests.

The lifetime for the token is controlled by the --server.session-timeout startup option.

Request Body application/json object
  • The password of the ArangoDB user.

  • The name of an ArangoDB user.

Responses
  • Successfully created a session token.

      Response Body application/json object
    • The encoded JWT session token.

  • An HTTP 400 Bad Request status code is returned if the request misses required attributes or if it is otherwise malformed.

  • An HTTP 401 Unauthorized status code is returned if the user credentials are incorrect.

  • An HTTP 404 Not Found status code is returned if the server has authentication disabled and the endpoint is thus not available.

JWT user tokens

If you know the active JWT secret, you can generate and sign a token for a user account yourself. A user token authenticates as the user specified in the preferred_username field and grants the permissions of this user, the same as a session token.

Unlike for session tokens, you decide which claims the token contains. In particular, a user token doesn’t need an expiry time. Without one, it stays valid until the JWT secret that signed it is removed or the user account is removed. See Validity and revocation of JWTs.

Security:

Anyone who knows any of the JWT secrets of the server, active or passive, can generate this JWT token, because the server accepts tokens signed with either.

You can generate a user token with the ArangoDB Starter CLI by specifying the user with the --auth.user option.

Should you wish to generate the JWT token yourself with a tool of your choice, the body must contain the iss field with string value arangodb and the preferred_username field with the name of the user account:

{
  "iat": 1537800279,
  "iss": "arangodb",
  "preferred_username": "root"
}

For example, to generate such a token via the jwtgen tool:

jwtgen -s <my-secret> -v -a "HS256" -c 'iss=arangodb' -c 'preferred_username=root'

JWT superuser tokens

To access specific internal APIs as well as Agency and DB-Server instances a session token or user token is not good enough. For these special APIs, you need to generate a special JWT token which grants superuser access. Note that using superuser access for normal database operations is not advised.

Security:

Anyone who knows any of the JWT secrets of the server, active or passive, can generate this JWT token, because the server accepts tokens signed with either.

For your convenience it is possible to generate this token via the ArangoDB Starter CLI.

Should you wish to generate the JWT token yourself with a tool of your choice, you need to include the correct body. The body must contain the iss field with string value arangodb and the server_id field with an arbitrary string identifier, but no preferred_username field. The exp field is optional. Without it, the token stays valid until the JWT secret that signed it is removed. The following example body includes an expiry time:

{
  "exp": 1537900279,
  "iat": 1537800279,
  "iss": "arangodb",
  "server_id": "myclient"
}

For example to generate a token via the jwtgen tool (note the lifetime of one hour):

jwtgen -s <my-secret> -e 3600 -v -a "HS256" -c 'iss=arangodb' -c 'server_id=myclient'
curl -v -H "Authorization: bearer $(jwtgen -s <my-secret> -e 3600 -a "HS256" -c 'iss=arangodb' -c 'server_id=myclient')" http://<database-ip>:8529/_api/version

Hot-reload JWT secrets

ArangoDB Enterprise Edition

To reload the JWT secrets of a local arangod process without a restart, you may use the following HTTP API. A POST request reloads the secret, a GET request may be used to load information about the currently used secrets.

Get the hashes of the loaded JWT secrets

GET http://<EXTERNAL_ENDPOINT>:8529/_db/:database-name/_admin/server/jwt
Get the SHA-256 hashes of the currently loaded JWT secrets.
Path Parameters
  • The name of a database. Which database you use doesn’t matter as long as the user account you authenticate with has at least ro access to this database. If the --server.harden startup option is enabled, rw access to the _system database is required.

    Example: _system

Query Parameters
    HTTP Headers
      Responses
      • Successfully retrieved the JWT secret information.

          Response Body application/json object
          The reply with the JWT secrets information.
        • The HTTP response status code.

          Example: 200

        • A flag indicating that no error occurred.

          Example: false

        • The result object.

          • An object with the SHA-256 hash of the active secret.

          • An array of objects with the SHA-256 hashes of the passive secrets.

            Can be empty.

      • if the request was not authenticated as a user with sufficient rights

      Hot-reload the JWT secret(s) from disk

      POST http://<EXTERNAL_ENDPOINT>:8529/_admin/server/jwt

      Sending a request without payload to this endpoint reloads the JWT secret(s) from disk. Only the files specified via the arangod startup option --server.jwt-secret-keyfile or --server.jwt-secret-folder are used. It is not possible to change the locations where files are loaded from without restarting the process.

      This endpoint requires a superuser JWT. User accounts, including root, are not sufficient.

      Responses
      • Successfully reloaded the JWT secrets.

          Response Body application/json object
          The reply with the JWT secrets information.
        • The HTTP response status code.

          Example: 200

        • A flag indicating that no error occurred.

          Example: false

        • The result object.

          • An object with the SHA-256 hash of the active secret.

          • An array of objects with the SHA-256 hashes of the passive secrets.

            Can be empty.

      • The JWT secrets cannot be reloaded because no JWT secret file is configured. This is the case if the server has been started with the deprecated --server.jwt-secret startup option or with no JWT secret at all.

          Response Body application/json object
        • The HTTP response status code.

          Example: 400

        • A flag indicating that an error occurred.

          Example: true

        • A descriptive error message.

        • The ArangoDB error number for the error that occurred.

          Example: 10

      • if the request was not authenticated as a user with sufficient rights

      Example result:

      {
        "error": false,
        "code": 200,
        "result": {
          "active": {
            "sha256": "c6c1021286dfe870b7050f9e704df93c7f1de3c89dbdadc3fb30394bebd81e97"
          },
          "passive": [
            {
              "sha256": "6d2fe32dc4249ef7e7359c6d874fffbbf335e832e49a2681236e1b686af78794"
            },
            {
              "sha256": "448a28491967ea4f7599f454af261a685153c27a7d5748456022565947820fb9"
            },
            {
              "sha256": "6745d49264bdfc2e89d4333fe88f0fce94615fdbdb8990e95b5fda0583336da8"
            }
          ]
        }
      }