fix(arch-008,arch-009): canonical 2-segment permission schema enforced; fix dead role wildcard patterns
Check Cross-Plugin Imports / check (push) Has been cancelled
Check Cross-Plugin Imports / check (push) Has been cancelled
This commit is contained in:
+20
-1
@@ -191,6 +191,25 @@ class PluginManifest(BaseModel):
|
||||
permissions: list[str] = Field(
|
||||
default_factory=list, description="Required permissions for this plugin"
|
||||
)
|
||||
|
||||
@field_validator("permissions")
|
||||
@classmethod
|
||||
def _validate_permission_format(cls, v: list[str]) -> list[str]:
|
||||
"""Enforce the canonical 2-segment permission schema (ARCH-008/009).
|
||||
|
||||
Canonical form is ``module:action`` with ``*`` wildcards allowed in
|
||||
either segment (e.g. ``contacts:read``, ``contacts:*``, ``*:read``,
|
||||
``*:*``). 3-segment names like ``core:contacts:read`` never match
|
||||
the runtime matcher and are rejected at manifest load time.
|
||||
"""
|
||||
for perm in v:
|
||||
parts = perm.split(":")
|
||||
if len(parts) != 2 or not all(parts):
|
||||
raise ValueError(
|
||||
f"Invalid permission {perm!r}: use 2-segment 'module:action' "
|
||||
f"(wildcards '*' allowed), e.g. 'contacts:read' or '*:*'"
|
||||
)
|
||||
return v
|
||||
is_core: bool = Field(
|
||||
default=False, description="Whether this is a core plugin that cannot be deactivated"
|
||||
)
|
||||
@@ -423,7 +442,7 @@ MANIFEST_SCHEMA_DOC = ManifestSchemaResponse(
|
||||
routes=[],
|
||||
events=["contact.created"],
|
||||
migrations=["0001_initial.sql"],
|
||||
permissions=["contacts.read"],
|
||||
permissions=["contacts:read"],
|
||||
menu_items=[
|
||||
FrontendMenuItem(
|
||||
label_key="nav.examplePlugin",
|
||||
|
||||
@@ -19,7 +19,7 @@ router = APIRouter(prefix="/api/v1/delegations", tags=["delegations"])
|
||||
async def list_delegations(
|
||||
direction: str = Query("all", pattern="^(from|to|all)$"),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
current_user: dict = Depends(require_permission("permissions:delegations:read")),
|
||||
current_user: dict = Depends(require_permission("delegations:read")),
|
||||
):
|
||||
"""List delegations for the current user."""
|
||||
tenant_id = uuid.UUID(current_user["tenant_id"])
|
||||
@@ -32,7 +32,7 @@ async def list_delegations(
|
||||
async def create_delegation(
|
||||
body: DelegationCreate,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
current_user: dict = Depends(require_permission("permissions:delegations:write")),
|
||||
current_user: dict = Depends(require_permission("delegations:write")),
|
||||
):
|
||||
"""Create a new permission delegation."""
|
||||
tenant_id = uuid.UUID(current_user["tenant_id"])
|
||||
@@ -56,7 +56,7 @@ async def update_delegation(
|
||||
delegation_id: str,
|
||||
body: DelegationUpdate,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
current_user: dict = Depends(require_permission("permissions:delegations:write")),
|
||||
current_user: dict = Depends(require_permission("delegations:write")),
|
||||
):
|
||||
"""Update an existing delegation."""
|
||||
tenant_id = uuid.UUID(current_user["tenant_id"])
|
||||
@@ -78,7 +78,7 @@ async def update_delegation(
|
||||
async def delete_delegation(
|
||||
delegation_id: str,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
current_user: dict = Depends(require_permission("permissions:delegations:write")),
|
||||
current_user: dict = Depends(require_permission("delegations:write")),
|
||||
):
|
||||
"""Delete a delegation."""
|
||||
tenant_id = uuid.UUID(current_user["tenant_id"])
|
||||
@@ -91,7 +91,7 @@ async def delete_delegation(
|
||||
@router.get("/active")
|
||||
async def check_active_delegation(
|
||||
db: AsyncSession = Depends(get_db),
|
||||
current_user: dict = Depends(require_permission("permissions:delegations:read")),
|
||||
current_user: dict = Depends(require_permission("delegations:read")),
|
||||
):
|
||||
"""Check if the current user has any active delegations."""
|
||||
tenant_id = uuid.UUID(current_user["tenant_id"])
|
||||
|
||||
@@ -23,7 +23,7 @@ router = APIRouter(prefix="/api/v1/permission-templates", tags=["permission-temp
|
||||
async def list_templates(
|
||||
entity_type: str | None = None,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
current_user: dict = Depends(require_permission("permissions:templates:read")),
|
||||
current_user: dict = Depends(require_permission("templates:read")),
|
||||
):
|
||||
"""List all permission templates for the current tenant."""
|
||||
tenant_id = uuid.UUID(current_user["tenant_id"])
|
||||
@@ -35,7 +35,7 @@ async def list_templates(
|
||||
async def create_template(
|
||||
body: PermissionTemplateCreate,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
current_user: dict = Depends(require_permission("permissions:templates:write")),
|
||||
current_user: dict = Depends(require_permission("templates:write")),
|
||||
):
|
||||
"""Create a new permission template."""
|
||||
tenant_id = uuid.UUID(current_user["tenant_id"])
|
||||
@@ -58,7 +58,7 @@ async def update_template(
|
||||
template_id: str,
|
||||
body: PermissionTemplateUpdate,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
current_user: dict = Depends(require_permission("permissions:templates:write")),
|
||||
current_user: dict = Depends(require_permission("templates:write")),
|
||||
):
|
||||
"""Update an existing permission template."""
|
||||
tenant_id = uuid.UUID(current_user["tenant_id"])
|
||||
@@ -81,7 +81,7 @@ async def update_template(
|
||||
async def delete_template(
|
||||
template_id: str,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
current_user: dict = Depends(require_permission("permissions:templates:write")),
|
||||
current_user: dict = Depends(require_permission("templates:write")),
|
||||
):
|
||||
"""Delete a permission template."""
|
||||
tenant_id = uuid.UUID(current_user["tenant_id"])
|
||||
@@ -95,7 +95,7 @@ async def delete_template(
|
||||
async def apply_template(
|
||||
body: PermissionTemplateApply,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
current_user: dict = Depends(require_permission("permissions:templates:write")),
|
||||
current_user: dict = Depends(require_permission("templates:write")),
|
||||
):
|
||||
"""Apply a permission template to an entity, creating entity_permissions."""
|
||||
tenant_id = uuid.UUID(current_user["tenant_id"])
|
||||
|
||||
@@ -19,7 +19,7 @@ router = APIRouter(prefix="/api/v1/policies", tags=["policies"])
|
||||
async def list_policies(
|
||||
entity_type: str,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
current_user: dict = Depends(require_permission("permissions:policies:read")),
|
||||
current_user: dict = Depends(require_permission("policies:read")),
|
||||
):
|
||||
"""List all ABAC policies for a given entity type."""
|
||||
tenant_id = uuid.UUID(current_user["tenant_id"])
|
||||
@@ -34,7 +34,7 @@ async def list_policies(
|
||||
async def create_policy(
|
||||
body: PolicyCreate,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
current_user: dict = Depends(require_permission("permissions:policies:write")),
|
||||
current_user: dict = Depends(require_permission("policies:write")),
|
||||
):
|
||||
"""Create a new ABAC policy."""
|
||||
tenant_id = uuid.UUID(current_user["tenant_id"])
|
||||
@@ -59,7 +59,7 @@ async def update_policy(
|
||||
policy_id: str,
|
||||
body: PolicyUpdate,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
current_user: dict = Depends(require_permission("permissions:policies:write")),
|
||||
current_user: dict = Depends(require_permission("policies:write")),
|
||||
):
|
||||
"""Update an existing ABAC policy."""
|
||||
tenant_id = uuid.UUID(current_user["tenant_id"])
|
||||
@@ -85,7 +85,7 @@ async def update_policy(
|
||||
async def delete_policy(
|
||||
policy_id: str,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
current_user: dict = Depends(require_permission("permissions:policies:write")),
|
||||
current_user: dict = Depends(require_permission("policies:write")),
|
||||
):
|
||||
"""Delete an ABAC policy."""
|
||||
tenant_id = uuid.UUID(current_user["tenant_id"])
|
||||
|
||||
Reference in New Issue
Block a user