PR Body Implements Spec 065 “Tenant RBAC v1” with capabilities-first RBAC, tenant membership scoping (Option 3), and consistent Filament action semantics. Key decisions / rules Tenancy Option 3: tenant switching is tenantless (ChooseTenant), tenant-scoped routes stay scoped, non-members get 404 (not 403). RBAC model: canonical capability registry + role→capability map + Gates for each capability (no role-string checks in UI logic). UX policy: for tenant members lacking permission → actions are visible but disabled + tooltip (avoid click→403). Security still enforced server-side. What’s included Capabilities foundation: Central capability registry (Capabilities::*) Role→capability mapping (RoleCapabilityMap) Gate registration + resolver/manager updates to support tenant-scoped authorization Filament enforcement hardening across the app: Tenant registration & tenant CRUD properly gated Backup/restore/policy flows aligned to “visible-but-disabled” where applicable Provider operations (health check / inventory sync / compliance snapshot) guarded and normalized Directory groups + inventory sync start surfaces normalized Policy version maintenance actions (archive/restore/prune/force delete) gated SpecKit artifacts for 065: spec.md, plan/tasks updates, checklists, enforcement hitlist Security guarantees Non-member → 404 via tenant scoping/membership guards. Member without capability → 403 on execution, even if UI is disabled. No destructive actions execute without proper authorization checks. Tests Adds/updates Pest coverage for: Tenant scoping & membership denial behavior Role matrix expectations (owner/manager/operator/readonly) Filament surface checks (visible/disabled actions, no side effects) Provider/Inventory/Groups run-start authorization Verified locally with targeted vendor/bin/sail artisan test --compact … Deployment / ops notes No new services required. Safe change: behavior is authorization + UI semantics; no breaking route changes intended. Co-authored-by: Ahmed Darrazi <ahmeddarrazi@MacBookPro.fritz.box> Reviewed-on: #79
123 lines
3.2 KiB
PHP
123 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Auth;
|
|
|
|
use App\Support\Auth\Capabilities;
|
|
use App\Support\TenantRole;
|
|
|
|
/**
|
|
* Role to Capability Mapping (Single Source of Truth)
|
|
*
|
|
* This class defines which capabilities each role has.
|
|
* All capability strings MUST be references from the Capabilities registry.
|
|
*/
|
|
class RoleCapabilityMap
|
|
{
|
|
private static array $roleCapabilities = [
|
|
TenantRole::Owner->value => [
|
|
Capabilities::TENANT_VIEW,
|
|
Capabilities::TENANT_MANAGE,
|
|
Capabilities::TENANT_DELETE,
|
|
Capabilities::TENANT_SYNC,
|
|
|
|
Capabilities::TENANT_MEMBERSHIP_VIEW,
|
|
Capabilities::TENANT_MEMBERSHIP_MANAGE,
|
|
|
|
Capabilities::TENANT_ROLE_MAPPING_VIEW,
|
|
Capabilities::TENANT_ROLE_MAPPING_MANAGE,
|
|
|
|
Capabilities::TENANT_BACKUP_SCHEDULES_MANAGE,
|
|
Capabilities::TENANT_BACKUP_SCHEDULES_RUN,
|
|
|
|
Capabilities::PROVIDER_VIEW,
|
|
Capabilities::PROVIDER_MANAGE,
|
|
Capabilities::PROVIDER_RUN,
|
|
|
|
Capabilities::AUDIT_VIEW,
|
|
],
|
|
|
|
TenantRole::Manager->value => [
|
|
Capabilities::TENANT_VIEW,
|
|
Capabilities::TENANT_MANAGE,
|
|
Capabilities::TENANT_SYNC,
|
|
|
|
Capabilities::TENANT_MEMBERSHIP_VIEW,
|
|
|
|
Capabilities::TENANT_ROLE_MAPPING_VIEW,
|
|
|
|
Capabilities::TENANT_BACKUP_SCHEDULES_MANAGE,
|
|
Capabilities::TENANT_BACKUP_SCHEDULES_RUN,
|
|
|
|
Capabilities::PROVIDER_VIEW,
|
|
Capabilities::PROVIDER_MANAGE,
|
|
Capabilities::PROVIDER_RUN,
|
|
|
|
Capabilities::AUDIT_VIEW,
|
|
],
|
|
|
|
TenantRole::Operator->value => [
|
|
Capabilities::TENANT_VIEW,
|
|
Capabilities::TENANT_SYNC,
|
|
|
|
Capabilities::TENANT_MEMBERSHIP_VIEW,
|
|
Capabilities::TENANT_ROLE_MAPPING_VIEW,
|
|
|
|
Capabilities::TENANT_BACKUP_SCHEDULES_RUN,
|
|
|
|
Capabilities::PROVIDER_VIEW,
|
|
Capabilities::PROVIDER_RUN,
|
|
|
|
Capabilities::AUDIT_VIEW,
|
|
],
|
|
|
|
TenantRole::Readonly->value => [
|
|
Capabilities::TENANT_VIEW,
|
|
|
|
Capabilities::TENANT_MEMBERSHIP_VIEW,
|
|
Capabilities::TENANT_ROLE_MAPPING_VIEW,
|
|
|
|
Capabilities::PROVIDER_VIEW,
|
|
|
|
Capabilities::AUDIT_VIEW,
|
|
],
|
|
];
|
|
|
|
/**
|
|
* Get all capabilities for a given role
|
|
*
|
|
* @return array<string>
|
|
*/
|
|
public static function getCapabilities(TenantRole|string $role): array
|
|
{
|
|
$roleValue = $role instanceof TenantRole ? $role->value : $role;
|
|
|
|
return self::$roleCapabilities[$roleValue] ?? [];
|
|
}
|
|
|
|
/**
|
|
* Get all role values that grant a given capability.
|
|
*
|
|
* @return array<string>
|
|
*/
|
|
public static function rolesWithCapability(string $capability): array
|
|
{
|
|
$roles = [];
|
|
|
|
foreach (self::$roleCapabilities as $role => $capabilities) {
|
|
if (in_array($capability, $capabilities, true)) {
|
|
$roles[] = $role;
|
|
}
|
|
}
|
|
|
|
return $roles;
|
|
}
|
|
|
|
/**
|
|
* Check if a role has a specific capability
|
|
*/
|
|
public static function hasCapability(TenantRole|string $role, string $capability): bool
|
|
{
|
|
return in_array($capability, self::getCapabilities($role), true);
|
|
}
|
|
}
|