Skip to content

Bugfix on ACLs #1242

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion core/schemas/dfiq.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from core import database_arango
from core.helpers import now
from core.schemas import audit, indicator
from core.schemas import audit, indicator, rbac
from core.schemas.model import YetiAclModel, YetiModel

LATEST_SUPPORTED_DFIQ_VERSION = "1.1.0"
Expand Down Expand Up @@ -88,6 +88,7 @@ def read_from_data_directory(
if not dfiq_object.uuid:
dfiq_object.uuid = str(uuid.uuid4())
dfiq_object = dfiq_object.save()
rbac.set_acls(dfiq_object)
dfiq_addition.dfiq.append(dfiq_object)
audit.log_timeline(user, dfiq_object, old=db_dfiq)
total_added += 1
Expand Down
7 changes: 4 additions & 3 deletions core/schemas/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,19 @@ def __init__(self, **data):
def acls(self):
return self._acls

def get_acls(self) -> None:
def get_acls(self, direct=False) -> None:
"""Returns the permissions assigned to a user.
Args:
user: The user to check permissions for.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like Args documentation are no longer relevant

"""
vertices, paths, total = self.neighbors(
graph="acls", direction="inbound", max_hops=2
graph="acls", direction="inbound", max_hops=1 if direct else 2
)
for path in paths:
source = path[-1].source # inbound, so source is last.
for edge in path:
if edge.target == self.extended_id:
identity = vertices[edge.source]
identity = vertices[source]
if identity.root_type == "rbacgroup":
self._acls[identity.name] = edge
if identity.root_type == "user":
Expand Down
3 changes: 2 additions & 1 deletion core/web/apiv2/rbac.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ def get_acl_details(httpreq: Request, type: str, id: str):
if not db_entity:
raise HTTPException(status_code=404, detail=f"{type} {id} not found")

return db_entity.acl
db_entity.get_acls(direct=True)
return db_entity


@router.post("/{type}/{id}/update-members")
Expand Down
21 changes: 15 additions & 6 deletions tests/schemas/rbac.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ def setUp(self) -> None:
database_arango.RBAC_ENABLED = True

self.yeti_user = user.User(username="yeti", admin=True).save()
self.user1 = user.User(username="test1").save()
self.user2 = user.User(username="test2").save()
self.group1 = rbac.Group(name="test1").save()
self.group2 = rbac.Group(name="test2").save()
self.entity1 = entity.Malware(name="test1").save()
self.entity2 = entity.Malware(name="test2").save()
self.user1 = user.User(username="user1").save()
self.user2 = user.User(username="user2").save()
self.group1 = rbac.Group(name="group1").save()
self.group2 = rbac.Group(name="group2").save()
self.entity1 = entity.Malware(name="malware1").save()
self.entity2 = entity.Malware(name="malware2").save()
self.observable1 = observable.Hostname(value="test.com").save()
self.observable1.link_to(self.entity1, "test", description="test")

Expand Down Expand Up @@ -115,3 +115,12 @@ def test_neighbors_filter_when_passing_username(self):
vertices, edges, total = self.observable1.neighbors(user=self.user1)
self.assertEqual(total, 1)
self.assertEqual(len(vertices), 1)

def test_get_acls(self):
"""Test that get_acls() returns the correct ACLs"""
self.user1.link_to_acl(self.group1, roles.Role.OWNER)
self.group1.link_to_acl(self.entity1, roles.Role.OWNER)
self.entity1.get_acls()
self.assertEqual(len(self.entity1._acls), 2)
self.assertIn(self.group1.name, self.entity1._acls)
self.assertIn(self.user1.username, self.entity1._acls)
Loading