Configuration

This chapter describes the configuration format and usage of Sylvia-IoT.

Sylvia-IoT supports four sources of configuration, prioritized as follows (from highest to lowest):

  • JSON5 configuration file
  • Command-line parameters
  • Environment variables
  • Internal default values (may not exist; if required but not provided, an error message will be displayed)

You can refer to the sample JSON5 file for a complete list of configuration options. This chapter will provide corresponding explanations. The following conventions apply to the configuration:

  • The nested structure in JSON5 is represented using . (dot).
  • For command-line parameters that encounter nested JSON5, the dot notation is also used.
  • For command-line parameters corresponding to camelCase JSON5 properties, they will be written in all lowercase or with - followed by lowercase. For example:
    • JSON5 property server.httpPort corresponds to --server.httpport.
    • JSON5 property broker.mqChannels corresponds to --broker.mq-channels.
  • Environment variables are written in all uppercase.
  • For environment variables that encounter nested JSON5, _ (underscore) is used.
  • For environment variables corresponding to camelCase JSON5 properties, they will be written in all uppercase or with _ (underscore) separating words. For example:
    • JSON5 property server.httpPort corresponds to SERVER_HTTP_PORT.
    • JSON5 property broker.mqChannels corresponds to BROKER_MQCHANNELS.

Here are the complete table explanations:

If marked with Refer to example, it means that the sample JSON5 is provided or you can use the CLI help command to view the supported options.

Common Settings

JSON5CLI ParametersEnvironment VariablesDefaultDescription
log.levellog.levelLOG_LEVELinfoLog level. Refer to example
log.stylelog.styleLOG_STYLEjsonLog style. Refer to example
server.httpPortlog.httpportSERVER_HTTP_PORT1080HTTP listening port
server.httpsPortlog.httpsportSERVER_HTTPS_PORT1443HTTPS listening port
server.cacertFilelog.cacertfileSERVER_CACERT_FILEHTTPS root certificate file location
server.certFilelog.certfileSERVER_CERT_FILEHTTPS certificate file location
server.keyFilelog.keyfileSERVER_KEY_FILEHTTPS private key file location
server.staticPathlog.staticSERVER_STATIC_PATHStatic files directory location

Detailed Explanation

  • Root certificate is not currently used.
  • Both certificate and private key must be used simultaneously to enable HTTPS service.

API Scopes

All APIs require access through registered clients and access tokens. Each token is associated with a specific client, and only authorized clients can access the APIs.

When a particular API is configured with apiScopes settings, the access token must include the relevant scopes enabled by the client during registration and authorized by the user to access that API.

Both command-line parameters and environment variables should be provided as JSON strings. For example:

--auth.api-scopes='{"auth.tokeninfo.get":[]}'

You can define custom scope names and apply them to various API scopes. You can refer to the example provided in the Authentication Service section for more details.

Authentication Service (auth)

JSON5CLI ParametersEnvironment VariablesDefaultDescription
auth.db.engineauth.db.engineAUTH_DB_ENGINEsqliteDatabase type
auth.db.mongodb.urlauth.db.mongodb.urlAUTH_DB_MONGODB_URLmongodb://localhost:27017MongoDB connection URL
auth.db.mongodb.databaseauth.db.mongodb.databaseAUTH_DB_MONGODB_DATABASEauthMongoDB database name
auth.db.mongodb.poolSizeauth.db.mongodb.poolsizeAUTH_DB_MONGODB_POOLSIZEMaximum number of MongoDB connections
auth.db.sqlite.pathauth.db.sqlite.pathAUTH_DB_SQLITE_PATHauth.dbSQLite file location
auth.db.templates.loginauth.db.templatesAUTH_TEMPLATESLogin page template file location
auth.db.templates.grantauth.db.templatesAUTH_TEMPLATESAuthorization page template file location
auth.db.apiScopesauth.api-scopesAUTH_API_SCOPESAPI scope settings

