aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2022-10-03 07:35:27 -0500
committerJP Dillingham <jp@dillingham.me>2022-10-03 07:35:27 -0500
commit56567464a5955ce6be66769ddec4acea90ac36b5 (patch)
tree9f50ff24d89ed4477b3f7c3790760191c19bf519
parent6f75ffa2ebf07999bd90396ad8ee3b09146d7321 (diff)
downloadslskd-56567464a5955ce6be66769ddec4acea90ac36b5.tar.gz
docs
-rw-r--r--docs/config.md10
-rw-r--r--src/slskd/Common/Authentication/ApiKeyAuthentication.cs3
2 files changed, 13 insertions, 0 deletions
diff --git a/docs/config.md b/docs/config.md
index 5ad80033..a4c1c8ee 100644
--- a/docs/config.md
+++ b/docs/config.md
@@ -558,6 +558,12 @@ By default, a random JWT secret key is generated at each start. It is convenient
The JWT TTL option determines how long issued JWTs are valid, defaulting to 7 days.
+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.
+
+An optional comma separated list of [CIDRs](https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing) can be defined for each key, which will restrict usage of the key to callers with a remote IP address that falls within one of the defined CIDRs. The default CIDR list for each key is `0.0.0.0/0,::0`, which applies to any IP address (IPv4 or IPv6).
+
+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.
+
| Command-Line | Environment Variable | Description |
| ---------------- | -------------------- | --------------------------------------------------- |
| `-X\|--no-auth` | `NO_AUTH` | Determines whether authentication is to be disabled |
@@ -576,6 +582,10 @@ web:
jwt:
key: ~
ttl: 604800000
+ api_keys:
+ my_api_key:
+ key: <some example string between 16 and 255 characters>
+ cidr: 0.0.0.0/0,::/0
```
# Filters
diff --git a/src/slskd/Common/Authentication/ApiKeyAuthentication.cs b/src/slskd/Common/Authentication/ApiKeyAuthentication.cs
index 08cfa3b6..8baae3f9 100644
--- a/src/slskd/Common/Authentication/ApiKeyAuthentication.cs
+++ b/src/slskd/Common/Authentication/ApiKeyAuthentication.cs
@@ -85,6 +85,9 @@ namespace slskd.Authentication
}
else if (apiKeyOptions.EnableSignalRSupport && Request.Path.StartsWithSegments(apiKeyOptions.SignalRRoutePrefix) && Request.Query.ContainsKey("access_token"))
{
+ // assign the request token from the access_token query parameter
+ // but only if the destination is a SignalR hub
+ // https://docs.microsoft.com/en-us/aspnet/core/signalr/authn-and-authz?view=aspnetcore-5.0
key = Request.Query["access_token"];
}
else