thingsboard / thingsboard-gateway

Open-source IoT Gateway - integrates devices connected to legacy and third-party systems with ThingsBoard IoT Platform using Modbus, CAN bus, BACnet, BLE, OPC-UA, MQTT, ODBC and REST protocols
https://thingsboard.io/docs/iot-gateway/what-is-iot-gateway/
Apache License 2.0
1.76k stars 845 forks source link

[BUG] Connect to Thingsboard using X.509 certificates after general configuration update #1602

Closed andersenthomas98 closed 4 days ago

andersenthomas98 commented 4 days ago

Describe the bug I am using the following docker-compose.yaml file to run the gateway:

services:
  # ThingsBoard IoT Gateway Service Configuration
  tb-gateway:
    image: thingsboard/tb-gateway:3.5.3
    container_name: tb-gateway
    restart: always

    # Necessary mapping for Linux
    extra_hosts:
      - "host.docker.internal:host-gateway"

    # Environment variables
    environment:
      - TB_GW_HOST=mqtt.thingsboard.cloud
      - TB_GW_PORT=8883
      - TB_GW_CA_CERT=credentials/ca-root.pem
      - TB_GW_PRIVATE_KEY=credentials/key.pem
      - TB_GW_CERT=credentials/cert.pem

    # Volumes bind
    volumes:
      - ./credentials:/thingsboard_gateway/config/credentials
      - tb-gw-config:/thingsboard_gateway/config
      - tb-gw-logs:/thingsboard_gateway/logs
      - tb-gw-extensions:/thingsboard_gateway/extensions

# Volumes declaration for configurations, extensions and configuration
volumes:
  tb-gw-config:
    name: tb-gw-config
  tb-gw-logs:
    name: tb-gw-logs
  tb-gw-extensions:
    name: tb-gw-extensions

The gateway connected successfully to thingsboard cloud initially using X.509 certs. However, after applying a general configuration update (using the Thingsboard IoT Gateways), I am no longer able to connect to thingsboard cloud. From the logs I can also see that I am exceeding some rate limit. Do not know if that is related to this issue.

Error traceback (If available):

tb-gateway  | 2024-11-18 13:23:38 - |INFO| - [tb_client.py] - tb_client - connect - 313 - Connecting to ThingsBoard...
tb-gateway  | 2024-11-18 13:23:40 - |INFO| - [tb_client.py] - tb_client - connect - 313 - Connecting to ThingsBoard...
tb-gateway  | 2024-11-18 13:23:41 - |INFO| - [tb_device_mqtt.py] - tb_device_mqtt - _on_connect - 396 - MQTT client <paho.mqtt.client.Client object at 0x73b51da5f050> - Connected!
tb-gateway  | 2024-11-18 13:23:41 - |WARNING| - [tb_device_mqtt.py] - tb_device_mqtt - _wait_for_rate_limit_released - 720 - Rate limit reached for 1 seconds, waiting for rate limit to be released...
tb-gateway  | 2024-11-18 13:23:41 - |ERROR| - [tb_gateway_remote_configurator.py] - tb_gateway_remote_configurator - _process_config_request - 250 - Unknown attribute update name (Available: ['storage_configuration', 'grpc_configuration', 'logs_configuration', 'active_connectors', 'RemoteLoggingLevel', '(?=\\D*\\d?).*']), KeyError('commands')
tb-gateway  | 2024-11-18 13:23:41 - |INFO| - [tb_device_mqtt.py] - tb_device_mqtt - on_service_configuration - 683 - Service configuration was successfully retrieved and applied.
tb-gateway  | 2024-11-18 13:23:41 - |INFO| - [tb_device_mqtt.py] - tb_device_mqtt - on_service_configuration - 684 - Current limits: {'rateLimit': {'messages': '200:1,6000:60,20000:3600', 'telemetryMessages': '100:1,3000:60,14400:3600', 'telemetryDataPoints': '200:1,6000:60,20000:3600'}, 'maxPayloadSize': 65536, 'maxInflightMessages': 100}
tb-gateway  | 2024-11-18 13:23:41 - |INFO| - [tb_gateway_mqtt.py] - tb_gateway_mqtt - gw_subscribe_to_attribute - 255 - Subscribed to *|* with id 1 for device *
tb-gateway  | 2024-11-18 13:23:42 - |INFO| - [tb_gateway_service.py] - tb_gateway_service - __process_remote_logging_update - 669 - Remote logging has being deactivated.
tb-gateway  | 2024-11-18 13:23:42 - |INFO| - [tb_gateway_remote_configurator.py] - tb_gateway_remote_configurator - _process_config_request - 225 - Configuration update request received.
tb-gateway  | 2024-11-18 13:23:42 - |INFO| - [tb_gateway_mqtt.py] - tb_gateway_mqtt - gw_unsubscribe - 263 - Unsubscribed from *|*, subscription id '*'
tb-gateway  | 2024-11-18 13:23:42 - |WARNING| - [tb_device_mqtt.py] - tb_device_mqtt - _on_disconnect - 387 - MQTT client was disconnected with reason code 0 (The operation completed successfully.)
tb-gateway  | 2024-11-18 13:23:42 - |ERROR| - [tb_gateway_remote_configurator.py] - tb_gateway_remote_configurator - _apply_connection_config - 719 - 'accessToken'
tb-gateway  | Traceback (most recent call last):
tb-gateway  |   File "/thingsboard_gateway/tb_utility/tb_gateway_remote_configurator.py", line 696, in _apply_connection_config
tb-gateway  |     new_tb_client = TBClient(config if use_new_config else old_tb_client_config, old_tb_client_config_path, connection_logger)
tb-gateway  |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
tb-gateway  |   File "/thingsboard_gateway/gateway/tb_client.py", line 69, in __init__
tb-gateway  |     self._create_mqtt_client(config['security'])
tb-gateway  |   File "/thingsboard_gateway/gateway/tb_client.py", line 136, in _create_mqtt_client
tb-gateway  |     self.__username = str(credentials["accessToken"])
tb-gateway  |                           ~~~~~~~~~~~^^^^^^^^^^^^^^^
tb-gateway  | KeyError: 'accessToken'
tb-gateway  | 2024-11-18 13:23:42 - |WARNING| - [tb_gateway_remote_configurator.py] - tb_gateway_remote_configurator - _revert_connection - 725 - Remote general configuration will be restored.
tb-gateway  | 2024-11-18 13:23:42 - |INFO| - [tb_client.py] - tb_client - _check_certificates - 223 - Will generate new certificate

Versions (please complete the following information):

andersenthomas98 commented 4 days ago

Upgrading thingsboard gateway to version 3.6.1 seems to have solved the issue