Detailed Explanation

  • Templates:
    • These are the web pages required for the OAuth2 authorization code grant flow. sylvia-iot-auth provides default pages, but Sylvia-IoT allows you to customize web pages to match your own style.
    • The templates use the Jinja2 format (dependent on the tera package).
    • Both command-line parameters and environment variables should use JSON strings. For example:
      --auth.templates='{"login":"xxx"}'
      
    • For more details, please refer to OAuth2 Authentication.
  • API scopes
    • The auth module provides the following scopes that can be configured for corresponding APIs to limit the scope of access for clients:
      • auth.tokeninfo.get: Authorize clients to read token data.
        • GET /api/v1/auth/tokeninfo
      • auth.logout.post: Authorize clients to log out tokens.
        • POST /auth/api/v1/auth/logout
      • user.get: Authorize clients to access current user's profile data.
        • GET /api/v1/user
      • user.path: Authorize clients to modify current user's profile data.
        • PATCH /api/v1/user
      • user.get.admin: Authorize clients to access data of all system users.
        • GET /api/v1/user/count
        • GET /api/v1/user/list
        • GET /api/v1/user/{userId}
      • user.post.admin: Authorize clients to create new users in the system.
        • POST /api/v1/user
      • user.patch.admin: Authorize clients to modify data of any system user.
        • PATCH /api/v1/user/{userId}
      • user.delete.admin: Authorize clients to delete data of any system user.
        • DELETE /api/v1/user/{userId}
      • client.get: Authorize clients to access data of all system clients.
        • GET /api/v1/client/count
        • GET /api/v1/client/list
        • GET /api/v1/client/{clientId}
      • client.post: Authorize clients to create new clients in the system.
        • POST /api/v1/client
      • client.patch: Authorize clients to modify data of any system client.
        • PATCH /api/v1/client/{clientId}
      • client.delete: Authorize clients to delete data of any system client.
        • DELETE /api/v1/client/{clientId}
      • client.delete.user: Authorize clients to delete all clients of any system user.
        • DELETE /api/v1/client/user/{userId}
    • For example, in your service, you define the following scopes:
      • api.admin: Only authorize the removal of all clients of a user.
      • api.rw: Allow read and write access to all APIs except DELETE /api/v1/client/user/{userId}.
      • api.readonly: Only allow access to GET APIs.
      • Allow access to token data and log out actions for all clients.
      "auth": {
          ...
          "apiScopes": {
              "auth.tokeninfo.get": [],
              "auth.logout.post": [],
              "user.get": ["api.rw", "api.readonly"],
              "user.patch": ["api.rw"],
              "user.post.admin": ["api.rw"],
              "user.get.admin": ["api.rw", "api.readonly"],
              "user.patch.admin": ["api.rw"],
              "user.delete.admin": ["api.rw"],
              "client.post": ["api.rw"],
              "client.get": ["api.rw", "api.readonly"],
              "client.patch": ["api.rw"],
              "client.delete": ["api.rw"],
              "client.delete.user": ["api.admin"],
          },
          ...
      }
      
      • In this example, registered clients can freely select these three scopes. Subsequently, users will be informed of this information on the authorization page and decide whether to grant authorization to the client.

Message Broker Service (broker)

