Bug: enforce_permission decorator defined but never applied at any CLI or service call site — authorization entirely unenforced #3630

Open
opened 2026-04-05 20:58:07 +00:00 by freemo · 1 comment
Owner

Metadata

  • Branch: fix/permission-enforce-decorator-wiring
  • Commit Message: fix(security): wire enforce_permission decorator to all security-sensitive CLI commands and service methods
  • Milestone: (none — backlog)
  • Parent Epic: #362

Description

The enforce_permission decorator is fully implemented in
src/cleveragents/application/services/permission_service.py (line 320) and
exported from src/cleveragents/application/services/__init__.py, but a
codebase-wide search reveals it is never actually applied at any CLI
command or service method call site.

The permission_service.py docstring explicitly acknowledges this gap:

"Actual wiring of the decorator into CLI and service call sites is deferred
to a future integration pass."

This means the entire permission system is a dead letter — no operation is
actually gated by permissions. In server mode (CLEVERAGENTS_SERVER_MODE=1),
any authenticated user can perform any operation regardless of their role
binding.

What Was Tested

  • Searched all Python files under src/cleveragents/ for @enforce_permission
    decorator usage
  • Searched for enforce_permission in the CLI commands directory
    (src/cleveragents/cli/commands/)
  • Searched for enforce_permission in the application services directory
    (src/cleveragents/application/services/)

Expected Behaviour (from spec)

The spec defines a permission system with PermissionAction, PermissionScope,
and PermissionRole. The enforce_permission decorator is documented as the
mechanism to "apply at CLI/service boundaries." In server mode, unauthorised
users must be denied access to protected operations.

Actual Behaviour

Zero usages of @enforce_permission found anywhere in the codebase outside of
the definition file itself. The entire permission system is bypassed at runtime.

Impact

In server mode (CLEVERAGENTS_SERVER_MODE=1), all operations bypass permission
checks entirely because the decorator is never invoked. Any authenticated user
can perform any operation regardless of their role binding.

Steps to Reproduce

  1. Set CLEVERAGENTS_SERVER_MODE=1
  2. Run any agents CLI command (e.g., agents project delete)
  3. Observe: no permission check is performed; the operation succeeds regardless
    of role bindings

Code Locations

Location Note
src/cleveragents/application/services/permission_service.py line 320 Decorator defined here; docstring at line 3 acknowledges the gap
src/cleveragents/cli/commands/ No @enforce_permission usage found
src/cleveragents/application/services/ No @enforce_permission usage found (except definition file)

Subtasks

  • Audit all CLI commands and service methods to identify every
    security-sensitive call site requiring permission enforcement
  • Apply @enforce_permission to plan apply CLI command and underlying
    service method
  • Apply @enforce_permission to plan execute CLI command and underlying
    service method
  • Apply @enforce_permission to project delete CLI command and underlying
    service method
  • Apply @enforce_permission to actor add / actor remove CLI commands
    and underlying service methods
  • Apply @enforce_permission to resource add / resource remove CLI
    commands and underlying service methods
  • Apply @enforce_permission to config set CLI command and underlying
    service method
  • Write Behave unit test scenarios verifying that unauthorised principals
    are denied in server mode for each decorated call site
  • Write Robot Framework integration tests verifying that authorised
    principals are permitted for each decorated call site
  • Update permission_service.py docstring to remove the "deferred to a
    future integration pass" acknowledgement

Definition of Done

  • All subtasks above are completed
  • @enforce_permission is applied to all security-sensitive CLI commands
    and service methods (at minimum: plan apply, plan execute,
    project delete, actor add/remove, resource add/remove, config set)
  • Unit tests (Behave) verify that unauthorised principals are denied in
    server mode for every decorated call site
  • Integration tests (Robot Framework) verify that authorised principals are
    permitted for every decorated call site
  • A commit is created with the exact message from Metadata
  • The commit is pushed to the branch specified in Metadata
  • A pull request is created, reviewed (≥ 2 approvals), and merged
  • All nox stages pass (nox -e lint, nox -e typecheck, nox -e unit_tests, nox -e integration_tests)
  • Coverage ≥ 97%

Backlog note: This issue was discovered during autonomous operation
on milestone UAT Testing. It does not block milestone completion and has been
placed in the backlog for human review and future milestone assignment.


Automated by CleverAgents Bot
Supervisor: UAT Testing | Agent: ca-uat-tester

