forked from feast-dev/feast
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request feast-dev#26 from dmartinol/feast-rbac
Added filter_only flag to assert_permissions
- Loading branch information
Showing
9 changed files
with
254 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
from unittest.mock import Mock | ||
|
||
import pytest | ||
|
||
from feast import FeatureView | ||
from feast.permissions.decorator import require_permissions | ||
from feast.permissions.permission import AuthzedAction, Permission | ||
from feast.permissions.policy import RoleBasedPolicy | ||
from feast.permissions.role_manager import RoleManager | ||
from feast.permissions.security_manager import ( | ||
SecurityManager, | ||
set_security_manager, | ||
) | ||
|
||
|
||
class SecuredFeatureView(FeatureView): | ||
def __init__(self, name, tags): | ||
super().__init__( | ||
name=name, | ||
source=Mock(), | ||
tags=tags, | ||
) | ||
|
||
@require_permissions(actions=[AuthzedAction.READ]) | ||
def read_protected(self) -> bool: | ||
return True | ||
|
||
@require_permissions(actions=[AuthzedAction.WRITE]) | ||
def write_protected(self) -> bool: | ||
return True | ||
|
||
def unprotected(self) -> bool: | ||
return True | ||
|
||
|
||
@pytest.fixture | ||
def feature_views() -> list[FeatureView]: | ||
return [ | ||
SecuredFeatureView("secured", {}), | ||
SecuredFeatureView("special-secured", {}), | ||
] | ||
|
||
|
||
@pytest.fixture | ||
def role_manager() -> RoleManager: | ||
rm = RoleManager() | ||
rm.add_roles_for_user("r", ["reader"]) | ||
rm.add_roles_for_user("w", ["writer"]) | ||
rm.add_roles_for_user("rw", ["reader", "writer"]) | ||
return rm | ||
|
||
|
||
@pytest.fixture | ||
def security_manager() -> SecurityManager: | ||
permissions = [] | ||
permissions.append( | ||
Permission( | ||
name="reader", | ||
types=FeatureView, | ||
with_subclasses=True, | ||
policy=RoleBasedPolicy(roles=["reader"]), | ||
actions=[AuthzedAction.READ], | ||
) | ||
) | ||
permissions.append( | ||
Permission( | ||
name="writer", | ||
types=FeatureView, | ||
with_subclasses=True, | ||
policy=RoleBasedPolicy(roles=["writer"]), | ||
actions=[AuthzedAction.WRITE], | ||
) | ||
) | ||
permissions.append( | ||
Permission( | ||
name="special", | ||
types=FeatureView, | ||
with_subclasses=True, | ||
name_pattern="special.*", | ||
policy=RoleBasedPolicy(roles=["admin", "special-reader"]), | ||
actions=[AuthzedAction.READ, AuthzedAction.WRITE], | ||
) | ||
) | ||
|
||
rm = RoleManager() | ||
rm.add_roles_for_user("r", ["reader"]) | ||
rm.add_roles_for_user("w", ["writer"]) | ||
rm.add_roles_for_user("rw", ["reader", "writer"]) | ||
rm.add_roles_for_user("admin", ["reader", "writer", "admin"]) | ||
sm = SecurityManager(role_manager=rm, permissions=permissions) | ||
set_security_manager(sm) | ||
return sm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.