Skip to content

feat(security): MQTT token rotation and revocation #17

@MarkCesium

Description

@MarkCesium

Summary

backend/devices/src/services/devices.py:40-42 hashes the device token with bcrypt and stores it. RegenerateDeviceToken exists but does not evict an already-connected MQTT session. No RevokeDeviceToken. A stolen device token stays usable until natural expiry (never, since there is no TTL).

Changes

  • New RPC RevokeDeviceToken(device_id) — clears the stored hash, publishes a kick signal.
  • RegenerateDeviceToken — same kick behaviour on top of existing rotation.
  • MQTT session termination via EMQX management API (POST /api/v5/clients/:clientid/kick on all nodes — ties into infra#25 when clustered).
  • Optional: add device.token_rotated_at; emit DeviceTokenRotated event for audit.

Verification

  • Device connected with token T1. Call RegenerateDeviceToken. Connection dropped; reconnect with T1 fails, with T2 succeeds.
  • RevokeDeviceToken — no token works; device is offline until a new one is issued.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions