Skip to content

feat: Auth registry audit log writes - #387

Merged
jiaolong89 merged 46 commits into
masterfrom
auth_registry_audit_log_writes
Oct 21, 2026
Merged

jiaolong89 merged 46 commits into
masterfrom
auth_registry_audit_log_writes

Conversation

@jiaolong89

Copy link
Copy Markdown

What this PR does / why we need it:

Enable audit logs on registry grpc write ops

Which issue(s) this PR fixes:

Misc

Comment thread sdk/python/feast/infra/registry/sql.py Outdated
)
row = conn.execute(stmt).first()
if not row:
raise RuntimeError(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

With enable_object_audit_log: true and purge_feast_metadata: true together, every registry write fails. Purge mode skips _maybe_init_project_metadata and _sync_feast_metadata_to_projects_table deletes the feast_metadata rows, so this raises on every apply/delete, rolls back, and the registry becomes effectively read-only. Could we either reject that combination in a SqlRegistryConfig validator, or get project_uuid from something that doesn't depend on feast_metadata?

@jiaolong89 jiaolong89 Oct 13, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

makes sense, I'll add in a SqlRegistryConfig validator

name,
project,
"validation_reference_name",
"validation_reference_proto",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

apply_materialization goes through _apply_object with audit on, so every materialization run writes an UPDATE row with two full gzip copies of the feature view proto, including the full interval list. A view materialized every 15 min adds ~96 rows/day, which will far outnumber real definition changes. Can we pass audit=False here, or record materialization under a separate category?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

ah good catch, Yeah Ill pass in a audit=False

Comment thread sdk/python/feast/infra/registry/sql.py Outdated
)
deleted = rows.rowcount

