From 804f661ab5d0e3b6ffdfd6a5b38959ac1b1690be Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 13 Dec 2025 16:11:45 -0600 Subject: docs for API keys --- docs/config.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'docs') diff --git a/docs/config.md b/docs/config.md index 40f186f6..6ba5bd2a 100644 --- a/docs/config.md +++ b/docs/config.md @@ -864,10 +864,16 @@ web: Authentication for the web UI (and underlying API) is enabled by default, and the default username and password are both `slskd`. Changing both the username and password during the initial configuration is highly recommended. +### JWT (Json Web Token) + +JWTs are used to authenticate the UI, and are generated by making an API call and supplying a username and password. + By default, a random JWT secret key is generated at each start. It is convenient and secure, but restarting the application will invalidate any issued JWTs, causing users to sign in again. To avoid this, supply a custom secret at least 16 characters in length. Note that the secret can be used to generate valid JWTs for the application, so keep this value secret. The JWT TTL option determines how long issued JWTs are valid, defaulting to 7 days. +### API Keys + API keys can be configured to allow for secure communication without requiring the caller to obtain a JWT by signing in with a username and password. Each key must be given a name and a key with a length between 16 and 255 characters (inclusive). Callers may then supply one of the configured keys in the `X-API-Key` header when making web requests. Remember that API keys are secrets, so keep them safe. You can generate a random, 32 bit API key by starting the application with `--generate-secret` at the command line. @@ -876,6 +882,15 @@ An optional comma separated list of [CIDRs](https://en.wikipedia.org/wiki/Classl A common use case for CIDR filtering might be to restrict API access to clients within your home network. Assuming your network uses the common `192.168.1.x` addressing, you could specify a `cidr` of `192.168.1.0/24`, which would apply to any IP between `192.168.1.1` and `192.168.1.254`, inclusive. +An optional 'primary' API key can be configured by passiing it via `-k` or `--api-key` on the command line, or by setting the `SLSKD_API_KEY` environment variable. As with other API keys, a role and list of CIDRs can be supplied, but because the command line and environment variables are limited to a simple string, the role and CIDRs must be passed via tuples separated by semicolons: + +``` +role=ReadOnly;cidr=0.0.0.0/0,::/0;<16 to 255 character string> +``` + +By default, the role associated with the 'primary' API key is `Administrator` (other API keys default to `ReadOnly`) and list of CIDRs is `0.0.0.0/0,::0` (same as other API keys). + +#### Cautions Note that CIDR filtering may not work as expected behind a reverse proxy, ingress controller, or load balancer, because the remote IP address will be that of the device that's handling ingress. This application doesn't support the `X-Forwarded-For` header (or anything like it) because a bad actor can easily fake it. If you wish to use CIDR filtering in this scenario, you'll need to do it at the point of ingress to your network. Please also note that using API key authentication without HTTPS is **NOT RECOMMENDED**. API keys are sent in HTTP headers (and in the case of SignalR, in query parameters) and will be easily accessible to anyone eavesdropping on the network. This is a risk with JWTs as well, but JWTs expire and API keys don't. If you choose to use API keys over plain HTTP, seriously consider using CIDR filtering. @@ -885,6 +900,7 @@ Please also note that using API key authentication without HTTPS is **NOT RECOMM | `-X\|--no-auth` | `SLSKD_NO_AUTH` | Determines whether authentication is to be disabled | | `-u\|--username` | `SLSKD_USERNAME` | The username for the web UI | | `-p\|--password` | `SLSKD_PASSWORD` | The password for the web UI | +| `-k\|--api-key` | `SLSKD_API_KEY` | The primary API key | | `--jwt-key` | `SLSKD_JWT_KEY` | The secret key used to sign JWTs | | `--jwt-ttl` | `SLSKD_JWT_TTL` | The TTL (duration) of JWTs, in milliseconds | -- cgit v1.2.3 From 0d548ed62517ed1807d3c13f96772f33a9a3c1d1 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 13 Dec 2025 16:33:37 -0600 Subject: warning about ipv6 --- docs/config.md | 3 +++ 1 file changed, 3 insertions(+) (limited to 'docs') diff --git a/docs/config.md b/docs/config.md index 6ba5bd2a..1ab7daec 100644 --- a/docs/config.md +++ b/docs/config.md @@ -891,6 +891,9 @@ role=ReadOnly;cidr=0.0.0.0/0,::/0;<16 to 255 character string> By default, the role associated with the 'primary' API key is `Administrator` (other API keys default to `ReadOnly`) and list of CIDRs is `0.0.0.0/0,::0` (same as other API keys). #### Cautions + +When using CIDR filtering, you *must* supply both IPv4 and IPv6 ranges. + Note that CIDR filtering may not work as expected behind a reverse proxy, ingress controller, or load balancer, because the remote IP address will be that of the device that's handling ingress. This application doesn't support the `X-Forwarded-For` header (or anything like it) because a bad actor can easily fake it. If you wish to use CIDR filtering in this scenario, you'll need to do it at the point of ingress to your network. Please also note that using API key authentication without HTTPS is **NOT RECOMMENDED**. API keys are sent in HTTP headers (and in the case of SignalR, in query parameters) and will be easily accessible to anyone eavesdropping on the network. This is a risk with JWTs as well, but JWTs expire and API keys don't. If you choose to use API keys over plain HTTP, seriously consider using CIDR filtering. -- cgit v1.2.3 From 1e0eb94a16fd6b8a3204bc14e11c0c5d47617d0c Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 13 Dec 2025 16:35:06 -0600 Subject: on second thought, remove caution --- docs/config.md | 2 -- 1 file changed, 2 deletions(-) (limited to 'docs') diff --git a/docs/config.md b/docs/config.md index 1ab7daec..3efe2e8a 100644 --- a/docs/config.md +++ b/docs/config.md @@ -892,8 +892,6 @@ By default, the role associated with the 'primary' API key is `Administrator` (o #### Cautions -When using CIDR filtering, you *must* supply both IPv4 and IPv6 ranges. - Note that CIDR filtering may not work as expected behind a reverse proxy, ingress controller, or load balancer, because the remote IP address will be that of the device that's handling ingress. This application doesn't support the `X-Forwarded-For` header (or anything like it) because a bad actor can easily fake it. If you wish to use CIDR filtering in this scenario, you'll need to do it at the point of ingress to your network. Please also note that using API key authentication without HTTPS is **NOT RECOMMENDED**. API keys are sent in HTTP headers (and in the case of SignalR, in query parameters) and will be easily accessible to anyone eavesdropping on the network. This is a risk with JWTs as well, but JWTs expire and API keys don't. If you choose to use API keys over plain HTTP, seriously consider using CIDR filtering. -- cgit v1.2.3