JSON5CLI ParametersEnvironment VariablesDefaultDescription
broker.authbroker.authBROKER_AUTHhttp://localhost:1080/authAuthentication service URL
broker.db.enginebroker.db.engineBROKER_DB_ENGINEsqliteDatabase type
broker.db.mongodb.urlbroker.db.mongodb.urlBROKER_DB_MONGODB_URLmongodb://localhost:27017MongoDB connection URL
broker.db.mongodb.databasebroker.db.mongodb.databaseBROKER_DB_MONGODB_DATABASEauthMongoDB database name
broker.db.mongodb.poolSizebroker.db.mongodb.poolsizeBROKER_DB_MONGODB_POOLSIZEMaximum number of MongoDB connections
broker.db.sqlite.pathbroker.db.sqlite.pathBROKER_DB_SQLITE_PATHauth.dbSQLite file location
broker.cache.enginebroker.cache.engineBROKER_CACHE_ENGINEnoneCache type
broker.cache.memory.devicebroker.cache.memory.deviceBROKER_CACHE_MEMORY_DEVICE1,000,000Memory cache size for devices
broker.cache.memory.deviceRoutebroker.cache.memory.device-routeBROKER_CACHE_MEMORY_DEVICE_ROUTE1,000,000Memory cache size for device routes
broker.cache.memory.networkRoutebroker.cache.memory.network-routeBROKER_CACHE_MEMORY_NETWORK_ROUTE1,000,000Memory cache size for network routes
broker.mq.prefetchbroker.mq.prefetchBROKER_MQ_PREFETCH100Maximum number of AMQP consumers
broker.mq.persistentbroker.mq.persistentBROKER_MQ_PERSISTENTfalsePersistent message delivery for AMQP producers
broker.mq.sharedPrefixbroker.mq.sharedprefixBROKER_MQ_SHAREDPREFIX$share/sylvia-iot-broker/MQTT shared subscription prefix
broker.mqChannels.unit.urlbroker.mq-channels.unit.urlBROKER_MQCHANNELS_UNIT_URLamqp://localhostUnit control message host
broker.mqChannels.unit.prefetchbroker.mq-channels.unit.prefetchBROKER_MQCHANNELS_UNIT_PREFETCH100Maximum number of AMQP consumers for unit control messages
broker.mqChannels.application.urlbroker.mq-channels.application.urlBROKER_MQCHANNELS_APPLICATION_URLamqp://localhostApplication control message host
broker.mqChannels.application.prefetchbroker.mq-channels.application.prefetchBROKER_MQCHANNELS_APPLICATION_PREFETCH100Maximum number of AMQP consumers for application control messages
broker.mqChannels.network.urlbroker.mq-channels.network.urlBROKER_MQCHANNELS_NETWORK_URLamqp://localhostNetwork control message host
broker.mqChannels.network.prefetchbroker.mq-channels.network.prefetchBROKER_MQCHANNELS_NETWORK_PREFETCH100Maximum number of AMQP consumers for network control messages
broker.mqChannels.device.urlbroker.mq-channels.device.urlBROKER_MQCHANNELS_DEVICE_URLamqp://localhostDevice control message host
broker.mqChannels.device.prefetchbroker.mq-channels.device.prefetchBROKER_MQCHANNELS_DEVICE_PREFETCH100Maximum number of AMQP consumers for device control messages
broker.mqChannels.deviceRoute.urlbroker.mq-channels.device-route.urlBROKER_MQCHANNELS_DEVICE_ROUTE_URLamqp://localhostDevice route control message host
broker.mqChannels.deviceRoute.prefetchbroker.mq-channels.device-route.prefetchBROKER_MQCHANNELS_DEVICE_ROUTE_PREFETCH100Maximum number of AMQP consumers for device route control messages
broker.mqChannels.networkRoute.urlbroker.mq-channels.network-route.urlBROKER_MQCHANNELS_NETWORK_ROUTE_URLamqp://localhostNetwork route control message host
broker.mqChannels.networkRoute.prefetchbroker.mq-channels.network-route.prefetchBROKER_MQCHANNELS_NETWORK_ROUTE_PREFETCH100Maximum number of AMQP consumers for network route control messages
broker.mqChannels.data.urlbroker.mq-channels.data.urlBROKER_MQCHANNELS_DATA_URLData message host
broker.mqChannels.data.persistentbroker.mq-channels.data.persistentBROKER_MQCHANNELS_DATA_PERSISTENTfalsePersistent delivery for data messages
broker.db.apiScopesbroker.api-scopesBROKER_API_SCOPESAPI scope settings

Detailed Explanation

  • The purpose of specifying the Authentication Service URL (broker.auth) is to verify the legitimacy of API calls, including user accounts and clients.

  • MQ channels:

    • As the Sylvia-IoT Message Broker Service is a critical module that determines performance, many configurations are stored in memory. These configurations need to be propagated to various instances of the cluster through Control Channel Messages via message queues when API changes are made.
      • For relevant details, please refer to the Cache chapter.
    • data represents the Data Channel Message, which records all data into the sylvia-iot-data module.
      • If no parameters are specified (or JSON5 is set to null), no data will be stored.
      • For relevant details, please refer to the Data Flow chapter.
  • API scopes: Please refer to the explanation in the Authentication Service section.

Core Manager Service (coremgr)

