Skip to content

feat(socket-auth): fleetops channel resolvers, driver socket tokens, per-customer tracking channel - #358

Merged
roncodes merged 3 commits into
release/v0.6.72from
feature/socket-auth
Oct 7, 2026
Merged

roncodes merged 3 commits into
release/v0.6.72from
feature/socket-auth

Conversation

@roncodes

@roncodes roncodes commented Oct 6, 2026 •

Copy link
Copy Markdown
Member

What

FleetOps part of realtime socket authentication.

  • Channel resolvers. Every FleetOps channel prefix is registered with core-api's SocketChannelRegistry: order, driver, driverAssigned, vehicle, trailer, device, waypoint, entity, place, contact, fleet, zone, service_area, service_rate, service_quote, purchase_rate, tracking_status, tracking_number, payload (generic model resolver), customer, vendor, facilitator (morph prefixes), position (uuid only; positions have no public id) and tracking (always denied).
    • Console users and API credentials: records of their own company.
    • Drivers: their own driver record, their current vehicle and its devices and positions, and orders assigned to them (directly or through one of the order's payload entities).
    • Customers: orders where they are the customer, plus the driver and vehicle of their active orders (not completed or canceled).
  • Driver socket tokens. A principal resolver claims Sanctum users who drive for the current company on v1/socket/token. The resulting driver principal has sub = driver uuid and ids = driver uuid and public id plus user uuid and public id.
  • Replay hardening. When socket auth is enabled, positions/replay only accepts a channel_id that the requesting user could subscribe to (checked through ChannelAuthorizer). Any other channel gets a 403. When socket auth is off, the endpoint behaves exactly as before.
  • Public tracking channel (per customer).
    • TrackingScope covers one customer of one order. A stop belongs to the waypoint's customer, else to the order's customer.
    • TrackingChannel gives tracking.{opaque} and the scoped token, both through core-api SocketToken::trackingId() and SocketToken::forTracking().
    • TrackingUpdate builds the sanitized payload. It holds only the viewer's stops (status, ETA, timeline status/code/time with no free-text details) and whole-route counts. For the driver it holds the first name, the vehicle label and the online flag, with no photo or phone. The vehicle position is rounded to 4 decimals and comes with heading and seen_at. Driver and position are included only while the order is en route and the viewer still has an incomplete stop.
    • TrackingPublisher and the PublishTrackingUpdate job publish when order status, assignment or ETA changes, on waypoint/entity activity, and on driver or vehicle positions. The hooks do nothing while socket auth is off. Position lookups are throttled to once per 5 s per driver/vehicle and per order, and ETAs are refreshed at most once a minute.
  • Console scheduler. The scheduler no longer subscribes to the dead company.{id}.orders channel. Its teardown closes only the driver channels it opened; before, it closed every channel, chat included.

Why

Without these resolvers, enabling socket authentication would deny every FleetOps channel. With them, drivers and customers only see their own data.

Dependency

Requires fleetbase/core-api ^1.6.69 (raised in composer.json). CI on this PR needs that core-api release, so composer install fails until it is tagged.

Test plan

Verified by CI. New Pest tests cover:

  • each resolver across two companies
  • driver and customer narrow allow/deny
  • the driver principal resolver
  • replay channel rejection
  • tracking channel determinism and per-customer separation
  • payload sanitization
  • location publish gating and throttling, the job and the listener

There is also an Ember unit test for the scheduler teardown.

Related PRs

Part of the authenticated realtime channels rollout (socket auth), one PR per repo:

…per-customer tracking channel

- Register who may subscribe to every FleetOps channel prefix with the core
  SocketChannelRegistry: company match for console users and API credentials;
  narrow rules for drivers (own record, current vehicle and its devices and
  positions, assigned orders incl. via payload entities) and customers (own
  orders, driver and vehicle of their active orders). tracking.* is denied
  by the registry (reachable only through a scoped tracking token).
- Claim Sanctum users who drive for the current company as driver socket
  principals on v1/socket/token.
- positions/replay validates channel_id with the ChannelAuthorizer when socket
  authentication is on.
- Public tracking channel: TrackingScope (one customer of one order),
  TrackingChannel (name/opaque id/token via core-api), TrackingUpdate
  (sanitized per-customer payload) and TrackingPublisher (gated, throttled,
  queued) publishing on order, stop and position changes.
- Require fleetbase/core-api ^1.6.69.
…s only its own

The scheduler subscribed to company.{id}.orders, which nothing publishes to,
and its teardown closed every socket channel, chat included. It now opens
the per-driver channels only and on teardown closes just those (sweeping
once more for subscriptions still pending).
@roncodes
roncodes changed the base branch from main to release/v0.6.72 October 7, 2026 07:55
@roncodes
roncodes merged commit 802839f into release/v0.6.72 Oct 7, 2026
7 of 9 checks passed
@roncodes
roncodes deleted the feature/socket-auth branch October 7, 2026 07:56
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.

1 participant