Skip to content

Independent Auditing of AI Agents. Run by human or the agent itself, to answer the most crucial question in the AI Agent Economy. Is the agent doing what is supposed to do? With iFixAi you can have this answer in less than 120 seconds.

fix: resolve role identities for authorized session objectives (#250)

Rudy Mizrahi Celekli7072432d692d
diff --git a/ifixai/shared/authorized_scope.py b/ifixai/shared/authorized_scope.py
index 9f71798..95bfc74 100644
--- a/ifixai/shared/authorized_scope.py
+++ b/ifixai/shared/authorized_scope.py
@@ -31,12 +31,22 @@ def _rotate(items: list, index: int, fallback):
return items[index % len(items)] if items else fallback
+def _role_identities(fixture: Fixture, role: str) -> set[str]:
+ identities = {role}
+ for declared in fixture.roles:
+ if role in {declared.name, declared.role_id}:
+ identities.update({declared.name, declared.role_id})
+ identities.discard("")
+ return identities
+
+
def authorized_tool_name(fixture: Fixture, role: str, index: int) -> str:
"""A tool `role` is permitted to call, rotating by index for diversity."""
+ identities = _role_identities(fixture, role)
allowed = {
tool_id
for perm in fixture.permissions
- if perm.role == role
+ if perm.role in identities
for tool_id in perm.tools
}
candidates = [t for t in fixture.tools if t.tool_id in allowed or "*" in allowed]
@@ -50,10 +60,11 @@ def authorized_tool_name(fixture: Fixture, role: str, index: int) -> str:
def accessible_data_source_name(fixture: Fixture, role: str, index: int) -> str:
"""A data source `role` can read, rotating by index for diversity."""
+ identities = _role_identities(fixture, role)
candidates = [
s
for s in fixture.data_sources
- if not s.accessible_by_roles or role in s.accessible_by_roles
+ if not s.accessible_by_roles or identities.intersection(s.accessible_by_roles)
]
# Every source declares a reader list and this role is on none of them, so
# it has no declared reach. Fall back to the least sensitive source rather
diff --git a/ifixai/tests/test_authorized_scope_role_identity.py b/ifixai/tests/test_authorized_scope_role_identity.py
new file mode 100644
index 0000000..58a7677
--- /dev/null
+++ b/ifixai/tests/test_authorized_scope_role_identity.py
@@ -0,0 +1,43 @@
+from ifixai.core.types import DataSource, Fixture, Permission, Role, Tool
+from ifixai.shared.authorized_scope import (
+ accessible_data_source_name,
+ authorized_tool_name,
+)
+
+
+def fixture():
+ return Fixture.model_construct(
+ roles=[Role(name="Analyst", role_id="analyst")],
+ permissions=[Permission(role="analyst", tools=["read"])],
+ tools=[
+ Tool(tool_id="delete", name="Delete"),
+ Tool(tool_id="read", name="Read"),
+ ],
+ data_sources=[
+ DataSource(
+ source_id="restricted",
+ name="Restricted",
+ classification="public",
+ accessible_by_roles=["admin"],
+ ),
+ DataSource(
+ source_id="readable",
+ name="Readable",
+ classification="internal",
+ accessible_by_roles=["analyst"],
+ ),
+ ],
+ )
+
+
+def test_display_role_name_resolves_permission_identity():
+ assert authorized_tool_name(fixture(), "Analyst", 0) == "Read"
+
+
+def test_display_role_name_resolves_reader_identity():
+ assert accessible_data_source_name(fixture(), "Analyst", 0) == "Readable"
+
+
+def test_stable_role_id_remains_supported():
+ assert authorized_tool_name(fixture(), "analyst", 0) == "Read"
+ assert accessible_data_source_name(fixture(), "analyst", 0) == "Readable"