Skip to content

Commit f42be49

Browse files
committed
feat: Implement RegistryServer.Proto RPC with RBAC-filtered response
The Proto RPC existed in the RegistryServer proto contract but had no real server-side implementation, so RemoteRegistry.proto() failed with UNIMPLEMENTED (breaking CachingRegistry init, registry refresh, and metrics over a remote registry). The naive fix (return proxied_registry.proto()) would bypass RBAC and return every object regardless of authorization. Build the RegistryProto from individually RBAC-filtered list_* calls, each passed through permitted_resources(..., AuthzedAction.DESCRIBE), iterating every project. Under NoAuthConfig this is a no-op so the full registry is returned (remote registries keep working); with auth enabled callers only see objects they may DESCRIBE. Adds unit tests covering the no-auth full-return path, RBAC filtering, and the empty-registry case. Closes feast-dev#6558 Signed-off-by: Nick Quinn <[email protected]>
1 parent 89d6d81 commit f42be49

2 files changed

Lines changed: 198 additions & 1 deletion

File tree

‎sdk/python/feast/registry_server.py‎

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,89 @@ def __init__(self, registry: BaseRegistry) -> None:
182182
self.proxied_registry = registry
183183

184184
def Proto(self, request: Empty, context) -> RegistryProto:
185-
return self.proxied_registry.proto()
185+
"""Build a RegistryProto from individually RBAC-filtered list calls.
186+
187+
The ``RegistryServer.Proto`` RPC must honor the same permission checks as the
188+
other RPCs rather than returning ``proxied_registry.proto()`` directly, which
189+
would bypass RBAC and expose every object (entities, feature views, data
190+
sources, permissions, projects, etc.) regardless of authorization.
191+
192+
Each object type is filtered with ``permitted_resources(..., DESCRIBE)``: under
193+
``NoAuthConfig`` this is a no-op (the full registry is returned, so remote
194+
registries keep working), while with auth enabled the caller only sees the
195+
objects they are permitted to ``DESCRIBE``.
196+
"""
197+
198+
def describable(resources: list) -> list:
199+
return permitted_resources(
200+
resources=cast(list[FeastObject], resources),
201+
actions=AuthzedAction.DESCRIBE,
202+
)
203+
204+
registry_proto = RegistryProto()
205+
206+
for project in describable(self.proxied_registry.list_projects()):
207+
registry_proto.projects.append(project.to_proto())
208+
project_name = project.name
209+
210+
for entity in describable(
211+
self.proxied_registry.list_entities(project=project_name)
212+
):
213+
registry_proto.entities.append(entity.to_proto())
214+
215+
for data_source in describable(
216+
self.proxied_registry.list_data_sources(project=project_name)
217+
):
218+
registry_proto.data_sources.append(data_source.to_proto())
219+
220+
for feature_view in describable(
221+
self.proxied_registry.list_feature_views(project=project_name)
222+
):
223+
registry_proto.feature_views.append(feature_view.to_proto())
224+
225+
for stream_feature_view in describable(
226+
self.proxied_registry.list_stream_feature_views(project=project_name)
227+
):
228+
registry_proto.stream_feature_views.append(
229+
stream_feature_view.to_proto()
230+
)
231+
232+
for on_demand_feature_view in describable(
233+
self.proxied_registry.list_on_demand_feature_views(project=project_name)
234+
):
235+
registry_proto.on_demand_feature_views.append(
236+
on_demand_feature_view.to_proto()
237+
)
238+
239+
for label_view in describable(
240+
self.proxied_registry.list_label_views(project=project_name)
241+
):
242+
registry_proto.label_views.append(label_view.to_proto())
243+
244+
for feature_service in describable(
245+
self.proxied_registry.list_feature_services(project=project_name)
246+
):
247+
registry_proto.feature_services.append(feature_service.to_proto())
248+
249+
for saved_dataset in describable(
250+
self.proxied_registry.list_saved_datasets(project=project_name)
251+
):
252+
registry_proto.saved_datasets.append(saved_dataset.to_proto())
253+
254+
for validation_reference in describable(
255+
self.proxied_registry.list_validation_references(project=project_name)
256+
):
257+
registry_proto.validation_references.append(
258+
validation_reference.to_proto()
259+
)
260+
261+
for permission in describable(
262+
self.proxied_registry.list_permissions(project=project_name)
263+
):
264+
registry_proto.permissions.append(permission.to_proto())
265+
266+
registry_proto.last_updated.FromDatetime(datetime.now(timezone.utc))
267+
return registry_proto
186268