JSON5CLI ParametersEnvironment VariablesDefaultDescription
coremgr.authcoremgr.authCOREMGR_AUTHhttp://localhost:1080/authAuthentication service URL
coremgr.brokercoremgr.brokerCOREMGR_BROKERhttp://localhost:2080/brokerMessage broker service URL
coremgr.mq.engine.amqpcoremgr.mq.engine.amqpCOREMGR_MQ_ENGINE_AMQPrabbitmqAMQP type
coremgr.mq.engine.mqttcoremgr.mq.engine.mqttCOREMGR_MQ_ENGINE_MQTTemqxMQTT type
coremgr.mq.rabbitmq.usernamecoremgr.mq.rabbitmq.usernameCOREMGR_MQ_RABBITMQ_USERNAMEguestRabbitMQ administrator account
coremgr.mq.rabbitmq.passwordcoremgr.mq.rabbitmq.passwordCOREMGR_MQ_RABBITMQ_PASSWORDguestRabbitMQ administrator password
coremgr.mq.rabbitmq.ttlcoremgr.mq.rabbitmq.ttlCOREMGR_MQ_RABBITMQ_TTLRabbitMQ default message TTL (seconds)
coremgr.mq.rabbitmq.lengthcoremgr.mq.rabbitmq.lengthCOREMGR_MQ_RABBITMQ_LENGTHRabbitMQ default maximum number of messages in queues
coremgr.mq.rabbitmq.hostscoremgr.mq.rabbitmq.hostsCOREMGR_MQ_RABBITMQ_HOSTS(Reserved)
coremgr.mq.emqx.apiKeycoremgr.mq.emqx.apikeyCOREMGR_MQ_EMQX_APIKEYEMQX management API key
coremgr.mq.emqx.apiSecretcoremgr.mq.emqx.apisecretCOREMGR_MQ_EMQX_APISECRETEMQX management API secret
coremgr.mq.emqx.hostscoremgr.mq.emqx.hostsCOREMGR_MQ_EMQX_HOSTS(Reserved)
coremgr.mq.rumqttd.mqttPortcoremgr.mq.rumqttd.mqtt-portCOREMGR_MQ_RUMQTTD_MQTT_PORT1883rumqttd MQTT port
coremgr.mq.rumqttd.mqttsPortcoremgr.mq.rumqttd.mqtts-portCOREMGR_MQ_RUMQTTD_MQTTS_PORT8883rumqttd MQTTS port
coremgr.mq.rumqttd.consolePortcoremgr.mq.rumqttd.console-portCOREMGR_MQ_RUMQTTD_CONSOLE_PORT18083rumqttd management API port
coremgr.mqChannels.data.urlcoremgr.mq-channels.data.urlCOREMGR_MQCHANNELS_DATA_URLData message host
coremgr.mqChannels.data.persistentcoremgr.mq-channels.data.persistentCOREMGR_MQCHANNELS_DATA_PERSISTENTfalsePersistent delivery for data messages

Detailed Explanation

  • MQ channels:
    • data represents the Data Channel Message.
      • Currently, coremgr supports recording HTTP request content for all API requests except GET. Enabling the data channel will record the API usage history.
      • If no parameters are specified (or JSON5 is set to null), no data will be stored.

Core Manager Command-Line Interface (coremgr-cli)

JSON5CLI ParametersEnvironment VariablesDefaultDescription
coremgrCli.authcoremgr-cli.authCOREMGRCLI_AUTHhttp://localhost:1080/authAuthentication service URL
coremgrCli.coremgrcoremgr-cli.coremgrCOREMGRCLI_COREMGRhttp://localhost:3080/coremgrCore manager service URL
coremgrCli.datacoremgr-cli.dataCOREMGRCLI_DATAhttp://localhost:4080/dataData service URL
coremgrCli.clientIdcoremgr-cli.client-idCOREMGRCLI_CLIENT_IDCLI client ID
coremgrCli.redirectUricoremgr-cli.redirect-uriCOREMGRCLI_REDIRECT_URICLI client redirect URI

Data Service (data)

JSON5CLI ParametersEnvironment VariablesDefaultDescription
data.authdata.authDATA_AUTHhttp://localhost:1080/authAuthentication service URL
data.brokerdata.brokerDATA_BROKERhttp://localhost:2080/brokerMessage broker service URL
data.db.enginedata.db.engineDATA_DB_ENGINEsqliteDatabase type
data.db.mongodb.urldata.db.mongodb.urlDATA_DB_MONGODB_URLmongodb://localhost:27017MongoDB connection URL
data.db.mongodb.databasedata.db.mongodb.databaseDATA_DB_MONGODB_DATABASEdataMongoDB database name
data.db.mongodb.poolSizedata.db.mongodb.poolsizeDATA_DB_MONGODB_POOLSIZEMaximum number of MongoDB connections
data.db.sqlite.pathdata.db.sqlite.pathDATA_DB_SQLITE_PATHdata.dbSQLite file location
data.mqChannels.broker.urldata.mq-channels.broker.urlDATA_MQCHANNELS_BROKER_URLamqp://localhostData message host
data.mqChannels.broker.prefetchdata.mq-channels.broker.prefetchDATA_MQCHANNELS_BROKER_PREFETCH100Maximum number of AMQP consumers for data messages
data.mqChannels.broker.sharedPrefixdata.mq-channels.broker.sharedprefixDATA_MQCHANNELS_BROKER_SHAREDPREFIX$share/sylvia-iot-data/MQTT shared subscription prefix
data.mqChannels.coremgr.urldata.mq-channels.coremgr.urlDATA_MQCHANNELS_COREMGR_URLamqp://localhostData message host
data.mqChannels.coremgr.prefetchdata.mq-channels.coremgr.prefetchDATA_MQCHANNELS_COREMGR_PREFETCH100Maximum number of AMQP consumers for data messages
data.mqChannels.coremgr.sharedPrefixdata.mq-channels.coremgr.sharedprefixDATA_MQCHANNELS_COREMGR_SHAREDPREFIX$share/sylvia-iot-data/MQTT shared subscription prefix