## Metadata - **Branch**: `fix/permission-enforce-decorator-wiring` - **Commit Message**: `fix(security): wire enforce_permission decorator to all security-sensitive CLI commands and service methods` - **Milestone**: *(none — backlog)* - **Parent Epic**: #362 ## Description The `enforce_permission` decorator is fully implemented in `src/cleveragents/application/services/permission_service.py` (line 320) and exported from `src/cleveragents/application/services/__init__.py`, but a codebase-wide search reveals it is **never actually applied** at any CLI command or service method call site. The `permission_service.py` docstring explicitly acknowledges this gap: > *"Actual wiring of the decorator into CLI and service call sites is deferred > to a future integration pass."* This means the entire permission system is a dead letter — no operation is actually gated by permissions. In server mode (`CLEVERAGENTS_SERVER_MODE=1`), any authenticated user can perform any operation regardless of their role binding. ### What Was Tested - Searched all Python files under `src/cleveragents/` for `@enforce_permission` decorator usage - Searched for `enforce_permission` in the CLI commands directory (`src/cleveragents/cli/commands/`) - Searched for `enforce_permission` in the application services directory (`src/cleveragents/application/services/`) ### Expected Behaviour (from spec) The spec defines a permission system with `PermissionAction`, `PermissionScope`, and `PermissionRole`. The `enforce_permission` decorator is documented as the mechanism to "apply at CLI/service boundaries." In server mode, unauthorised users must be denied access to protected operations. ### Actual Behaviour Zero usages of `@enforce_permission` found anywhere in the codebase outside of the definition file itself. The entire permission system is bypassed at runtime. ### Impact In server mode (`CLEVERAGENTS_SERVER_MODE=1`), all operations bypass permission checks entirely because the decorator is never invoked. Any authenticated user can perform any operation regardless of their role binding. ### Steps to Reproduce 1. Set `CLEVERAGENTS_SERVER_MODE=1` 2. Run any `agents` CLI command (e.g., `agents project delete`) 3. Observe: no permission check is performed; the operation succeeds regardless of role bindings ### Code Locations | Location | Note | |---|---| | `src/cleveragents/application/services/permission_service.py` line 320 | Decorator defined here; docstring at line 3 acknowledges the gap | | `src/cleveragents/cli/commands/` | No `@enforce_permission` usage found | | `src/cleveragents/application/services/` | No `@enforce_permission` usage found (except definition file) | --- ## Subtasks - [ ] Audit all CLI commands and service methods to identify every security-sensitive call site requiring permission enforcement - [ ] Apply `@enforce_permission` to `plan apply` CLI command and underlying service method - [ ] Apply `@enforce_permission` to `plan execute` CLI command and underlying service method - [ ] Apply `@enforce_permission` to `project delete` CLI command and underlying service method - [ ] Apply `@enforce_permission` to `actor add` / `actor remove` CLI commands and underlying service methods - [ ] Apply `@enforce_permission` to `resource add` / `resource remove` CLI commands and underlying service methods - [ ] Apply `@enforce_permission` to `config set` CLI command and underlying service method - [ ] Write Behave unit test scenarios verifying that unauthorised principals are denied in server mode for each decorated call site - [ ] Write Robot Framework integration tests verifying that authorised principals are permitted for each decorated call site - [ ] Update `permission_service.py` docstring to remove the "deferred to a future integration pass" acknowledgement ## Definition of Done - [ ] All subtasks above are completed - [ ] `@enforce_permission` is applied to all security-sensitive CLI commands and service methods (at minimum: `plan apply`, `plan execute`, `project delete`, `actor add/remove`, `resource add/remove`, `config set`) - [ ] Unit tests (Behave) verify that unauthorised principals are denied in server mode for every decorated call site - [ ] Integration tests (Robot Framework) verify that authorised principals are permitted for every decorated call site - [ ] A commit is created with the exact message from Metadata - [ ] The commit is pushed to the branch specified in Metadata - [ ] A pull request is created, reviewed (≥ 2 approvals), and merged - [ ] All nox stages pass (`nox -e lint`, `nox -e typecheck`, `nox -e unit_tests`, `nox -e integration_tests`) - [ ] Coverage ≥ 97% --- > **Backlog note:** This issue was discovered during autonomous operation > on milestone UAT Testing. It does not block milestone completion and has been > placed in the backlog for human review and future milestone assignment. --- **Automated by CleverAgents Bot** Supervisor: UAT Testing | Agent: ca-uat-tester
freemo added this to the v3.8.0 milestone 2026-04-05 21:00:59 +00:00
Author
Owner

Issue triaged by project owner:

  • State: Verified
  • Priority: Critical — The enforce_permission decorator is defined but never applied anywhere. The entire permission system is bypassed at runtime. In server mode, any authenticated user can perform any operation.
  • Milestone: v3.8.0 (Server Implementation — this is a server-mode-only issue)
  • Story Points: 8 — XL — Requires auditing all CLI commands and service methods, applying the decorator to every security-sensitive call site, and writing comprehensive tests.
  • MoSCoW: Should Have — While Critical in severity, this only affects server mode (CLEVERAGENTS_SERVER_MODE=1). In local CLI mode, there's no multi-user scenario. This is essential for v3.8.0 (Server Implementation) but not blocking current milestones.

Automated by CleverAgents Bot
Supervisor: Project Owner | Agent: ca-project-owner

Issue triaged by project owner: - **State**: Verified - **Priority**: Critical — The `enforce_permission` decorator is defined but never applied anywhere. The entire permission system is bypassed at runtime. In server mode, any authenticated user can perform any operation. - **Milestone**: v3.8.0 (Server Implementation — this is a server-mode-only issue) - **Story Points**: 8 — XL — Requires auditing all CLI commands and service methods, applying the decorator to every security-sensitive call site, and writing comprehensive tests. - **MoSCoW**: Should Have — While Critical in severity, this only affects server mode (`CLEVERAGENTS_SERVER_MODE=1`). In local CLI mode, there's no multi-user scenario. This is essential for v3.8.0 (Server Implementation) but not blocking current milestones. --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: ca-project-owner
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Blocks
#362 Epic: Security & Safety Hardening
cleveragents/cleveragents-core
Reference
cleveragents/cleveragents-core#3630
No description provided.