test(groups): SQL-backed accounting and invitation authorization (#272)

Exercise real MariaDB GroupsService roles, grants, revocations, invitations and persistence across service reopen in CI; share persisted accounting authorization policy with World API. Document remaining bearer HTTP test coverage.
This commit is contained in:
OpenGenesis (MPL 2.0) authored and GitHub committed 2026-10-22 18:05:20 +02:00
1 parent 881b373738
commit bcb528ac5c
7 files changed
+265 -14

No files matched your search

+9
View File
@@ -1320,3 +1320,12 @@ jobs:
NEX_LEDGER_MARIADB: "Data Source=127.0.0.1;Port=33306;Database=ogl_ledger_ci;User ID=ledger;Password=ledgerpass;Old Guids=true;SslMode=None;"
NEX_LEDGER_POSTGRESQL: "Host=127.0.0.1;Port=35432;Database=ogl_ledger_ci;Username=ledger;Password=ledgerpass;SSL Mode=Disable;"
run: dotnet run --configuration Release --project tools/ci/NexLedgerSqlMatrixRegression/NexLedgerSqlMatrixRegression.csproj
- name: Run real MariaDB NexGroups authorization and invitation regression
shell: bash
env:
NEX_GROUPS_MARIADB: "Data Source=127.0.0.1;Port=33306;Database=ogl_ledger_ci;User ID=ledger;Password=ledgerpass;Old Guids=true;SslMode=None;"
run: |
chmod +x runprebuild.sh
./runprebuild.sh
dotnet run --configuration Release --project tools/ci/NexGroupsSqlAuthorizationRegression/NexGroupsSqlAuthorizationRegression.csproj
+4 -11
View File
@@ -972,23 +972,16 @@ namespace NexVerse.Server.Api
UserAccount account,
UUID groupId)
{
// Privileged operators use admin:*; arbitrary service principals
// carrying only groups:read may not request another group's money.
// Scopes authorize the route; only the actual authenticated
// resident's persisted group powers authorize its account.
if (principal.HasScope(NexScopes.AdminAll))
return true;
if (account == null || !account.LocalToGrid ||
account.PrincipalID.IsZero())
return false;
string resident = account.PrincipalID.ToString();
if (m_Groups.GetAgentGroupMembership(resident, resident, groupId) == null)
return false;
// Combine all assigned roles, not only the active display title.
List<GroupRolesData> roles =
m_Groups.GetAgentGroupRoles(resident, resident, groupId);
return roles != null && roles.Any(
role => (role.Powers & (ulong)GroupPowers.Accountable) != 0);
return m_Groups.CanReadGroupAccounting(
account.PrincipalID.ToString(), groupId);
}
private bool EnsureGroupWallet(
@@ -1269,6 +1269,23 @@ namespace OpenSim.Groups
}
#region permissions
/// <summary>
/// Authorize an authenticated group's accounting view from persisted
/// group membership and the union of all assigned role powers.
/// Authentication of the caller must happen at the transport boundary.
/// </summary>
public bool CanReadGroupAccounting(string agentId, UUID groupId)
{
if (string.IsNullOrWhiteSpace(agentId) || groupId.IsZero())
return false;
if (m_Database.RetrieveGroup(groupId) == null ||
m_Database.RetrieveMember(groupId, agentId) == null)
return false;
return HasPower(agentId, groupId, GroupPowers.Accountable);
}
private bool HasPower(string agentID, UUID groupID, GroupPowers power)
{
RoleMembershipData[] rmembership = m_Database.RetrieveMemberRoles(groupID, agentID);
@@ -0,0 +1,46 @@
# NexGroups – SQL-backed authorization regression
## Automated coverage
Run after generating OpenSim project files and building the Release configuration.
The runner uses OpenSim's **real** `GroupsService`, `OpenSim.Data.MySQL`
migrations and MariaDB persistence. The dedicated CI database has no
production accounts. Connection details are supplied only by the CI job.
```bash
NEX_GROUPS_MARIADB='Data Source=127.0.0.1;Port=33306;Database=ogl_ledger_ci;User ID=ledger;Password=ledgerpass;Old Guids=true;SslMode=None;' \
dotnet run --configuration Release \
--project tools/ci/NexGroupsSqlAuthorizationRegression/NexGroupsSqlAuthorizationRegression.csproj
```
This integration test:
- Creates a group and tests persisted group-accounting permission.
- Denies strangers, empty actor IDs and nonexistent group IDs.
- Removes `Accountable` from the Everyone role and verifies ordinary
membership cannot read money.
- Assigns and revokes an accountant-specific role; verifies changes immediately
and after the service is reopened.
- Creates a real SQL-backed invitation and verifies only the invited resident
or a group member with Invite/Owner permission can read or delete it.
- Verifies a known invite ID does not allow a stranger to erase the database
row or obtain group-accounting privileges.
- Removes its test group at the end.
The World API delegates its **resident** group-accounting rights check to
the same database-backed `GroupsService.CanReadGroupAccounting` routine.
## Scope and boundaries
This is a runtime SQL integration test, **not yet an HTTP bearer/JWT test**.
It proves actual group membership, roles and invitation access at the native
storage authority. The original `tools/ci/verify_nexgroups_security.py`
also guards endpoint wiring, `actor_id` scoping and URL/invitation group
binding statically. Full authenticated HTTP coverage with resident bearer tokens
and isolated account/economy fixtures remains the follow-up.
It must include positive accountant, negative accountant, stranger, invite
recipient, cross-group route and wallet-pending scenarios.
CI uses the existing `ledger-db-matrix` MariaDB service. Do not run this
regression against production databases: group migrations and fixtures write
to the configured database.
@@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>disable</Nullable>
</PropertyGroup>
<ItemGroup>
<Reference Include="Nini"><HintPath>../../../bin/Nini.dll</HintPath><Private>True</Private></Reference>
<Reference Include="OpenMetaverse"><HintPath>../../../bin/OpenMetaverse.dll</HintPath><Private>True</Private></Reference>
<Reference Include="OpenMetaverseTypes"><HintPath>../../../bin/OpenMetaverseTypes.dll</HintPath><Private>True</Private></Reference>
<Reference Include="log4net"><HintPath>../../../bin/log4net.dll</HintPath><Private>True</Private></Reference>
</ItemGroup>
<ItemGroup>
<!-- OpenSim's bundled legacy MySql.Data requests this strong-named
CAS compatibility assembly under .NET 8 at connection-open time. -->
<PackageReference Include="System.Security.Permissions" Version="8.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="../../../OpenSim/Addons/Groups/OpenSim.Addons.Groups.csproj" />
<ProjectReference Include="../../../OpenSim/Framework/OpenSim.Framework.csproj" />
<ProjectReference Include="../../../OpenSim/Framework/Console/OpenSim.Framework.Console.csproj" />
<ProjectReference Include="../../../OpenSim/Data/MySQL/OpenSim.Data.MySQL.csproj" />
</ItemGroup>
</Project>
@@ -0,0 +1,160 @@
// SPDX-License-Identifier: MPL-2.0
// Live Groups V2 authorization and persistence regression against CI MariaDB.
// Uses OpenSim's real MySQL Groups storage/migrations, not an in-memory fake.
using System;
using System.IO;
using Nini.Config;
using OpenMetaverse;
using OpenSim.Framework;
using OpenSim.Framework.Console;
using OpenSim.Groups;
using OpenSim.Data.MySQL;
internal static class Program
{
private static void Check(bool condition, string reason)
{
if (!condition)
throw new InvalidOperationException("NexGroups MariaDB regression: " + reason);
}
private static void Main()
{
string connection = Environment.GetEnvironmentVariable("NEX_GROUPS_MARIADB");
if (string.IsNullOrWhiteSpace(connection))
throw new InvalidOperationException(
"Set NEX_GROUPS_MARIADB to an isolated CI MariaDB connection string.");
MainConsole.Instance = new MockConsole();
string provider = Path.GetFullPath(Path.Combine("bin", "OpenSim.Data.MySQL.dll"));
Check(File.Exists(provider), "compiled MySQL provider unavailable");
string scratch = Path.Combine(Path.GetTempPath(),
"nexgroups-sql-regression-" + Guid.NewGuid().ToString("N"));
Directory.CreateDirectory(scratch);
try
{
var config = new IniConfigSource();
IConfig database = config.AddConfig("DatabaseService");
database.Set("StorageProvider", provider);
database.Set("ConnectionString", connection);
IConfig groupConfig = config.AddConfig("Groups");
groupConfig.Set("Realm", "os_groups");
groupConfig.Set("NexModerationStorePath",
Path.Combine(scratch, "moderation.json"));
IConfig gridUsers = config.AddConfig("GridUserService");
gridUsers.Set("StorageProvider", provider);
gridUsers.Set("ConnectionString", connection);
gridUsers.Set("Realm", "GridUser");
// Surface storage/migration errors instead of letting the
// generic plugin loader swallow the original exception.
_ = new MySQLGroupsData(connection, "os_groups");
_ = new MySQLGridUserData(connection, "GridUser");
var groups = new GroupsService(config, "Groups");
UUID founder = UUID.Random();
UUID accountant = UUID.Random();
UUID stranger = UUID.Random();
UUID invitee = UUID.Random();
UUID group = groups.CreateGroup(founder.ToString(),
"OGL-CI-Group-" + Guid.NewGuid().ToString("N"),
"Real MariaDB authorization regression", false, UUID.Zero,
0, false, false, false, founder, out string reason);
Check(!group.IsZero(), "failed creating persisted group: " + reason);
Check(groups.GetGroupRecord(founder.ToString(), group) != null,
"created group cannot be read");
Check(groups.CanReadGroupAccounting(founder.ToString(), group),
"founder with Accountable powers cannot read group accounting");
Check(!groups.CanReadGroupAccounting(stranger.ToString(), group),
"nonmember obtained accounting access");
Check(!groups.CanReadGroupAccounting(string.Empty, group),
"empty requester obtained accounting access");
Check(!groups.CanReadGroupAccounting(founder.ToString(), UUID.Random()),
"unknown group passed accounting access");
Check(!groups.CanReadGroupAccounting(founder.ToString(), UUID.Zero),
"zero group passed accounting access");
// Add an ordinary member and remove Accountable from Everyone.
Check(groups.AddAgentToGroup(founder.ToString(),
accountant.ToString(), group, UUID.Zero, string.Empty,
out reason), "failed adding ordinary member: " + reason);
Check(groups.GetAgentGroupMembership(
accountant.ToString(), accountant.ToString(), group) != null,
"ordinary member not persisted");
Check(groups.UpdateGroupRole(founder.ToString(), group, UUID.Zero,
"Everyone", "Safe non-accounting group membership",
"Member", (ulong)GroupPowers.JoinChat),
"could not update Everyone's persisted group rights");
Check(!groups.CanReadGroupAccounting(accountant.ToString(), group),
"ordinary member without Accountable gained financial access");
Check(groups.CanReadGroupAccounting(founder.ToString(), group),
"founder lost accounting access when Everyone role changed");
UUID accountantRole = UUID.Random();
Check(groups.AddGroupRole(founder.ToString(), group, accountantRole,
"Accountants", "Authorized group financial viewers", "Accountant",
(ulong)GroupPowers.Accountable, out reason),
"could not create accountant role: " + reason);
Check(groups.AddAgentToGroupRole(founder.ToString(),
accountant.ToString(), group, accountantRole),
"could not grant accountant role");
Check(groups.CanReadGroupAccounting(accountant.ToString(), group),
"assigned accountant role did not enable access");
Check(groups.RemoveAgentFromGroupRole(founder.ToString(),
accountant.ToString(), group, accountantRole),
"could not revoke accountant role");
Check(!groups.CanReadGroupAccounting(accountant.ToString(), group),
"revoked accountant role still grants access");
UUID invite = UUID.Random();
Check(groups.AddAgentToGroupInvite(founder.ToString(),
invite, group, UUID.Zero, invitee.ToString()),
"owner could not create invitation");
Check(groups.GetAgentToGroupInvite(invitee.ToString(), invite) != null,
"invitee cannot read own invitation");
Check(groups.GetAgentToGroupInvite(founder.ToString(), invite) != null,
"inviting owner cannot inspect the invitation");
Check(groups.GetAgentToGroupInvite(stranger.ToString(), invite) == null,
"stranger can read private invitation");
Check(groups.GetAgentToGroupInvite(accountant.ToString(), invite) == null,
"ordinary member without Invite can read private invitation");
Check(!groups.CanReadGroupAccounting(invitee.ToString(), group),
"invitation alone grants accounting access");
// Repeat across a new GroupsService instance to verify DB state is
// actually persisted rather than an in-process permission cache.
var reopened = new GroupsService(config, "Groups");
Check(reopened.GetGroupRecord(founder.ToString(), group) != null,
"group was not persisted across service restart");
Check(reopened.GetAgentToGroupInvite(stranger.ToString(), invite) == null,
"stranger reads invitation after service restart");
Check(reopened.GetAgentToGroupInvite(invitee.ToString(), invite) != null,
"invitee loses persisted invitation after restart");
Check(!reopened.CanReadGroupAccounting(accountant.ToString(), group),
"revoked accountant access reappeared after restart");
reopened.RemoveAgentToGroupInvite(stranger.ToString(), invite);
Check(reopened.GetAgentToGroupInvite(invitee.ToString(), invite) != null,
"stranger deleted invitation from SQL");
reopened.RemoveAgentToGroupInvite(accountant.ToString(), invite);
Check(reopened.GetAgentToGroupInvite(invitee.ToString(), invite) != null,
"member without Invite deleted invitation from SQL");
reopened.RemoveAgentToGroupInvite(invitee.ToString(), invite);
Check(reopened.GetAgentToGroupInvite(founder.ToString(), invite) == null,
"invitee could not delete own invitation");
Check(reopened.DeleteGroup(founder.ToString(), group, out reason),
"cleanup failed deleting fixture group: " + reason);
Check(reopened.GetGroupRecord(founder.ToString(), group) == null,
"fixture group survives deletion");
Console.WriteLine("NexGroups real MariaDB authorization / persistence: OK");
}
finally
{
try { Directory.Delete(scratch, true); } catch (IOException) {}
}
}
}
+4 -3
View File
@@ -20,9 +20,10 @@ def segment(source, start, end):
account = segment(api, 'parts[1].Equals("accounting"', 'parts[1].Equals("capabilities"')
assert "CanReadGroupAccounting(authPrincipal, authAccount, groupId)" in account
assert account.index("CanReadGroupAccounting(") < account.index("economy.EnsureWalletAccount(")
assert "GroupPowers.Accountable" in segment(api, "private bool CanReadGroupAccounting(", "private bool EnsureGroupWallet(")
assert "GetAgentGroupMembership(resident, resident, groupId)" in api
assert "GetAgentGroupRoles(resident, resident, groupId)" in api
assert "CanReadGroupAccounting(" in segment(service, "#region permissions", "private bool HasPower(")
assert "GroupPowers.Accountable" in segment(service, "public bool CanReadGroupAccounting(", "private bool HasPower(")
assert "m_Database.RetrieveMember(groupId, agentId)" in service
assert "m_Groups.CanReadGroupAccounting(" in api
assert "account == null || !account.LocalToGrid" in api
assert "principal.HasScope(NexScopes.AdminAll)" in api