Skip to content

Commit 9a38ce9

Browse files
heiytorgustavosbarreto
authored andcommitted
fix(ssh): look for tenant in api when header is empty
In versions before 0.15, the agent's authentication may not provide the "X-Tenant-ID" header. This can cause issues with establishing sessions and tracking online devices. To solve this, we retrieve the tenant ID by querying the API.
1 parent e6331c7 commit 9a38ce9

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

ssh/pkg/tunnel/tunnel.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,23 @@ func NewTunnel(connection, dial string) *Tunnel {
3131
tenant := request.Header.Get("X-Tenant-ID")
3232
uid := request.Header.Get("X-Device-UID")
3333

34+
// WARN:
35+
// In versions before 0.15, the agent's authentication may not provide the "X-Tenant-ID" header.
36+
// This can cause issues with establishing sessions and tracking online devices. To solve this,
37+
// we retrieve the tenant ID by querying the API. Maybe this can be removed in a future release.
38+
if tenant == "" {
39+
device, err := tunnel.API.GetDevice(uid)
40+
if err != nil {
41+
log.WithError(err).
42+
WithField("uid", uid).
43+
Error("unable to retrieve device's tenant id")
44+
45+
return "", err
46+
}
47+
48+
tenant = device.TenantID
49+
}
50+
3451
return tenant + ":" + uid, nil
3552
}
3653
tunnel.Tunnel.CloseHandler = func(key string) {

0 commit comments

Comments
 (0)