Skip to content

make IP optional in activity log#2394

Merged
wojcik91 merged 6 commits into
devfrom
activity_log_optional_ip
Mar 18, 2026
Merged

make IP optional in activity log#2394
wojcik91 merged 6 commits into
devfrom
activity_log_optional_ip

Conversation

@wojcik91
Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.ip nullable in Postgres and update Rust models/event contexts to use Option for 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

  • location and description are currently typed as optional (location?: string, description?: string), but the API (Rust Option<T> without skip_serializing_if) serializes missing values as explicit null rather than omitting the field. To keep the web types accurate (and avoid unhandled null at runtime), consider changing these to string | null (and non-optional) similarly to the updated ip field.
  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.

@wojcik91 wojcik91 merged commit d0cd36e into dev Mar 18, 2026
7 checks passed
@wojcik91 wojcik91 deleted the activity_log_optional_ip branch March 18, 2026 08:41
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.

3 participants