187269
def ApplyEntity(self, request: RegistryServer_pb2.ApplyEntityRequest, context):
188270
entity = cast(
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
"""Unit tests for the ``RegistryServer.Proto`` RPC (issue #6558).
2+
3+
The RPC must build the ``RegistryProto`` from individually RBAC-filtered list calls
4+
rather than returning ``proxied_registry.proto()`` directly (which would bypass
5+
permissions). Under ``NoAuthConfig`` filtering is a no-op, so the full registry is
6+
returned; with auth enabled only ``DESCRIBE``-permitted objects are included.
7+
"""
8+
9+
from unittest.mock import patch
10+
11+
from google.protobuf.empty_pb2 import Empty
12+
13+
from feast.data_source import DataSource
14+
from feast.entity import Entity
15+
from feast.feast_object import FeastObject
16+
from feast.project import Project
17+
from feast.registry_server import RegistryServer
18+
from feast.value_type import ValueType
19+
20+
21+
class _FakeRegistry:
22+
"""Minimal BaseRegistry stand-in exposing only the list_* calls Proto uses."""
23+
24+
def __init__(self, projects, entities_by_project, data_sources_by_project):
25+
self._projects = projects
26+
self._entities = entities_by_project
27+
self._data_sources = data_sources_by_project
28+
29+
def list_projects(self, allow_cache: bool = False, tags=None):
30+
return self._projects
31+
32+
def list_entities(self, project: str, allow_cache: bool = False, tags=None):
33+
return self._entities.get(project, [])
34+
35+
def list_data_sources(self, project: str, allow_cache: bool = False, tags=None):
36+
return self._data_sources.get(project, [])
37+
38+
# Every other object type is empty for this fixture.
39+
def _empty(self, *args, **kwargs):
40+
return []
41+
42+
list_feature_views = _empty
43+
list_stream_feature_views = _empty
44+
list_on_demand_feature_views = _empty
45+
list_label_views = _empty
46+
list_feature_services = _empty
47+
list_saved_datasets = _empty
48+
list_validation_references = _empty
49+
list_permissions = _empty
50+
51+
52+
def _entity(name: str) -> Entity:
53+
return Entity(name=name, value_type=ValueType.STRING)
54+
55+
56+
def _data_source(name: str) -> DataSource:
57+
from feast.infra.offline_stores.file_source import FileSource
58+
59+
return FileSource(name=name, path=f"/tmp/{name}.parquet", timestamp_field="ts")
60+
61+
62+
def _build_server() -> tuple[RegistryServer, _FakeRegistry]:
63+
registry = _FakeRegistry(
64+
projects=[Project(name="proj_a"), Project(name="proj_b")],
65+
entities_by_project={
66+
"proj_a": [_entity("driver"), _entity("customer")],
67+
"proj_b": [_entity("merchant")],
68+
},
69+
data_sources_by_project={"proj_a": [_data_source("src_a")]},
70+
)
71+
return RegistryServer(registry), registry # type: ignore[arg-type]
72+
73+
74+
def test_proto_returns_full_registry_when_no_auth():
75+
"""NoAuthConfig (no security manager) -> every object across all projects."""
76+
server, _ = _build_server()
77+
78+
result = server.Proto(Empty(), context=None)
79+
80+
assert {p.spec.name for p in result.projects} == {"proj_a", "proj_b"}
81+
assert {e.spec.name for e in result.entities} == {"driver", "customer", "merchant"}
82+
assert {d.name for d in result.data_sources} == {"src_a"}
83+
# last_updated is stamped so cache consumers see a fresh timestamp.
84+
assert result.HasField("last_updated")
85+
86+
87+
def test_proto_filters_by_describe_permission():
88+
"""With RBAC, only DESCRIBE-permitted objects are included."""
89+
server, _ = _build_server()
90+
91+
# Simulate a security manager that permits everything except the "customer"
92+
# entity, regardless of object type (filters by DESCRIBE).
93+
def fake_permitted(resources: list[FeastObject], actions):
94+
return [r for r in resources if getattr(r, "name", None) != "customer"]
95+
96+
with patch(
97+
"feast.registry_server.permitted_resources", side_effect=fake_permitted
98+
) as mocked:
99+
result = server.Proto(Empty(), context=None)
100+
101+
assert mocked.called
102+
# "customer" is filtered out; everything else survives.
103+
assert {e.spec.name for e in result.entities} == {"driver", "merchant"}
104+
assert {p.spec.name for p in result.projects} == {"proj_a", "proj_b"}
105+
assert {d.name for d in result.data_sources} == {"src_a"}
106+
107+
108+
def test_proto_empty_registry():
109+
"""No projects -> empty (but valid) RegistryProto, not an error."""
110+
server = RegistryServer(_FakeRegistry([], {}, {})) # type: ignore[arg-type]
111+
112+
result = server.Proto(Empty(), context=None)
113+
114+
assert len(result.projects) == 0
115+
assert len(result.entities) == 0

0 commit comments

Comments
 (0)