self._apply_object(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This calls _apply_object(projects, ...) on a second transaction while the outer delete + audit transaction is still open, so the project update isn't atomic with the delete. Routing delete_data_source / delete_permission through here also changes their behavior: a project with no projects row now raises ProjectObjectNotFoundException and rolls back, where it used to succeed, and on SQLite the inner write can fail with database is locked. Can the project update use the same conn?

Comment thread sdk/python/feast/infra/registry/sql.py Outdated
projects.c.project_id == name
)
).first()
before_bytes = (

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit: get_project just found the row, so this to_proto().SerializeToString() fallback looks unreachable. If it were ever hit, it would quietly audit re-serialized bytes rather than the stored ones, so raising seems safer. Separately, _project_uuid_for_audit runs an extra SELECT on every audited write inside the transaction; it could be fetched once per transaction.

Comment thread sdk/python/feast/infra/registry/sql.py Outdated
before_bytes,
None,
)
for t in {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

delete_project writes one DELETE row for the project, then bulk-deletes every child object (entities, feature views, data sources, permissions, …) without audit rows. Their final protos are lost from the audit trail, and each object's history still ends at its last create/update, as if it still existed. Should we write a DELETE row per child object here (inside the same transaction)?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yes, will make it write a DELETE row for every child object that is deleted

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

In full-auth mode (AuthInterceptor, used whenever write_auth_only is off), nothing sets a request id, and current_user is set inside intercept_service, which runs on the gRPC polling thread rather than the worker that runs the handler. Audit rows in that mode would get request_id = NULL and an actor that's NULL or left over from an earlier call on that worker. Can we set both in the handler wrapper on the worker thread, the same way WritePathAuthInterceptor does?

sm = get_security_manager()
if sm is not None:
sm.set_current_user(current_user)
sm.set_request_id(str(uuid.uuid4()))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

These ContextVars are set on a pooled worker thread but never reset, so the actor/request id stay on that thread after the RPC. Any later registry write on the same thread that doesn't go through this path (e.g. implicit project init) would be attributed to the previous caller. Suggest token = var.set(...) with var.reset(token) in a finally.


assert isinstance(feature_view, SortedFeatureView)

def test_delete_entity_forwards_proto_field_name(self, sqlite_fallback_registry):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This test sits in TestSqlRegistrySortedFeatureView and only checks that the entity is gone. It never turns on enable_object_audit_log for SqlFallbackRegistry, so fallback audit writes and cache eviction on the newly routed data source / permission deletes aren't tested. Could we move it to its own class and assert the audit rows too? (Also, the TestObjectAuditLogSchema docstring still says "no inserts yet".)

Comment thread sdk/python/feast/infra/registry/sql.py Resolved
Comment thread sdk/python/feast/infra/registry/sql.py Outdated
).all()
for row in rows:
mapping = row._mapping
self._record_object_audit(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This runs one INSERT per child row inside the delete_project write transaction, and looks up actor/request_id again for each one. A project with thousands of objects means thousands of round trips while holding the write lock (the whole database lock on SQLite). Could we get actor/request_id once and do a single executemany insert(object_audit_log) with a list of row dicts?

Comment thread sdk/python/feast/infra/registry/sql.py Outdated
if row:
before_bytes = row._mapping[proto_field_name]
operation = ObjectAuditLogOperation.UPDATE
if proto_field_name in [

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Following up on the no-op update comment from the last round: infra_proto and validation_reference_proto still aren't in this unchanged-object check, so unchanged update_infra / apply_validation_reference calls still write an UPDATE row where before_bytes == after_bytes. update_infra runs on every feast apply, so each apply adds a managed_infra row with two identical blobs, the same noise the apply_materialization fix removed. Could we skip the audit write (and ideally the UPDATE) when the bytes are equal?

Comment thread sdk/python/feast/infra/registry/sql.py Outdated
operation,
before_bytes,
after_bytes,
self._project_uuid_if_auditing(conn, project),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This still does a separate PROJECT_UUID SELECT right after _maybe_init_project_metadata (~1453) already read or created the same row in its own transaction. Besides the extra round trip, a concurrent delete_project landing between the two can cause the RuntimeError here. Could _maybe_init_project_metadata return the UUID so we pass it in, or could the get-or-create move into this transaction?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This is what my cursor is suggesting:
Give _maybe_init_project_metadata the same optional conn pattern as _set_last_updated_metadata, and return the UUID

Comment thread sdk/python/feast/infra/registry/sql.py Outdated
ObjectAuditLogOperation.DELETE,
before_bytes,
None,
self._project_uuid_if_auditing(conn, project),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

With auditing on, this raises if the PROJECT_UUID row is missing, and the delete paths no longer call _maybe_init_project_metadata (the old apply_project(get_project()) did as a side effect). A registry that previously ran with purge_feast_metadata: true and then turns on the audit log can't delete anything in a project until something is applied there, and a project nobody applies to again can never be deleted. Same in delete_project (~1899). Could we create the UUID lazily inside the write transaction?

)
deleted = rows.rowcount

self._update_project_timestamp(project, update_datetime, update_time, conn)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

When nothing was deleted and not_found_exception is None, this still updates the project timestamp, writes the last-updated metadata and refreshes. delete_feature_view tries 4 tables this way, so the misses each update the project, and if the view doesn't exist at all we raise only after 4 committed updates, which invalidates every client's cache for a failed delete. Could we skip the timestamp/refresh when rowcount == 0?

Comment thread sdk/python/feast/infra/registry/sql.py Outdated
select(projects.c.project_proto).where(projects.c.project_id == name)
).first()
if proto_row is None:
raise ProjectNotFoundException(name)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This changes the exception for a missing project from ProjectObjectNotFoundException (a FeastObjectNotFoundException, so NOT_FOUND) to ProjectNotFoundException (a plain FeastError, so INTERNAL/500). Callers that catch the not-found type for an already-deleted project will now get a 500. Was that intended? If not, can we keep raising ProjectObjectNotFoundException (and update test_delete_project_raises_when_missing)?

Comment thread sdk/python/feast/infra/registry/sql.py Outdated
None,
project_uuid,
)
for t in {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This hand-written table set has to stay in sync with _PROJECT_CHILD_AUDIT_TABLES (~326). If a new child table is added here but not there, it gets wiped with no audit rows, which is the gap from last round back again. Could we build this loop from [t for t, _, _ in _PROJECT_CHILD_AUDIT_TABLES] + [feast_metadata, projects]?

user_token, request_id_token = _set_user_from_metadata(metadata)
except AuthenticationError as e:
context.abort(grpc.StatusCode.UNAUTHENTICATED, str(e))
return behavior(request, context)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

For unary_stream / stream_stream handlers, behavior() returns a generator, so this returns immediately and the finally resets current_user / request_id before the stream body runs. Now that full-auth mode wraps every RPC, a streaming handler that checks permissions or writes the registry runs as no user. Could the streaming wrappers iterate the generator inside the try (yield from behavior(...)) so the reset runs after the stream ends?

ObjectAuditLogOperation.DELETE.value,
]

