From c82edcd0d4819f359df0c763dcf69a457d35f8a8 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 21 Mar 2023 09:36:30 -0500 Subject: fix logger --- src/slskd/Relay/API/Hubs/RelayHub.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/slskd/Relay/API/Hubs/RelayHub.cs b/src/slskd/Relay/API/Hubs/RelayHub.cs index e246711e..48d03c90 100644 --- a/src/slskd/Relay/API/Hubs/RelayHub.cs +++ b/src/slskd/Relay/API/Hubs/RelayHub.cs @@ -89,7 +89,7 @@ namespace slskd.Relay OptionsAtStartup = optionsAtStartup; } - private ILogger Log { get; } = Serilog.Log.ForContext(); + private ILogger Log { get; } = Serilog.Log.ForContext(); private IRelayService Relay { get; } private IOptionsMonitor OptionsMonitor { get; } private OptionsAtStartup OptionsAtStartup { get; } -- cgit v1.2.3 From 199d24e28b860b3a042d2a569cdfebd066e41be0 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 21 Mar 2023 09:37:02 -0500 Subject: fetch agent config by InstanceName property instead of key --- src/slskd/Relay/API/Hubs/RelayHub.cs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/slskd/Relay/API/Hubs/RelayHub.cs b/src/slskd/Relay/API/Hubs/RelayHub.cs index 48d03c90..11410804 100644 --- a/src/slskd/Relay/API/Hubs/RelayHub.cs +++ b/src/slskd/Relay/API/Hubs/RelayHub.cs @@ -138,9 +138,24 @@ namespace slskd.Relay /// Thrown when the challenge response is invalid. public void Login(string agent, string challengeResponse) { - OptionsMonitor.CurrentValue.Relay.Agents.TryGetValue(agent, out var agentOptions); + bool TryGetAgentConfig(string agent, out Options.RelayOptions.RelayAgentConfigurationOptions options) + { + var agentOptions = OptionsMonitor.CurrentValue.Relay.Agents; + var found = agentOptions.Values.SingleOrDefault(a => a.InstanceName == agent); + + if (found != default) + { + options = found; + return true; + } + + Log.Warning("Unable to locate Agent config for '{Agent}' (configured Agents: {Agents})", agent, string.Join(", ", agentOptions.Values.Select(a => a.InstanceName))); + + options = null; + return false; + } - if (agentOptions == default) + if (!TryGetAgentConfig(agent, out var agentOptions)) { Log.Warning("Unauthorized login attempt from unknown Agent {Agent} (connection {Id}) from {IP}", agent, Context.ConnectionId, RemoteIpAddress); throw new UnauthorizedAccessException(); -- cgit v1.2.3 From 82d8a3b17d27acd28f1398672f83e18d442c80d4 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 21 Mar 2023 14:01:26 -0500 Subject: tweak validation --- src/slskd/Core/Options.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs index c9b46239..1d9f814c 100644 --- a/src/slskd/Core/Options.cs +++ b/src/slskd/Core/Options.cs @@ -438,6 +438,14 @@ namespace slskd } else { + // determine whether any InstanceName is used more than once + var instanceNames = Agents.Values.Select(a => a.InstanceName); + + if (instanceNames.Count() != instanceNames.Distinct().Count()) + { + modeResults.Add(new ValidationResult("One or more Agent instance names are duplicated. Ensure instance names are unique.")); + } + foreach (var (name, agent) in Agents) { var res = new List(); @@ -515,6 +523,15 @@ namespace slskd /// public class RelayAgentConfigurationOptions : IValidatableObject { + /// + /// Gets the agent instance name. + /// + [Description("the name for this agent")] + [StringLength(255, MinimumLength = 1)] + [NotNullOrWhiteSpace] + [Secret] + public string InstanceName { get; init; } + /// /// Gets the agent secret. /// -- cgit v1.2.3 From 32cb13db1ff7c82b2aac6cf8f8638e3866d4752e Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 21 Mar 2023 14:01:36 -0500 Subject: update example yaml --- config/slskd.example.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/config/slskd.example.yml b/config/slskd.example.yml index f58e2f6e..cbf59dab 100644 --- a/config/slskd.example.yml +++ b/config/slskd.example.yml @@ -26,6 +26,7 @@ # # this specifies all of the agents capable of connecting # agents: # my_agent: +# instance_name: my_agent # make sure the top-level instance_name of the agent matches! # secret: # cidr: 0.0.0.0/0,::/0 # directories: -- cgit v1.2.3 From 19d1fa20c090b1152e97858d7230106ae1a695a6 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 21 Mar 2023 14:22:35 -0500 Subject: update docs --- docs/config.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/config.md b/docs/config.md index cd68c45a..720878b6 100644 --- a/docs/config.md +++ b/docs/config.md @@ -198,7 +198,7 @@ Controllers must have at least one API key configured. For increased security i The relay mode for the controller must be set to `controller`, and the relay must be enabled. -For each agent, the agent's name (corresponding to the configured instance name of the agent) must be specified in the agent map, and a different secret value between 16-255 characters should be specified for each agent. +For each agent, the agent must be specified in the `agents` map, including an `instance_name` that corresponds to the top-level `instance_name` configured for the agent, and a different secret value between 16-255 characters should be specified for each agent. It is strongly suggested that controllers be configured to force HTTPS. This makes the traffic between the controller and agents completely private, and prevents API keys and agent secrets from being exposed. @@ -208,8 +208,10 @@ relay: mode: controller agents: some_instance: + instance_name: some_instance secret: a_different_instance: + instance_name: different_instance secret: ``` @@ -220,7 +222,7 @@ relay: ## Agents -The relay mode for agents must be set to `agent`, the relay must be enabled, and each agent must have a unique instance name that corresponds to an agent configured in the controller. +The relay mode for agents must be set to `agent`, the relay must be enabled, and each agent must have a unique instance name that corresponds to the `instance_name` of an agent configured in the controller. Agents need to specify the HTTP or HTTPS address of their controller, the API key for the controller, and the secret that corresponds to the value configured in the controller for the agent. -- cgit v1.2.3 From a1e0187ffc59d4ca326008bd6865d7d962db3a09 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 21 Mar 2023 14:23:36 -0500 Subject: update relay docs --- docs/relay.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/relay.md b/docs/relay.md index c1f09b4a..47c201f2 100644 --- a/docs/relay.md +++ b/docs/relay.md @@ -85,6 +85,7 @@ relay: mode: controller agents: example: + instance_name: example_agent secret: BgI04SuVtsAYipxPHDpdxJsnVoPEeq4tKJeorWxr3Pj cidr: 192.168.1.0/24 web: @@ -120,7 +121,7 @@ To demonstrate how file relays work, I've created a file `foo.txt` in `~/Music/t The entire `slskd.yml` file is below if you'd like to copy/paste it. Be sure to update the controller's address to the IP address of the machine the controller is working on. ```yaml -instance_name: example +instance_name: example_agent relay: enabled: true mode: agent -- cgit v1.2.3 From 289c7532b340fcc04c9aaa6c9b4b3edfe0adcba7 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 21 Mar 2023 14:25:44 -0500 Subject: update example logs --- docs/relay.md | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/docs/relay.md b/docs/relay.md index 47c201f2..6ba22048 100644 --- a/docs/relay.md +++ b/docs/relay.md @@ -72,7 +72,7 @@ For this example we'll use `9tWy5c3NrmekKVWLQXBztz0hY7rNGlj1tGMfvHKmU1q` for the ### Controller -Next, we'll configure the controller. We'll enable the Relay, set this instance's mode to `controller`, and configure a single agent named `example`. We'll accept connections from within our home network, which uses IP addresses in the 192.168.1.x range. +Next, we'll configure the controller. We'll enable the Relay, set this instance's mode to `controller`, and configure a single agent named `example_agent`. We'll accept connections from within our home network, which uses IP addresses in the 192.168.1.x range. We'll also need to create an API key, which we'll allow to be used from anywhere. We'll give the key the role `readwrite`, which is required for agents. @@ -152,14 +152,14 @@ The controller should show logs similar to the following: ``` [19:09:30 INF] Agent connection GyBMnXHfdomNzR2FEzT68Q from 192.168.1.250 established. Sending authentication challenge GU7pSFTG60skUtqM24FfB2WiUnWsC1LxYagBsz7edcp... -[19:09:30 INF] Agent connection GyBMnXHfdomNzR2FEzT68Q from 192.168.1.250 authenticated as agent example -[19:09:31 INF] Agent example (connection GyBMnXHfdomNzR2FEzT68Q) from 192.168.1.250 requested share upload token f81eb299-1a86-4f72-a77c-922d3f73106f -[19:09:31 INF] Handling share upload (f81eb299-1a86-4f72-a77c-922d3f73106f) from a caller claiming to be agent example -[19:09:31 INF] Agent example authenticated for token f81eb299-1a86-4f72-a77c-922d3f73106f. Beginning download of shares to /tmp/slskd/share_example_h0ycner1.svm.db -[19:09:31 INF] Download of shares from example (f81eb299-1a86-4f72-a77c-922d3f73106f) complete (48.0 KB in 2ms) -[19:09:31 INF] Loading shares from agent example +[19:09:30 INF] Agent connection GyBMnXHfdomNzR2FEzT68Q from 192.168.1.250 authenticated as agent example_agent +[19:09:31 INF] Agent example_agent (connection GyBMnXHfdomNzR2FEzT68Q) from 192.168.1.250 requested share upload token f81eb299-1a86-4f72-a77c-922d3f73106f +[19:09:31 INF] Handling share upload (f81eb299-1a86-4f72-a77c-922d3f73106f) from a caller claiming to be agent example_agent +[19:09:31 INF] Agent example_agent authenticated for token f81eb299-1a86-4f72-a77c-922d3f73106f. Beginning download of shares to /tmp/slskd/share_example_h0ycner1.svm.db +[19:09:31 INF] Download of shares from example_agent (f81eb299-1a86-4f72-a77c-922d3f73106f) complete (48.0 KB in 2ms) +[19:09:31 INF] Loading shares from agent example_agent [19:09:31 INF] Warming browse response cache... -[19:09:31 INF] Shares from agent example ready. +[19:09:31 INF] Shares from agent example_agent ready. [19:09:31 INF] Browse response cached successfully in 25ms ``` @@ -170,12 +170,12 @@ We're now ready to relay files! From another machine running a different Soulseek client, download the `foo.txt` file we shared as a test. The controller should show logs similar to the following: ``` -[19:19:34 INF] Resolved Music\test\foo.txt to physical file /home/kubuntu/Music/test/foo.txt on host 'example' -[19:19:35 INF] Requested file Music\test\foo.txt from Agent example with ID 09e76dde-c4fa-4c50-8c25-d92a26b52102. Waiting for incoming connection. -[19:19:35 INF] Handling file upload of Music\test\foo.txt (09e76dde-c4fa-4c50-8c25-d92a26b52102) from a caller claiming to be agent example -[19:19:35 INF] Agent example authenticated for token 09e76dde-c4fa-4c50-8c25-d92a26b52102. Forwarding file stream for Music\test\foo.txt -[19:19:35 INF] Agent example provided file stream for file Music\test\foo.txt with ID 09e76dde-c4fa-4c50-8c25-d92a26b52102 -[19:19:35 INF] File upload of Music\test\foo.txt (09e76dde-c4fa-4c50-8c25-d92a26b52102) from agent example complete +[19:19:34 INF] Resolved Music\test\foo.txt to physical file /home/kubuntu/Music/test/foo.txt on host 'example_agent' +[19:19:35 INF] Requested file Music\test\foo.txt from Agent example_agent with ID 09e76dde-c4fa-4c50-8c25-d92a26b52102. Waiting for incoming connection. +[19:19:35 INF] Handling file upload of Music\test\foo.txt (09e76dde-c4fa-4c50-8c25-d92a26b52102) from a caller claiming to be agent example_agent +[19:19:35 INF] Agent example_agent authenticated for token 09e76dde-c4fa-4c50-8c25-d92a26b52102. Forwarding file stream for Music\test\foo.txt +[19:19:35 INF] Agent example_agent provided file stream for file Music\test\foo.txt with ID 09e76dde-c4fa-4c50-8c25-d92a26b52102 +[19:19:35 INF] File upload of Music\test\foo.txt (09e76dde-c4fa-4c50-8c25-d92a26b52102) from agent example_agent complete ``` And the agent should show: -- cgit v1.2.3 From fb3f5000808666034bd0697d02462848ac137892 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 21 Mar 2023 16:16:44 -0500 Subject: update credential checks to use InstanceName --- src/slskd/Relay/API/Hubs/RelayHub.cs | 6 +++--- src/slskd/Relay/RelayService.cs | 8 ++++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/slskd/Relay/API/Hubs/RelayHub.cs b/src/slskd/Relay/API/Hubs/RelayHub.cs index 11410804..333bd529 100644 --- a/src/slskd/Relay/API/Hubs/RelayHub.cs +++ b/src/slskd/Relay/API/Hubs/RelayHub.cs @@ -140,8 +140,8 @@ namespace slskd.Relay { bool TryGetAgentConfig(string agent, out Options.RelayOptions.RelayAgentConfigurationOptions options) { - var agentOptions = OptionsMonitor.CurrentValue.Relay.Agents; - var found = agentOptions.Values.SingleOrDefault(a => a.InstanceName == agent); + var allAgents = OptionsMonitor.CurrentValue.Relay.Agents; + var found = allAgents.Values.SingleOrDefault(a => a.InstanceName == agent); if (found != default) { @@ -149,7 +149,7 @@ namespace slskd.Relay return true; } - Log.Warning("Unable to locate Agent config for '{Agent}' (configured Agents: {Agents})", agent, string.Join(", ", agentOptions.Values.Select(a => a.InstanceName))); + Log.Warning("Unable to locate Agent config for '{Agent}' (configured Agents: {Agents})", agent, string.Join(", ", allAgents.Values.Select(a => a.InstanceName))); options = null; return false; diff --git a/src/slskd/Relay/RelayService.cs b/src/slskd/Relay/RelayService.cs index c7056a0c..433a53ff 100644 --- a/src/slskd/Relay/RelayService.cs +++ b/src/slskd/Relay/RelayService.cs @@ -743,7 +743,9 @@ namespace slskd.Relay return false; } - if (!OptionsMonitor.CurrentValue.Relay.Agents.TryGetValue(agentName, out var agentOptions)) + var agentOptions = OptionsMonitor.CurrentValue.Relay.Agents.Values.SingleOrDefault(a => a.InstanceName == agentName); + + if (agentOptions == default) { Log.Debug("Auth challenge for {Id} failed: no configuration for agent '{Agent}'", connectionId, agentName); return false; @@ -860,7 +862,9 @@ namespace slskd.Relay { try { - if (!OptionsMonitor.CurrentValue.Relay.Agents.TryGetValue(agentName, out var agentOptions)) + var agentOptions = OptionsMonitor.CurrentValue.Relay.Agents.Values.SingleOrDefault(a => a.InstanceName == agentName); + + if (agentOptions == default) { Log.Debug("Validation failed: Agent {Agent} not configured", agentName); return false; -- cgit v1.2.3 From 23b61906072b9df7d0c72e48d133da62b7c52342 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 21 Mar 2023 16:54:00 -0500 Subject: debug log when validation fails --- src/slskd/Relay/RelayService.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/slskd/Relay/RelayService.cs b/src/slskd/Relay/RelayService.cs index 433a53ff..6cbbb0a2 100644 --- a/src/slskd/Relay/RelayService.cs +++ b/src/slskd/Relay/RelayService.cs @@ -753,9 +753,15 @@ namespace slskd.Relay var key = Pbkdf2.GetKey(password: agentOptions.Secret, salt: agentName, length: 48); var tokenBytes = System.Text.Encoding.UTF8.GetBytes((string)challengeToken); - var expectedResponse = Aes.Encrypt(tokenBytes, key).ToBase62(); + var expectedCredential = Aes.Encrypt(tokenBytes, key).ToBase62(); - return expectedResponse == credential; + if (expectedCredential != credential) + { + Log.Debug("Validation failed: Supplied credential {Credential} does not match expected credential {Expected}", credential, expectedCredential); + return false; + } + + return true; } /// -- cgit v1.2.3 From 097859a4b3d59b6131f82ba64ee9ee1c774a2f54 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 21 Mar 2023 17:04:38 -0500 Subject: remove roles from ApiKeyOnly policy --- src/slskd/Program.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index 5674aa2b..41c54626 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -625,7 +625,6 @@ namespace slskd options.AddPolicy(AuthPolicy.ApiKeyOnly, policy => { - policy.RequireRole(Role.ReadWrite.ToString(), Role.Administrator.ToString()); policy.AuthenticationSchemes.Add(ApiKeyAuthentication.AuthenticationScheme); policy.RequireAuthenticatedUser(); }); -- cgit v1.2.3 From d2f51073593bfb7d88d57fc46abf6bd3bd90a8a7 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 21 Mar 2023 17:13:37 -0500 Subject: add a Guest role, add AuthRole to avoid magic strings --- src/slskd/Common/Authentication/AuthRole.cs | 33 +++++++++++++++++++++++++++++ src/slskd/Common/Authentication/Role.cs | 3 ++- 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 src/slskd/Common/Authentication/AuthRole.cs diff --git a/src/slskd/Common/Authentication/AuthRole.cs b/src/slskd/Common/Authentication/AuthRole.cs new file mode 100644 index 00000000..0550c085 --- /dev/null +++ b/src/slskd/Common/Authentication/AuthRole.cs @@ -0,0 +1,33 @@ +// +// Copyright (c) slskd Team. All rights reserved. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published +// by the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see https://www.gnu.org/licenses/. +// + +namespace slskd +{ + /// + /// Authentication roles. + /// + /// + /// For use in the attribute, specifically. + /// + public static class AuthRole + { + public const string AdministratorOnly = "Administrator"; + public const string ReadWriteOrAdministrator = "ReadWrite,Administrator"; + public const string GuestOrAdministrator = "Guest,Administrator"; + public const string Any = "ReadOnly,ReadWrite,Guest,Administrator"; + } +} diff --git a/src/slskd/Common/Authentication/Role.cs b/src/slskd/Common/Authentication/Role.cs index 2f88283c..87ba3466 100644 --- a/src/slskd/Common/Authentication/Role.cs +++ b/src/slskd/Common/Authentication/Role.cs @@ -21,6 +21,7 @@ namespace slskd.Authentication { ReadOnly = 0, ReadWrite = 1, - Administrator = 2, + Guest = 2, + Administrator = 3, } } -- cgit v1.2.3 From 388e567bdf78eb7aade2db7187e1e806d172d932 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 21 Mar 2023 17:14:43 -0500 Subject: remove required roles from policies --- src/slskd/Core/API/Controllers/ApplicationController.cs | 4 ++-- src/slskd/Core/API/Controllers/OptionsController.cs | 8 ++++---- src/slskd/Program.cs | 1 - src/slskd/Relay/API/Controllers/RelayController.cs | 10 +++++----- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/slskd/Core/API/Controllers/ApplicationController.cs b/src/slskd/Core/API/Controllers/ApplicationController.cs index c09b5513..0fd542db 100644 --- a/src/slskd/Core/API/Controllers/ApplicationController.cs +++ b/src/slskd/Core/API/Controllers/ApplicationController.cs @@ -69,7 +69,7 @@ namespace slskd.Core.API /// /// [HttpDelete] - [Authorize(Policy = AuthPolicy.JwtOnly)] + [Authorize(Policy = AuthPolicy.JwtOnly, Roles = AuthRole.AdministratorOnly)] public IActionResult Shutdown() { Program.MasterCancellationTokenSource.Cancel(); @@ -89,7 +89,7 @@ namespace slskd.Core.API /// /// [HttpPut] - [Authorize(Policy = AuthPolicy.JwtOnly)] + [Authorize(Policy = AuthPolicy.JwtOnly, Roles = AuthRole.AdministratorOnly)] public IActionResult Restart() { Program.MasterCancellationTokenSource.Cancel(); diff --git a/src/slskd/Core/API/Controllers/OptionsController.cs b/src/slskd/Core/API/Controllers/OptionsController.cs index 961571a0..da8fb5f0 100644 --- a/src/slskd/Core/API/Controllers/OptionsController.cs +++ b/src/slskd/Core/API/Controllers/OptionsController.cs @@ -82,7 +82,7 @@ namespace slskd.Core.API /// [HttpGet] [Route("debug")] - [Authorize(Policy = AuthPolicy.JwtOnly)] + [Authorize(Policy = AuthPolicy.JwtOnly, Roles = AuthRole.AdministratorOnly)] [ProducesResponseType(typeof(string), 200)] public IActionResult Debug() { @@ -100,7 +100,7 @@ namespace slskd.Core.API } [HttpGet] - [Authorize(Policy = AuthPolicy.JwtOnly)] + [Authorize(Policy = AuthPolicy.JwtOnly, Roles = AuthRole.AdministratorOnly)] [Route("yaml/location")] public IActionResult GetYamlFileLocation() { @@ -113,7 +113,7 @@ namespace slskd.Core.API } [HttpGet] - [Authorize(Policy = AuthPolicy.JwtOnly)] + [Authorize(Policy = AuthPolicy.JwtOnly, Roles = AuthRole.AdministratorOnly)] [Route("yaml")] public IActionResult GetYamlFile() { @@ -127,7 +127,7 @@ namespace slskd.Core.API } [HttpPost] - [Authorize(Policy = AuthPolicy.JwtOnly)] + [Authorize(Policy = AuthPolicy.JwtOnly, Roles = AuthRole.AdministratorOnly)] [Route("yaml")] public IActionResult UpdateYamlFile([FromBody] string yaml) { diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index 41c54626..1236865f 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -618,7 +618,6 @@ namespace slskd { options.AddPolicy(AuthPolicy.JwtOnly, policy => { - policy.RequireRole(Role.Administrator.ToString()); policy.AuthenticationSchemes.Add(JwtBearerDefaults.AuthenticationScheme); policy.RequireAuthenticatedUser(); }); diff --git a/src/slskd/Relay/API/Controllers/RelayController.cs b/src/slskd/Relay/API/Controllers/RelayController.cs index 586cbbb2..49c76e2d 100644 --- a/src/slskd/Relay/API/Controllers/RelayController.cs +++ b/src/slskd/Relay/API/Controllers/RelayController.cs @@ -68,7 +68,7 @@ namespace slskd.Relay /// /// [HttpPut("agent")] - [Authorize(Policy = AuthPolicy.JwtOnly)] + [Authorize(Policy = AuthPolicy.JwtOnly, Roles = AuthRole.AdministratorOnly)] public async Task Connect() { if (!OptionsAtStartup.Relay.Enabled || !new[] { RelayMode.Agent, RelayMode.Debug }.Contains(OperationMode)) @@ -85,7 +85,7 @@ namespace slskd.Relay /// /// [HttpDelete("agent")] - [Authorize(Policy = AuthPolicy.JwtOnly)] + [Authorize(Policy = AuthPolicy.JwtOnly, Roles = AuthRole.AdministratorOnly)] public async Task Disconnect() { if (!OptionsAtStartup.Relay.Enabled || !new[] { RelayMode.Agent, RelayMode.Debug }.Contains(OperationMode)) @@ -103,7 +103,7 @@ namespace slskd.Relay /// The unique identifier for the request. /// [HttpGet("controller/downloads/{token}")] - [Authorize(Policy = AuthPolicy.ApiKeyOnly)] + [Authorize(Policy = AuthPolicy.ApiKeyOnly, Roles = AuthRole.Any)] public IActionResult DownloadFile([FromRoute]string token) { if (!OptionsAtStartup.Relay.Enabled || !new[] { RelayMode.Controller, RelayMode.Debug }.Contains(OperationMode)) @@ -157,7 +157,7 @@ namespace slskd.Relay [RequestSizeLimit(10L * 1024L * 1024L * 1024L)] [RequestFormLimits(MultipartBodyLengthLimit = 10L * 1024L * 1024L * 1024L)] [DisableFormValueModelBinding] - [Authorize(Policy = AuthPolicy.ApiKeyOnly)] + [Authorize(Policy = AuthPolicy.ApiKeyOnly, Roles = AuthRole.ReadWriteOrAdministrator)] public async Task UploadFile(string token) { if (!OptionsAtStartup.Relay.Enabled || !new[] { RelayMode.Controller, RelayMode.Debug }.Contains(OperationMode)) @@ -252,7 +252,7 @@ namespace slskd.Relay /// The unique identifier for the request. /// [HttpPost("controller/shares/{token}")] - [Authorize(Policy = AuthPolicy.ApiKeyOnly)] + [Authorize(Policy = AuthPolicy.ApiKeyOnly, Roles = AuthRole.ReadWriteOrAdministrator)] public async Task UploadShares(string token) { if (!OptionsAtStartup.Relay.Enabled || !new[] { RelayMode.Controller, RelayMode.Debug }.Contains(OperationMode)) -- cgit v1.2.3