Repository navigation
Added permission assert check for registry server, offline server, online server functions #25
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
redhatHameed
merged 1 commit into
RHEcosystemAppEng:feast-rbac
from
redhatHameed:server-permissions
Jul 5, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -17,7 +17,9 @@ | |
| from feast import proto_json, utils | ||
| from feast.constants import DEFAULT_FEATURE_SERVER_REGISTRY_TTL | ||
| from feast.data_source import PushMode | ||
| from feast.errors import PushSourceNotFoundException | ||
| from feast.errors import FeatureViewNotFoundException, PushSourceNotFoundException | ||
| from feast.permissions.action import WRITE, AuthzedAction | ||
| from feast.permissions.security_manager import assert_permissions | ||
|
|
||
|
|
||
| # TODO: deprecate this in favor of push features | ||
|
|
@@ -86,19 +88,40 @@ async def get_body(request: Request): | |
| def get_online_features(body=Depends(get_body)): | ||
| try: | ||
| body = json.loads(body) | ||
| full_feature_names = body.get("full_feature_names", False) | ||
| entity_rows = body["entities"] | ||
| # Initialize parameters for FeatureStore.get_online_features(...) call | ||
| if "feature_service" in body: | ||
| features = store.get_feature_service( | ||
| feature_service = store.get_feature_service( | ||
| body["feature_service"], allow_cache=True | ||
| ) | ||
| assert_permissions( | ||
|
redhatHameed marked this conversation as resolved.
Resolved
|
||
| resource=feature_service, actions=[AuthzedAction.QUERY_ONLINE] | ||
| ) | ||
| features = feature_service | ||
| else: | ||
| features = body["features"] | ||
|
|
||
| full_feature_names = body.get("full_feature_names", False) | ||
| all_feature_views, all_on_demand_feature_views = ( | ||
| utils._get_feature_views_to_use( | ||
| store.registry, | ||
| store.project, | ||
| features, | ||
| allow_cache=True, | ||
| hide_dummy_entity=False, | ||
| ) | ||
| ) | ||
| for feature_view in all_feature_views: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not going to do this right now, but we probably need an assert function accepting a list of resources |
||
| assert_permissions( | ||
| resource=feature_view, actions=[AuthzedAction.QUERY_ONLINE] | ||
| ) | ||
| for od_feature_view in all_on_demand_feature_views: | ||
| assert_permissions( | ||
| resource=od_feature_view, actions=[AuthzedAction.QUERY_ONLINE] | ||
| ) | ||
|
|
||
| response_proto = store.get_online_features( | ||
| features=features, | ||
| entity_rows=body["entities"], | ||
| entity_rows=entity_rows, | ||
| full_feature_names=full_feature_names, | ||
| ).proto | ||
|
|
||
|
|
@@ -117,16 +140,41 @@ def push(body=Depends(get_body)): | |
| try: | ||
| request = PushFeaturesRequest(**json.loads(body)) | ||
| df = pd.DataFrame(request.df) | ||
| actions = [] | ||
| if request.to == "offline": | ||
| to = PushMode.OFFLINE | ||
| actions = [AuthzedAction.WRITE_OFFLINE] | ||
| elif request.to == "online": | ||
| to = PushMode.ONLINE | ||
| actions = [AuthzedAction.WRITE_ONLINE] | ||
| elif request.to == "online_and_offline": | ||
| to = PushMode.ONLINE_AND_OFFLINE | ||
| actions = WRITE | ||
| else: | ||
| raise ValueError( | ||
| f"{request.to} is not a supported push format. Please specify one of these ['online', 'offline', 'online_and_offline']." | ||
| ) | ||
|
|
||
| from feast.data_source import PushSource | ||
|
|
||
| all_fvs = store.list_feature_views( | ||
| allow_cache=request.allow_registry_cache | ||
| ) + store.list_stream_feature_views( | ||
| allow_cache=request.allow_registry_cache | ||
| ) | ||
| fvs_with_push_sources = { | ||
| fv | ||
| for fv in all_fvs | ||
| if ( | ||
| fv.stream_source is not None | ||
| and isinstance(fv.stream_source, PushSource) | ||
| and fv.stream_source.name == request.push_source_name | ||
| ) | ||
| } | ||
|
|
||
|
redhatHameed marked this conversation as resolved.
Resolved
|
||
| for feature_view in fvs_with_push_sources: | ||
| assert_permissions(resource=feature_view, actions=actions) | ||
|
|
||
| store.push( | ||
| push_source_name=request.push_source_name, | ||
| df=df, | ||
|
|
@@ -149,10 +197,24 @@ def write_to_online_store(body=Depends(get_body)): | |
| try: | ||
| request = WriteToFeatureStoreRequest(**json.loads(body)) | ||
| df = pd.DataFrame(request.df) | ||
| feature_view_name = request.feature_view_name | ||
| allow_registry_cache = request.allow_registry_cache | ||
| try: | ||
| feature_view = store.get_stream_feature_view( | ||
| feature_view_name, allow_registry_cache=allow_registry_cache | ||
| ) | ||
| except FeatureViewNotFoundException: | ||
| feature_view = store.get_feature_view( | ||
| feature_view_name, allow_registry_cache=allow_registry_cache | ||
| ) | ||
|
|
||
| assert_permissions( | ||
| resource=feature_view, actions=[AuthzedAction.WRITE_ONLINE] | ||
| ) | ||
| store.write_to_online_store( | ||
| feature_view_name=request.feature_view_name, | ||
| feature_view_name=feature_view_name, | ||
| df=df, | ||
| allow_registry_cache=request.allow_registry_cache, | ||
| allow_registry_cache=allow_registry_cache, | ||
| ) | ||
| except Exception as e: | ||
| # Print the original exception on the server side | ||
|
|
@@ -168,6 +230,10 @@ def health(): | |
| def materialize(body=Depends(get_body)): | ||
| try: | ||
| request = MaterializeRequest(**json.loads(body)) | ||
| for feature_view in request.feature_views: | ||
| assert_permissions( | ||
| resource=feature_view, actions=[AuthzedAction.WRITE_ONLINE] | ||
| ) | ||
| store.materialize( | ||
| utils.make_tzaware(parser.parse(request.start_ts)), | ||
| utils.make_tzaware(parser.parse(request.end_ts)), | ||
|
|
@@ -183,6 +249,10 @@ def materialize(body=Depends(get_body)): | |
| def materialize_incremental(body=Depends(get_body)): | ||
| try: | ||
| request = MaterializeIncrementalRequest(**json.loads(body)) | ||
| for feature_view in request.feature_views: | ||
| assert_permissions( | ||
| resource=feature_view, actions=[AuthzedAction.WRITE_ONLINE] | ||
| ) | ||
| store.materialize_incremental( | ||
| utils.make_tzaware(parser.parse(request.end_ts)), request.feature_views | ||
| ) | ||
|
|
||
This file contains hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.