Don't set InstancePermissionSet for instances not on the swarm node

This commit is contained in:
Cyberboss
2020-12-28 10:59:11 -05:00
parent f5fcf331d3
commit 83c7828e38
@@ -1,9 +1,11 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Tgstation.Server.Host.Configuration;
using Tgstation.Server.Host.Database;
using Tgstation.Server.Host.Models;
@@ -30,19 +32,27 @@ namespace Tgstation.Server.Host.Security
/// </summary>
readonly ILogger<AuthenticationContextFactory> logger;
/// <summary>
/// The <see cref="SwarmConfiguration"/> for the <see cref="AuthenticationContextFactory"/>.
/// </summary>
readonly SwarmConfiguration swarmConfiguration;
/// <summary>
/// Construct an <see cref="AuthenticationContextFactory"/>
/// </summary>
/// <param name="databaseContext">The value of <see cref="databaseContext"/></param>
/// <param name="identityCache">The value of <see cref="identityCache"/></param>
/// <param name="swarmConfigurationOptions">The <see cref="IOptions{TOptions}"/> containing the value of <see cref="swarmConfiguration"/>.</param>
/// <param name="logger">The value of <see cref="logger"/>.</param>
public AuthenticationContextFactory(
IDatabaseContext databaseContext,
IIdentityCache identityCache,
IOptions<SwarmConfiguration> swarmConfigurationOptions,
ILogger<AuthenticationContextFactory> logger)
{
this.databaseContext = databaseContext ?? throw new ArgumentNullException(nameof(databaseContext));
this.identityCache = identityCache ?? throw new ArgumentNullException(nameof(identityCache));
swarmConfiguration = swarmConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(swarmConfigurationOptions));
this.logger = logger ?? throw new ArgumentNullException(nameof(logger));
}
@@ -96,7 +106,7 @@ namespace Tgstation.Server.Host.Security
{
instancePermissionSet = await databaseContext.InstancePermissionSets
.AsQueryable()
.Where(x => x.PermissionSetId == userPermissionSet.Id && x.InstanceId == instanceId)
.Where(x => x.PermissionSetId == userPermissionSet.Id && x.InstanceId == instanceId && x.Instance.SwarmIdentifer == swarmConfiguration.Identifier)
.Include(x => x.Instance)
.FirstOrDefaultAsync(cancellationToken)
.ConfigureAwait(false);
@@ -105,7 +115,10 @@ namespace Tgstation.Server.Host.Security
logger.LogDebug("User {0} does not have permissions on instance {1}!", userId, instanceId.Value);
}
CurrentAuthenticationContext = new AuthenticationContext(systemIdentity, user, instancePermissionSet);
CurrentAuthenticationContext = new AuthenticationContext(
systemIdentity,
user,
instancePermissionSet);
}
catch
{