Slurm provides a REST API through the slurmrestd daemon, using JSON Web Tokens for authentication. This page provides a brief tutorial for setting up these components.
See also:
The following development libraries are required at compile time in order for slurmrestd to be compiled (minimum versions are on the related software page linked below):
Additionally, it is highly recommended that you have SlurmDBD set up for accounting. Without slurmdbd, slurmrestd may fail when loading some plugins (use -s to specify which to load) or when attempting JWT authentication.
This may be done on a dedicated REST API machine or your existing 'slurmctld' machine, depending on demand. If you have multiple clusters, you will need a unique instance of slurmrestd for each cluster.
slurm-smd slurm-smd-slurmrestdslurm slurm-slurmrestd (requires
--with slurmrestd at build time)/etc/slurm/slurm.conf is present and correct for your
cluster (see Quick Start Admin Guide and
slurm.conf man page)export SLURM_JWT=daemon export SLURMRESTD_DEBUG=debug slurmrestd <host>:<port>Adjust SLURMRESTD_DEBUG to the desired level of output (as described on the man page)
Slurm ships with a slurmrestd service unit for systemd,
however, it might require some additional setup to run properly.
This section assumes you have either installed slurmrestd using DEB/RPM packages
or built it manually such that the files are in the same places.
Note the versions associated with certain steps in the instructions
below; these steps should be ignored on other versions.
sudo useradd -M -r -s /usr/sbin/nologin -U slurmrestd
/etc/default/slurmrestd
or /etc/sysconfig/slurmrestd
-u slurmrestd and -g slurmrestd
to SLURMRESTD_OPTIONSsystemctl edit slurmrestd to edit overrides for the
service.
[Service] User=slurmrestd Group=slurmrestd
SLURMRESTD_LISTEN
(see Customizing slurmrestd.service).systemctl edit slurmrestd[Service] section:
ExecStart= ExecStart=/usr/sbin/slurmrestd $SLURMRESTD_OPTIONS Environment=SLURMRESTD_LISTEN=:6820
The Slurm 24.05 release changes the operation of
the default service file and may break existing overrides. If you have
overridden ExecStart= to contain any TCP/UNIX sockets directly, it
will cause the service to fail if it duplicates any sockets contained in
SLURMRESTD_LISTEN. These overrides will need to be changed after upgrading.
The default slurmrestd.service file has two intended ways of
customizing its operation:
/etc/default/slurmrestd and /etc/sysconfig/slurmrestd.
You may set any environment variables recognized by
slurmrestd,
but the following are particularly relevant:
systemctl edit slurmrestd.
[Service]).Environment=NAME=value
(refer to systemd documentation for more details)systemctl revert slurmrestd
slurmrestd -d list
unset SLURM_JWT; export $(scontrol token)
lifespan=SECONDS to the 'scontrol' command to change this.curl -s -o "/tmp/curl.log" -k -vvvv \ -H X-SLURM-USER-TOKEN:$SLURM_JWT \ -X GET 'http://<server>:<port>/slurm/v0.0.<api-version>/diag'
curl -s -o "/tmp/curl.log" -k -vvvv \ -H X-SLURM-USER-TOKEN:$SLURM_JWT \ --unix-socket /path/to/slurmrestd.socket \ 'http://<server>/slurm/v0.0.<api-version>/diag'
This guide provides a simple overview using scontrol to
obtain tokens. This is a basic introductory approach that in many cases
should be disabled in favor of more sophisticated token management.
Refer to the JWT page for more details.
Information about ways to further customize and configure slurmrestd, including authentication methods, run modes, plugins, high availability, and proxies, is found on the REST API Reference page.
In general, look out for these things:
SLURM_JWTThis may be due to a permissions issue while attempting to set up the socket. Check the log output from slurmrestd for the path to the socket. Ensure that the user running the slurmrestd service has permissions to the parent directory of the configured socket path, or change/remove the socket path as described above.
If it says "Address already in use", check the command being run and the contents of "SLURMRESTD_LISTEN" for duplicates of the same TCP or UNIX socket.
Verify that slurmrestd is running and listening on the port you are attempting to connect to.
One common authentication problem is an expired token. Request a new one:
unset SLURM_JWT; export $(scontrol token)
This solution also applies to an HTTP 401 error caused by no authentication token being sent at all. This may appear in the slurmrestd logs as "Authentication does not apply to request."
Otherwise, consult the logs on the slurmctld and slurmdbd.
Check the API Reference page to ensure you're using a valid URL and the correct method for it. Pay attention to the path as there are different endpoints for slurm and slurmdbd.
Check that slurmrestd has loaded the auth/jwt plugin. You should see a debug message like this:
slurmrestd: debug: auth/jwt: init: JWT authentication plugin loadedIf it didn't load jwt, run this in the terminal you're using for slurmrestd:
export SLURM_JWT=daemon
Check the request URL and slurmrestd logs for characters that may be causing the URL to be parsed incorrectly. Use the appropriate URL encoding sequence in place of the problematic character (e.g., / = %2F).
... -X GET "localhost:8080/slurmdb/v0.0.40/jobs?submit_time=02/28/24" ### 400 BAD REQUEST ... -X GET "localhost:8080/slurmdb/v0.0.40/jobs?submit_time=02%2F28%2F24" ### 200 OK
If SLURM_JWT is set, other slurm commands will attempt to use JWT authentication, causing failures. This can be fixed by clearing the variable:
unset SLURM_JWT
Last modified 21 April 2025