Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ServiceControl.Infrastructure/Auth/Permissions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public static class Permissions
/// <inheritdoc cref="ErrorThroughputView"/>
public const string ErrorThroughputManage = "error:throughput:manage";

/// <summary>Platform connections area — viewing and managing broker/platform connection settings.</summary>
/// <summary>Platform connections area — viewing and managing platform connection settings.</summary>
public const string ErrorConnectionsView = "error:connections:view";
/// <inheritdoc cref="ErrorConnectionsView"/>
public const string ErrorConnectionsManage = "error:connections:manage";
Expand Down
28 changes: 19 additions & 9 deletions src/ServiceControl.Infrastructure/Auth/RolePermissions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,17 @@ public static class RolePermissions
static readonly Dictionary<string, string[]> RolePatterns = new(StringComparer.OrdinalIgnoreCase)
{
[Reader] = ["*:*:view"],
[Writer] = ["*:*:*"],
[Writer] =
[
"*:*:*",
"-error:licensing:*",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a fan of denials. This means that when a user has both Writer+Admin roles that they now cannot access most configuration related views as denials must always be prioritized over allows.

"-error:notifications:*",
"-error:redirects:*",
"-error:throughput:*",
],
[Admin] =
[
"*:*:view",
"error:licensing:*",
"error:notifications:*",
"error:redirects:*",
"error:throughput:*",
"error:connections:*",
"*:*:*",
],
};

Expand Down Expand Up @@ -106,15 +108,23 @@ static FrozenDictionary<string, FrozenSet<string>> Expand()

foreach (var (role, patterns) in RolePatterns)
{
var includePatterns = patterns.Where(pattern => pattern[0] != '-');
var excludePatterns = patterns.Where(pattern => pattern[0] == '-').Select(pattern => pattern[1..]);

expanded[role] = Permissions.All
.Where(permission => patterns.Any(pattern => Matches(pattern, permission)))
.Where(permission => includePatterns.Any(pattern => Matches(pattern, permission))
&& !excludePatterns.Any(pattern => Matches(pattern, permission)))
.ToFrozenSet(StringComparer.Ordinal);
}

return expanded.ToFrozenDictionary(StringComparer.OrdinalIgnoreCase);
}

/// <summary>Matches a colon-delimited permission against a pattern where <c>*</c> is a segment wildcard.</summary>
/// <summary>
/// Matches a colon-delimited permission against a pattern where <c>*</c> is a segment wildcard.
/// A leading <c>-</c> on the pattern (stripped by <see cref="Expand"/> before calling this method)
/// marks the pattern as an exclusion rather than a grant.
/// </summary>
static bool Matches(string pattern, string permission)
{
var patternSegments = pattern.Split(':');
Expand Down
Loading