make IP optional in activity log#2394
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR makes the Activity Log “IP” field optional end-to-end (DB → backend models/events → API → web UI), replacing the previous “unspecified IP” workaround with explicit null handling.
Changes:
- Make
activity_log_event.ipnullable in Postgres and update Rust models/event contexts to useOptionfor IPs. - Update web UI table rendering to display a consistent placeholder for missing IP/location values.
- Add/adjust unit + integration tests and refresh SQLx query metadata for nullable
ip.
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| web/src/shared/api/types.ts | Updates ActivityLogEvent IP type to allow null in the web API typings. |
| web/src/pages/ActivityLogPage/ActivityLogTable.tsx | Renders null/undefined IP/location values with an accessible placeholder. |
| migrations/20260317100000_[2.0.0]_activity_log_optional_ip.up.sql | Drops NOT NULL constraint on activity_log_event.ip. |
| migrations/20260317100000_[2.0.0]_activity_log_optional_ip.down.sql | Backfill NULL IPs and restores NOT NULL on rollback. |
| crates/defguard_session_manager/tests/session_manager/sessions.rs | Updates assertions for public_ip becoming optional. |
| crates/defguard_session_manager/tests/session_manager/event_flow.rs | Adds coverage for disconnect events producing public_ip: None. |
| crates/defguard_session_manager/src/session_state.rs | Emits connected events with public_ip: Some(...). |
| crates/defguard_session_manager/src/lib.rs | Removes “unspecified IP” workaround; emits public_ip: None where unavailable. |
| crates/defguard_session_manager/src/events.rs | Changes public_ip to Option<IpAddr> in event context. |
| crates/defguard_event_logger/src/message.rs | Changes logger context IP to Option<IpAddr> and wires through conversions. |
| crates/defguard_event_logger/src/lib.rs | Maps optional IP into DB model and adds a serialization regression test for null IP. |
| crates/defguard_core/tests/integration/api/mod.rs | Registers the new activity log integration test module. |
| crates/defguard_core/tests/integration/api/activity_log.rs | Adds integration test ensuring null IP persists and is returned by the API. |
| crates/defguard_core/src/handlers/activity_log.rs | Updates API response type to ip: Option<IpNetwork>. |
| crates/defguard_core/src/events.rs | Makes request contexts carry optional IPs and relaxes constructors to accept Into<Option<IpAddr>>. |
| crates/defguard_core/src/db/models/activity_log/mod.rs | Makes DB model ip optional (Option<IpNetwork>) for SQLx/model derive. |
| .sqlx/query-59d048f8110a53745afd80c607fc52cb537dfded663e6bbee73d5f908f0ca89e.json | SQLx metadata updated for nullable ip column in list query. |
| .sqlx/query-47c406366d0b53ca805cff303dfe2a67880adeaca1e10e50bea9b9fc53e08845.json | SQLx metadata updated for nullable ip column in find-by-id query. |
Comments suppressed due to low confidence (1)
web/src/shared/api/types.ts:1199
locationanddescriptionare currently typed as optional (location?: string,description?: string), but the API (RustOption<T>withoutskip_serializing_if) serializes missing values as explicitnullrather than omitting the field. To keep the web types accurate (and avoid unhandlednullat runtime), consider changing these tostring | null(and non-optional) similarly to the updatedipfield.
user_id: number;
username: string;
location?: string;
ip: string | null;
event: ActivityLogEventTypeValue;
module: ActivityLogModuleValue;
device: string;
description?: string;
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
moubctez
approved these changes
Mar 18, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Make IP field optional in activity log events to avoid forcing fake IPs in some cases (like VPN session disconnect which is triggered by defguard itself, not an external request).
Closes #2317