def test_failed_audit_insert_rolls_back_apply(self, sqlite_registry_audit):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The new coverage is great. These two rollback tests (here and _delete at 806) still patch _record_object_audit to raise, though, so a real object_audit_log INSERT never fails and a regression that moved the insert outside the transaction would still pass. Could we make the real insert fail instead (e.g. violate the CHECK, or patch _project_uuid_for_audit to raise)? Tests for a failed auth call, a streaming handler, and a no-op update_infra would also cover the other comments here.

…nsaction and uses that value on the audit insert.
… write transaction via _maybe_init_project_metadata. _delete_object and delete_project pick that up with no extra call sites.
…mestamp, last-updated metadata, or cache refresh.
…ject row is missing, so already-deleted projects stay NOT_FOUND / 404 instead of INTERNAL / 500.
…h yield froms the handler inside the try so current_user / request_id stay set until the stream ends.
…e BEFORE INSERT trigger (RAISE(ABORT)), not a patched _record_object_audit
Comment thread sdk/python/feast/infra/registry/sql.py Outdated
ObjectAuditLogOperation.DELETE,
before_bytes,
None,
self._project_uuid_if_auditing(conn, project),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Here the PROJECT_UUID lock is taken after the object row has been deleted (~1726), but _apply_object (~1488) and delete_project (~1942) take PROJECT_UUID first. With auditing on, an apply_entity('e') holding the UUID lock and waiting on row e can deadlock against a delete_entity('e') holding row e and waiting on the UUID, and the database aborts one of them. Could we get the UUID at the top of the _delete_object transaction, before the SELECT/DELETE?

…log and purge_feast_metadata so the other flag is read from ValidationInfo.data before the attribute is stored.
…ow. _record_object_audit inserts with [row]; the child path still batches one actor/recorded_at and executemanys the list.
…operties on SqlRegistry, copied once in __init__. Assignment raises AttributeError.
…uality checks first; only a real INSERT/UPDATE calls _maybe_init_project_metadata.
…e as entities and feature views. Byte comparison is only the fallback.
…LECT and before DELETE, same order as _apply_object. Misses still return without touching UUID.
self.description = description
self.tags = tags or {}

def __eq__(self, other):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This ignores _profile, but to_proto stores it as ge_profile. Since validation_reference_proto now goes through the from_proto equality check in _apply_object, re-applying a reference after its profile was computed or refreshed compares equal on name/dataset/description/tags/profiler and returns early. The new ge_profile is never stored and no UPDATE audit row is written. Could we include the profile in the comparison (e.g. compare ge_profile bytes from to_proto), or leave validation references to the byte check in _apply_object?

Comment thread sdk/python/feast/infra/registry/sql.py Outdated

row = _select_uuid(lock=False)
if row and for_update:
row = _select_uuid(lock=True)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If the unlocked read at 1733 finds the UUID but this locked read comes back empty, a concurrent delete_project committed while we waited on the lock. Right now we fall through to insert-do-nothing, create a new PROJECT_UUID, and carry on: the entity is inserted, an audit CREATE is written under the new UUID, and _update_project_timestamp silently does nothing because the projects row is gone. That leaves an orphaned object and feast_metadata rows for a project that no longer exists. Could we raise here (e.g. ProjectObjectNotFoundException) when the unlocked read found a row but the locked one didn't, instead of creating a new UUID?

Comment thread sdk/python/feast/infra/registry/sql.py Outdated
"project_id": project,
},
)
row = _select_uuid(lock=for_update)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

On MySQL (default REPEATABLE READ), when for_update=False (i.e. auditing off, the default), this is a snapshot read. If another transaction committed the PROJECT_UUID after our snapshot started (at the object SELECT, ~1561), the INSERT IGNORE skips the duplicate but this SELECT still can't see the row, so we raise "insert raced and the row is still missing" and the apply fails. Postgres READ COMMITTED is fine. Could this re-read always use a locking read (with_for_update(), which reads the latest committed row), or get the value back from the insert via ON DUPLICATE KEY UPDATE?

None,
project_uuid,
)
for t in [t for t, _, _ in _PROJECT_CHILD_AUDIT_TABLES] + [

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This list now always deletes feast_metadata before projects, but _apply_object / _delete_object update projects (~1694) before feast_metadata LAST_UPDATED (~1699). With auditing off nothing takes the UUID lock first to serialize them, so on Postgres an apply that has updated projects and a delete_project that has deleted feast_metadata each wait on the other's row and one is aborted. (The old set iteration order was random; this makes it reliably inverted.) Could we put projects before feast_metadata here so the order matches the apply path?

…nit_project_metadata now raises ProjectObjectNotFoundException instead of minting a replacement UUID.
…, including when auditing is off. That is a current read on MySQL REPEATABLE READ, so a concurrent commit is visible instead of raising “insert raced and the row is still missing.” Unaudited applies that already find a UUID still skip the lock.
… — the same order as _apply_object / _delete_object.
…integration/registration/test_sql_registry_object_audit_log.py, using the existing testcontainers servers with enable_object_audit_log on and off.
Comment thread sdk/python/feast/infra/registry/sql.py Outdated
after_bytes: Optional[bytes] = None

if row:
before_bytes = row._mapping[proto_field_name]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

before_bytes and the CREATE/UPDATE choice come from this unlocked read, but the UUID lock that serializes writers is only taken later in _project_uuid_for_mutating_apply (~1632 / ~1672). Under concurrent writes to the same object, the second writer acts on a stale read:

  • Updates: T1 and T2 both read v0. T1 locks, writes v1, and audits v0→v1. T2 then gets the lock, writes v2, and audits v0→v2, so the audit history silently skips v1.
  • Creates: both see no row and both choose CREATE; the second fails with a PK violation instead of becoming an UPDATE.

The registry data itself ends up right (last writer wins); it's the audit row that's wrong, which is the thing this table exists to get right. Could we re-read the object row after taking the UUID lock (SELECT ... FOR UPDATE), recompute before_bytes / operation from that, and re-run the no-op check? The first unlocked read can stay as the fast no-op exit so unchanged applies still don't lock. Related: the comment at ~1826 says _apply_object locks "UUID then object row", but it currently reads the object row first.

stmt = stmt.with_for_update()
return conn.execute(stmt).first()

existing = _select_uuid(lock=False)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit: when the UUID exists and for_update=True (every audited write), this does an unlocked SELECT and then a FOR UPDATE SELECT of the same row, so two round trips inside the write transaction. Could we start with the FOR UPDATE read when for_update is set? Since a locked read alone can't tell "never had a UUID" from "delete_project just committed", a miss would need a check of the projects row before falling through to insert-do-nothing (and could raise ProjectObjectNotFoundException the same way 1741 does). That would also close the remaining case where the unlocked read misses because the project was deleted first and we create a new UUID for it.

…ject, and rebuild operation / before_bytes / no-op from that row. Unchanged applies still return on the unlocked read and do not lock.
Comment on lines +1285 to +1290
filters = [object_audit_log.c.project_id == project]
if object_type:
filters.append(object_audit_log.c.object_type == object_type)
if object_name:
filters.append(object_audit_log.c.object_name == object_name)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

These new filters can't use the per-object index. idx_object_audit_log_project_object_recorded (line 404) is keyed (project_uuid, object_type, object_name, recorded_at), but the query filters on project_id, so the index's first column never matches.

On Postgres the planner will use idx_object_audit_log_project_id_recorded instead. It reads every audit row in the project and checks object_type and object_name row by row, twice per page: once for the COUNT(*) and once for the page itself. Looking up one object's history costs as much as listing the whole project's.

Suggest resolving the project's UUID first and filtering on that:

project_uuid = self._get_project_uuid(conn, project)  # or however PROJECT_UUID is read elsewhere
filters = [object_audit_log.c.project_uuid == project_uuid]
if object_type:
    filters.append(object_audit_log.c.object_type == object_type)
if object_name:
    filters.append(object_audit_log.c.object_name == object_name)

This also fixes the history leak: if a project is deleted and recreated with the same name, filtering by name returns the old project's audit rows, while filtering by UUID doesn't. If the UUID isn't found, return an empty page rather than falling back to the name.

@jiaolong89 jiaolong89 Oct 20, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

my cursor suggested I add a new index:
idx_object_audit_log_project_id_type_name_recorded = Index(
"idx_object_audit_log_project_id_type_name_recorded",
object_audit_log.c.project_id,
object_audit_log.c.object_type,
object_audit_log.c.object_name,
object_audit_log.c.recorded_at,
object_audit_log.c.id,
)

I can add it via schema deploy

@jiaolong89
jiaolong89 merged commit a0bedf3 into master Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants