Skip to content

armgit / AiSOC

Public Imported from GitHub
0

Open-source AI Security Operations Center: alert fusion, LLM-agent triage, MITRE ATT&CK investigation, and a replayable decision ledger for every agent step. Self-hostable, runs with no API keys, MIT licensed. Ships an MCP server for Claude, Cursor and Continue.

fix(8.1): the MFA policy route asks for the role vocabulary, not the map

Beenu Arora7389c61287f1
diff --git a/services/api/app/api/v1/endpoints/mfa.py b/services/api/app/api/v1/endpoints/mfa.py
index e327d8059..7e9267b17 100644
--- a/services/api/app/api/v1/endpoints/mfa.py
+++ b/services/api/app/api/v1/endpoints/mfa.py
@@ -69,7 +69,8 @@ from sqlalchemy import text
from app.api.v1.deps import AuthUser, DBSession, bearer_scheme, get_current_user, require_permission
from app.core.config import settings
-from app.core.security import ROLE_PERMISSIONS, create_access_token, create_refresh_token
+from app.core.role_grants import known_roles
+from app.core.security import create_access_token, create_refresh_token
from app.db.rls import set_rls_context
from app.security.credential_vault import CredentialVaultError, get_vault
from app.services import mfa as totp
@@ -861,13 +862,19 @@ async def put_policy(
this endpoint has no row and is not enforced.
`require_for_roles` names roles that must hold a factor even when the
- tenant-wide switch is off. Every name is checked against
- `ROLE_PERMISSIONS` before it is stored: a typo would otherwise be
- accepted, match nobody's role, and leave an administrator looking at
- a policy page that says a role is enforced while it is not — the
- quiet direction, and the one worth refusing loudly.
+ tenant-wide switch is off. Every name is checked against the role
+ vocabulary before it is stored: a typo would otherwise be accepted,
+ match nobody's role, and leave an administrator looking at a policy
+ page that says a role is enforced while it is not — the quiet
+ direction, and the one worth refusing loudly.
+
+ The vocabulary comes from `role_grants.known_roles()` rather than from
+ `ROLE_PERMISSIONS` directly. This route decides nothing about
+ permissions and must not be able to: a route that reads the static map
+ is how a second permission model gets rebuilt, which
+ `scripts/check_one_permission_model.py` exists to prevent.
"""
- unknown = sorted(set(body.require_for_roles) - set(ROLE_PERMISSIONS))
+ unknown = sorted(set(body.require_for_roles) - known_roles())
if unknown:
raise HTTPException(
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
diff --git a/services/api/app/core/role_grants.py b/services/api/app/core/role_grants.py
index 9c8a1e1f1..81bfc0bdb 100644
--- a/services/api/app/core/role_grants.py
+++ b/services/api/app/core/role_grants.py
@@ -106,6 +106,20 @@ class RoleGrantDenied(Exception):
self.unknown = unknown
+def known_roles() -> frozenset[str]:
+ """Every role name the product recognises.
+
+ The *vocabulary*, not a permission decision. A caller that needs to
+ reject a role nobody holds -- an MFA policy naming `infosce` would be
+ stored, match no user, and leave an administrator reading a page that
+ says a role is enforced while it is not -- asks here rather than
+ importing `ROLE_PERMISSIONS` and growing a second opinion about what a
+ role is. `check_one_permission_model.py` enforces that, and this module
+ is one of the four it names as the map's legitimate readers.
+ """
+ return frozenset(ROLE_PERMISSIONS)
+
+
def wildcard_roles() -> frozenset[str]:
"""Roles whose declared permission list is the wildcard."""
return frozenset(role for role, perms in ROLE_PERMISSIONS.items() if WILDCARD in perms)