Repository navigation
Labels
BugError or issue in the systemError or issue in the systemGatewaysTopic Gateways: all features related to gateway featuresTopic Gateways: all features related to gateway features
Description
Gateway connections use the first two characters of the Gateway Asset ID to perform a bidirectional mapping of child asset IDs to/from the gateway, when multiple gateway assets then use the same asset IDs for their child assets (i.e. each edge gateway is a clone) then we can end up with conflicts and data leakage.
Extract from central instance showing the problem:
2025-12-24T08:33:59.293181750Z INFO [ContainerExecutor-22162 ] e.manager.gateway.GatewayService.GATEWAY : Creating/updating gateway service user for gateway id: 4H1sjYjbYMnvQRsJnkmcrs
2025-12-24T08:34:00.073044751Z INFO [ContainerExecutor-22162 ] e.manager.gateway.GatewayService.GATEWAY : Created gateway keycloak client for gateway id: 4H1sjYjbYMnvQRsJnkmcrs
2025-12-24T08:35:55.508580909Z INFO [ContainerExecutor-22180 ] manager.gateway.GatewayConnector.GATEWAY : Connected: GatewayID=4H1sjYjbYMnvQRsJnkmcrs
2025-12-24T08:35:55.832116480Z INFO [ContainerExecutor-22178 ] manager.gateway.GatewayConnector.GATEWAY : Initial sync complete: 4H1sjYjbYMnvQRsJnkmcrs
2025-12-24T09:16:23.167451502Z INFO [ContainerExecutor-22281 ] e.manager.gateway.GatewayService.GATEWAY : Creating/updating gateway service user for gateway id: 4HQRYPyyW46j5pWoaKz0B3
2025-12-24T09:16:23.258911576Z INFO [ContainerExecutor-22281 ] e.manager.gateway.GatewayService.GATEWAY : Created gateway keycloak client for gateway id: 4HQRYPyyW46j5pWoaKz0B3
2025-12-24T09:17:03.634005174Z INFO [ContainerExecutor-22268 ] e.manager.gateway.GatewayService.GATEWAY : Creating/updating gateway service user for gateway id: 4HQRYPyyW46j5pWoaKz0B3
2025-12-24T09:17:03.698704377Z INFO [ContainerExecutor-22268 ] e.manager.gateway.GatewayService.GATEWAY : Created gateway keycloak client for gateway id: 4HQRYPyyW46j5pWoaKz0B3
2025-12-24T09:17:13.643846425Z INFO [ContainerExecutor-22266 ] manager.gateway.GatewayConnector.GATEWAY : Connected: GatewayID=4HQRYPyyW46j5pWoaKz0B3
2025-12-24T09:17:14.156086405Z INFO [ContainerExecutor-22257 ] manager.gateway.GatewayConnector.GATEWAY : Initial sync complete: 4HQRYPyyW46j5pWoaKz0B3
2025-12-24T09:19:35.183377962Z INFO [ContainerExecutor-22262 ] e.manager.gateway.GatewayService.GATEWAY : Creating/updating gateway service user for gateway id: 4H1sjYjbYMnvQRsJnkmcrs
2025-12-24T09:19:35.248706125Z INFO [ContainerExecutor-22262 ] e.manager.gateway.GatewayService.GATEWAY : Created gateway keycloak client for gateway id: 4H1sjYjbYMnvQRsJnkmcrs
2025-12-24T09:19:43.888879927Z INFO [ContainerExecutor-22257 ] e.manager.gateway.GatewayService.GATEWAY : Creating/updating gateway service user for gateway id: 4HQRYPyyW46j5pWoaKz0B3
2025-12-24T09:19:43.948538845Z INFO [ContainerExecutor-22257 ] e.manager.gateway.GatewayService.GATEWAY : Created gateway keycloak client for gateway id: 4HQRYPyyW46j5pWoaKz0B3
2025-12-24T09:19:46.405306404Z INFO [ContainerExecutor-22257 ] e.manager.gateway.GatewayService.GATEWAY : Creating/updating gateway service user for gateway id: 4HQRYPyyW46j5pWoaKz0B3
2025-12-24T09:19:46.454629008Z INFO [ContainerExecutor-22257 ] e.manager.gateway.GatewayService.GATEWAY : Created gateway keycloak client for gateway id: 4HQRYPyyW46j5pWoaKz0B3
2025-12-24T09:19:53.878740418Z INFO [ContainerExecutor-22269 ] manager.gateway.GatewayConnector.GATEWAY : Connected: GatewayID=4HQRYPyyW46j5pWoaKz0B3
2025-12-24T09:19:54.314304130Z INFO [ContainerExecutor-22266 ] manager.gateway.GatewayConnector.GATEWAY : Initial sync complete: 4HQRYPyyW46j5pWoaKz0B3
2026-01-08T03:42:45.077074034Z INFO [ContainerExecutor-81480 ] manager.gateway.GatewayConnector.GATEWAY : Connected: GatewayID=4HQRYPyyW46j5pWoaKz0B3
2026-01-08T03:42:45.369879882Z INFO [ContainerExecutor-81501 ] manager.gateway.GatewayConnector.GATEWAY : Initial sync complete: 4HQRYPyyW46j5pWoaKz0B3
Some potential ideas:
- Prevent gateway asset creation with first 2 characters matching - When creating a gateway asset perform a check to ensure another gateway doesn't already exist with the same first two characters as edge gateways often use cloned deployments so descendant assets have the same local IDs and quickly the 2 character mapping can be problematic
- Use a more complex algorithm for the mapping - include the creation timestamp of the gateway in the mapping calculation for more variability; would need a robust way to know when to use the old existing algorithm or the new one
- Prevent gateway asset sync when there are conflicting asset IDs - This seems more of a bug and the mapping function is not cross validating the source edge gateway and the destination gateway asset
Metadata
Metadata
Assignees
Labels
BugError or issue in the systemError or issue in the systemGatewaysTopic Gateways: all features related to gateway featuresTopic Gateways: all features related to gateway features
Activity
[-]Prevent gateway descendat asset data leakage[/-][+]Prevent gateway descendant asset data leakage[/+]ebariaux commentedon May 18, 2026
Take migration into account, don't want to loose history for assets in central manager
wborn commentedon Nov 3, 2026
Before implementing this issue, I'd like agreement on whether V2 should apply only to new gateway registrations, also to newly synchronized assets on existing gateways, or to existing assets through an explicit migration.
The two gateway IDs in this report both start with
4H, so every shared edge asset ID maps to the same central ID under V1.For V2, I suggest position-by-position addition of the Base62 alphabet indices of the corresponding gateway ID and edge asset ID characters, modulo 62, with subtraction providing the inverse. The alphabet order could remain
abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.This preserves the 22-character ID format and guarantees distinct results for identical edge asset IDs on different V2 gateways. Ownership validation would remain necessary because different gateway/edge-ID combinations can still collide.
1. Common requirements
Whichever approach we choose, gateway operations should validate persisted ownership when the central manager applies the change.
This should cover initial synchronization, live asset updates, attribute writes, and deletions. Existing targets must belong to the authenticated gateway, and destination parents must remain within its permitted subtree.
Ownership checks should run inside the existing asset locks and transactions. Failed or incomplete synchronization must stop before obsolete-asset cleanup. Outbound routing and cleanup must use the same mapping rules as incoming operations.
Mapping information must also be managed centrally and preserved across ordinary updates, reconnects, and restarts.
For already-affected installations, the current parent may reflect an earlier incorrect reassignment. Contested ownership and historical data would need investigation before either gateway resumes synchronization.
2. Overview of the options
All three approaches would use V2 for new gateway registrations.
3. Option 1 — Keep existing gateways on V1 and use V2 for new gateways
Store an immutable mapping version on each locally registered gateway. Existing registrations without a version continue using V1. Normal provisioning of a new registration assigns and persists V2 before synchronization.
Logical imports and recreation would need explicit handling so an old registration is restored with the version its existing IDs depend on.
Advantages
Disadvantages
Later migration
An existing gateway could later be migrated explicitly to V2 using the procedure described below. That operation would retain the gateway registration and edge IDs while rekeying its central descendants and updating their history and references.
Migrating individual descendants would require introducing support for mixed mappings, as described in option 2. A gateway with no central data or references worth preserving could instead be replaced with a fresh V2 registration.
4. Option 2 — Preserve existing V1 assets and use V2 for newly synchronized assets
Keep established central IDs and use V2 whenever an asset is first accepted centrally after the cutover.
Here, “new” means newly represented in the central manager. An asset created earlier on an offline gateway could still receive V2 when it is first synchronized.
This requires durable information identifying which mapping applies to each asset. Possible representations include:
A timestamp could identify the cutover, but imports, recreation, and ordinary synchronization would still need to preserve the established mapping choice.
Advantages
Disadvantages
That last point requires more than checking gateway ownership. It is possible for
V1(edgeA)andV2(edgeB)to produce the same central ID. The resolver must verify the exact association and prevent a new V2 allocation from taking an ID already bound or reserved for another asset.This approach could also help an affected gateway whose cloned asset has no verified central representation of its own. It could receive a V2 representation while the verified existing owner keeps the V1 ID. Already mixed history would still require separate investigation.
Later migration
Selected V1 assets could be explicitly migrated to V2-derived IDs. That would still require updating their history and references, but the scope could be limited to one asset or subtree.
Migrating a V1 parent would also require updating the parent references and paths of children that retain their own V1 IDs. References from assets outside the selected subtree must be considered too.
The stored version or binding would change only after the rewrite had been validated. Once all retained V1 bindings for a gateway had been migrated, that gateway could operate entirely with V2.
5. Option 3 — Fully migrate existing gateways and assets to V2
Recalculate the central IDs of existing gateway descendants using V2 and update the associated database records and known references.
For a verified V1 asset, the manager can reverse V1 to recover its edge ID, then apply V2 using the same gateway ID.
Advantages
Disadvantages
ltreepaths, permissions, asset rulesets, alarm associations, historical and predicted datapoints, attributes, and dashboards.Groovy rules are a concrete compatibility concern. OpenRemote's own
ChildAssetControl.groovycontains a hardcoded asset ID used in anAssetQuery. Scripts may also construct IDs dynamically, so a generic migration cannot reliably discover and rewrite every reference. External clients may retain IDs outside the database. Example Groovy ruleTimescaleDB adds a potential operational cost. Historical datapoints use
entity_idas a columnstore segmentation key. Updates to compressed data are supported, but rekeying extensive history could involve substantial rewriting and database load. This needs benchmarking against representative compressed datasets before deciding whether full migration is suitable for an upgrade.6. Requirements whenever existing IDs are migrated
Options 1 and 2 can defer rekeying existing assets. Whenever that migration is performed, the same underlying requirements apply.
I would make it an explicit administrative operation with the following stages.
Merely changing a version attribute would cause the manager to interpret existing IDs differently and could lead cleanup to classify valid descendants as obsolete.
For option 2, the operation could cover a selected asset or subtree. For option 1, it would normally cover the entire gateway. Option 3 makes this operation part of the initial rollout for existing installations.
7. Decisions to agree on
The main questions seem to be:
richturner commentedon Nov 3, 2026
I think Option 1 and V2 should only ever apply to newly created gateways, I suggest looking at the creation time of the gateway asset to decide whether to use V1 or V2.
wborn commentedon Nov 5, 2026
I looked into this a bit further. OpenRemote tracks database migrations through Flyway and exposes the current application version, but doesn't seem to persist when a particular application version was first deployed. We'd therefore need some additional persistent state to establish a reliable installation-specific cutoff timestamp.
Since we only want V2 for newly created gateways, could we instead assign a mapping version when a gateway asset is first persisted? Existing gateways without a mapping version would default to V1, while newly created gateways would receive V2. This should work without a Flyway migration or any timestamp comparison, provided we preserve the mapping version across updates and imports.
richturner commentedon Nov 5, 2026
The only issue I see with a mapping version attribute is it could be modified which it shouldn't.
Persisting the timestamp when an instance is migrated to specific versions could solve this, maybe we introduce a new table to track version history?
Prevent cross-gateway asset data leakage
Prevent cross-gateway asset data leakage
wborn commentedon Nov 5, 2026
I gave this approach a try in #3547.