Configuration Management
thin-edge.io implements an operation to manage device configuration files.
- The tedge-agent enables configuration management on its running device and, combined with a cloud mapper, extends this capability to enable configuration management from the cloud.
- This management is bi-directional:
- A device can act as a reference, with all the managed files being uploaded to the tedge file transfer repository and stored there as a configuration snapshot.
- A configuration update can be pushed from the tedge file transfer repository to any devices of the same type, i.e. supporting the same kind of configuration files.
- On each device running the agent, the device owner defines the list of files to be managed (usually configuration files, but not necessarily).
- The configuration of this feature itself can be managed both locally and from the cloud, meaning, the device owner can update the list of files to be managed from the cloud using the cloud mapper.
- The configuration files are managed according to their type, a name chosen by the device owner to categorize each configuration. By default, the full path of a configuration file on the device is used as its type.
- When files are downloaded from the tedge file transfer repository to the target device, these files are stored in the target path with a temporary name first. They are atomically renamed, only after a fully successful download to avoid breaking the system with half-downloaded files.
- When a downloaded file is copied to its target, the Unix user, group and mode are preserved.
- Once an update has been downloaded from the tedge file transfer repository to the target device, the agent publishes an operation status update message on the local thin-edge.io MQTT bus. The device software must subscribe to these messages if any action is required, such as checking the content of the file, to pre-processing it, or restarting a daemon.
In summary, the responsibilities of the agent regarding configuration management are:
- to define the list of files under configuration management,
- to notify the local MQTT bus when this list is updated,
- to upload these files to the tedge file transfer repository on demand,
- to download files pushed from the tedge file transfer repository,
- to delegate preparation, application, verification, and rollback of config updates to config plugins,
- to notify the device software when the configuration is updated.
By contrast, the agent is not responsible for:
- checking that the uploaded files are well-formed,
- restarting the configured processes (this is delegated to config plugins),
- establishing any direct connection to clouds.
A user-specific component installed on the device can implement more sophisticated configuration use-cases by:
- listening for configuration updates on the local thin-edge.io MQTT bus,
- restarting the appropriate processes when needed,
- declaring intermediate files as the managed files, to have the opportunity to check or update their content before moving them to the actual targets.
Configurationβ
The configuration file used by the agent for configuration management is stored by default
under /etc/tedge/plugins/tedge-configuration-plugin.toml.
The file-based config types defined in this file are handle by the built-in file plugin.
This TOML file defines the list of files to be managed by the agent. Each configuration file is defined by a record with:
- The full
pathto the file. - An optional configuration
type. If not provided, thepathis used astype. Thistypeis used to declare the supported configuration file and then to trigger operations on that file. All the configurationtypes are declared as the supported config list to the local MQTT bus on startup and on changes to theplugins/tedge-configuration-plugin.tomlfile. - Optional
servicename. When specified, the agent will restart that service after successfully applying a configuration update. For restarts, the servicerestartcommand defined in thesystem.tomlis used. The specifiedservicename is passed as the argument to therestartcommand. - Optional unix file ownership:
user,groupand octalmode. These are only used when a configuration file pushed via aconfig_updatecommand doesn't exist on the device, and a new one is created with these ownership parameters. When a configuration file is already present on the device, the agent preserves its existing ownership, ignoring these parameters. - Optional unix directory ownership of the immediate parent of the file:
parent_user,parent_groupand octalparent_mode. These parameters apply only when the configuration file and its parent directories do not already exist on the device. In such cases, the immediate parent directory is created with the specified ownership and mode. Any missing directories above the immediate parent are created using the current user and group. If the fileβsuseris specified butparent_useris not,parent_userwill default to the value ofuser. Similarly, if the fileβsgroupis specified butparent_groupis not,parent_groupwill default to the value ofgroup. If the parent directories already exist, the agent preserves their existing ownership and ignores these parameters.
files = [
{ path = '/etc/tedge/tedge.toml', type = 'tedge.toml' },
{ path = '/etc/tedge/mosquitto-conf/c8y-bridge.conf', type = 'c8y-bridge' },
{ path = '/etc/tedge/mosquitto-conf/tedge-mosquitto.conf', type = 'tedge-mosquitto' },
{ path = '/etc/collectd/collectd.conf', type = 'collectd-conf', service = 'collectd' },
{ path = '/etc/mosquitto/mosquitto.conf', type = 'mosquitto', user = 'mosquitto', group = 'mosquitto', mode = 0o644 },
{ path = '/etc/containers/certs.d/example/ca.crt', type = 'harbor-certificate', user = 'tedge', group = 'tedge', mode = 0o640, parent_user = 'root', parent_group = 'root', parent_mode = 0o755 },
]
On start and whenever this file is updated, the agent sends
the supported config types declaration message with a retained flag
to the config_snapshot and config_update command topics
with the set of types listed in that configuration file
(implicitly adding the tedge-configuration-plugin type also to that set).
The message can be observed over the MQTT bus of the thin-edge.io device.
Given that mqtt.topic_root and mqtt.device_topic_id are set to te and device/main// for the main device,
the message to declare the supported configuration types is as follows.
- tedge
- mosquitto
- mqtt
tedge mqtt pub -r 'te/device/main///cmd/config_snapshot' '{
"types": [
"tedge-configuration-plugin",
"tedge.toml",
"/etc/tedge/mosquitto-conf/c8y-bridge.conf",
"/etc/tedge/mosquitto-conf/tedge-mosquitto.conf",
"mosquitto"
]
}'
mosquitto_pub -r -t 'te/device/main///cmd/config_snapshot' -m '{
"types": [
"tedge-configuration-plugin",
"tedge.toml",
"/etc/tedge/mosquitto-conf/c8y-bridge.conf",
"/etc/tedge/mosquitto-conf/tedge-mosquitto.conf",
"mosquitto"
]
}'
te/device/main///cmd/config_snapshot
{
"types": [
"tedge-configuration-plugin",
"tedge.toml",
"/etc/tedge/mosquitto-conf/c8y-bridge.conf",
"/etc/tedge/mosquitto-conf/tedge-mosquitto.conf",
"mosquitto"
]
}
- tedge
- mosquitto
- mqtt
tedge mqtt pub -r 'te/device/main///cmd/config_update' '{
"types": [
"tedge-configuration-plugin",
"tedge.toml",
"/etc/tedge/mosquitto-conf/c8y-bridge.conf",
"/etc/tedge/mosquitto-conf/tedge-mosquitto.conf",
"mosquitto"
]
}'
mosquitto_pub -r -t 'te/device/main///cmd/config_update' -m '{
"types": [
"tedge-configuration-plugin",
"tedge.toml",
"/etc/tedge/mosquitto-conf/c8y-bridge.conf",
"/etc/tedge/mosquitto-conf/tedge-mosquitto.conf",
"mosquitto"
]
}'
te/device/main///cmd/config_update
{
"types": [
"tedge-configuration-plugin",
"tedge.toml",
"/etc/tedge/mosquitto-conf/c8y-bridge.conf",
"/etc/tedge/mosquitto-conf/tedge-mosquitto.conf",
"mosquitto"
]
}
- The file
/etc/tedge/plugins/tedge-configuration-plugin.tomlitself doesn't need to be listed. This is implied, so the list can always be configured. Thetypefor this self configuration file istedge-configuration-plugin. - If the file
/etc/tedge/plugins/tedge-configuration-plugin.tomlis not found, empty, ill-formed or not-readable then onlytedge-configuration-plugin.tomlis declared as a supported configuration type.
The behavior of the agent is also controlled by the configuration of thin-edge.io:
tedge config get mqtt.bind.address: the address of the local MQTT bus.tedge config get mqtt.bind.port: the TCP port of the local MQTT bus.tedge config get mqtt.topic_root: the root of the MQTT topic scheme to publish and subscribe.tedge config get mqtt.device_topic_id: the identifier of the MQTT topic scheme to publish and subscribe.
Config Pluginsβ
In addition to the file-based entries in tedge-configuration-plugin.toml,
configuration types can be provided by external plugins installed at /usr/share/tedge/config-plugins as well.
Each plugin is an executable that responds to list, get, prepare, set, verify, and rollback sub-commands.
When a plugin provides a type, the type name is published with a ::plugin-name suffix
to distinguish it from file-based types.
For example, a plugin named lighttpd advertising lighttpd.conf makes the agent to publish:
- tedge
- mosquitto
- mqtt
tedge mqtt pub -r 'te/device/main///cmd/config_snapshot' '{
"types": [
"tedge-configuration-plugin",
"tedge.toml",
"lighttpd.conf::lighttpd"
]
}'
mosquitto_pub -r -t 'te/device/main///cmd/config_snapshot' -m '{
"types": [
"tedge-configuration-plugin",
"tedge.toml",
"lighttpd.conf::lighttpd"
]
}'
te/device/main///cmd/config_snapshot
{
"types": [
"tedge-configuration-plugin",
"tedge.toml",
"lighttpd.conf::lighttpd"
]
}
The suffix is stripped before the type is passed to the plugin sub-commands.
See Configuration Management Plugins for details on authoring plugins.
Handling config snapshot commandsβ
During a config snapshot operation, the agent uploads a requested configuration file to the tedge file transfer repository.
The agent subscribes to config snapshot commands on the <root>/<identifier>/cmd/config_snapshot/+ MQTT topics.
For example, it subscribes to the following topic for the main device.
- tedge
- mosquitto
- mqtt
tedge mqtt sub 'te/device/main///cmd/config_snapshot/+'
mosquitto_sub -t 'te/device/main///cmd/config_snapshot/+'
te/device/main///cmd/config_snapshot/+
To start a new config snapshot with the ID "1234" on the device named "example", a component has to publish the following message over MQTT:
- tedge
- mosquitto
- mqtt
tedge mqtt pub -r 'te/device/main///cmd/config_snapshot/1234' '{
"status": "init",
"tedgeUrl": "http://127.0.0.1:8000/te/v1/files/example/config_snapshot/mosquitto-1234",
"type": "mosquitto"
}'
mosquitto_pub -r -t 'te/device/main///cmd/config_snapshot/1234' -m '{
"status": "init",
"tedgeUrl": "http://127.0.0.1:8000/te/v1/files/example/config_snapshot/mosquitto-1234",
"type": "mosquitto"
}'
te/device/main///cmd/config_snapshot/1234
{
"status": "init",
"tedgeUrl": "http://127.0.0.1:8000/te/v1/files/example/config_snapshot/mosquitto-1234",
"type": "mosquitto"
}
The tedgeUrl is an optional field. If the user does not provide the URL, the agent will create it, and the link will be added while the operation is being processed.
Upon receiving a configuration snapshot command, the agent performs the following actions:
- The agent uses the
typeinformation (mosquitto) to look up the target path from thetedge-configuration-plugin.tomlfile and retrieves the requested configuration content from the correspondingpath(/etc/mosquitto/mosquitto.conf). For a plugin-backed type such aslighttpd.conf::lighttpd, the agent calls the plugin'sgetcommand and captures its stdout as the snapshot content. - It then performs a
PUTrequest to thetedgeUrlspecified in the command's payload to upload the content.
Throughout the process, the agent updates the command status via MQTT by publishing a retained message
to the same <root>/<identifier>/cmd/config_snapshot/<id> topic where the command is received.
The payload contains all the received data along with the path information.
When the agent receives a new config snapshot command, it updates the status to executing.
After successfully uploading the file to the file transfer repository,
the agent updates the status to successful.
If any unexpected error occurs, the agent updates the status to failed,
providing a comprehensive reason for the failure.
As a result, the operation status update message for the example above looks like this:
- tedge
- mosquitto
- mqtt
tedge mqtt pub -r 'te/device/main///cmd/config_snapshot/1234' '{
"status": "successful",
"tedgeUrl": "http://127.0.0.1:8000/te/v1/files/example/config_snapshot/mosquitto-1234",
"type": "mosquitto",
"path": "/etc/mosquitto/mosquitto.conf"
}'
mosquitto_pub -r -t 'te/device/main///cmd/config_snapshot/1234' -m '{
"status": "successful",
"tedgeUrl": "http://127.0.0.1:8000/te/v1/files/example/config_snapshot/mosquitto-1234",
"type": "mosquitto",
"path": "/etc/mosquitto/mosquitto.conf"
}'
te/device/main///cmd/config_snapshot/1234
{
"status": "successful",
"tedgeUrl": "http://127.0.0.1:8000/te/v1/files/example/config_snapshot/mosquitto-1234",
"type": "mosquitto",
"path": "/etc/mosquitto/mosquitto.conf"
}
Flowβ
Handling config update commandsβ
During a config update operation, the agent downloads a requested configuration file from the tedge file transfer repository and moves it to the target path.
The agent subscribes to config update commands on the <root>/<identifier>/cmd/config_update/+ MQTT topics.
For example, it subscribes to the following topic for the main device.
- tedge
- mosquitto
- mqtt
tedge mqtt sub 'te/device/main///cmd/config_update/+'
mosquitto_sub -t 'te/device/main///cmd/config_update/+'
te/device/main///cmd/config_update/+
To start a new config update with the ID "1234" on the device named "example", a component has to publish the following message over MQTT:
- tedge
- mosquitto
- mqtt
tedge mqtt pub -r 'te/device/main///cmd/config_update/1234' '{
"status": "init",
"tedgeUrl": "http://127.0.0.1:8000/te/v1/files/example/config_update/mosquitto-1234",
"remoteUrl": "http://www.my.url",
"type": "mosquitto"
}'
mosquitto_pub -r -t 'te/device/main///cmd/config_update/1234' -m '{
"status": "init",
"tedgeUrl": "http://127.0.0.1:8000/te/v1/files/example/config_update/mosquitto-1234",
"remoteUrl": "http://www.my.url",
"type": "mosquitto"
}'
te/device/main///cmd/config_update/1234
{
"status": "init",
"tedgeUrl": "http://127.0.0.1:8000/te/v1/files/example/config_update/mosquitto-1234",
"remoteUrl": "http://www.my.url",
"type": "mosquitto"
}
Upon receiving a configuration update command,
the agent executes the config_update workflow as defined in /etc/tedge/operations/config_update.toml,
which performs the following actions in sequence:
download: The agent downloads the new configuration file from the URL in the command payload using the built-indownloadaction. The path of the downloaded file is stored asdownloadedPathin the operation payload for subsequent steps.prepare: The agent creates a temporary work directory to be passed as--work-dirto subsequent plugin commands and calls the plugin'spreparecommand (builtin:config_update:prepare). The plugin may perform steps like validating the new configuration or save a backup of the current configuration to the work directory.set: The agent calls the plugin'ssetcommand (builtin:config_update:set) to apply the new configuration. If this step fails, the workflow proceeds torollback.evaluate-agent-restart: β If"restartAgent": truewas set in the command payload, the agent proceeds to therestart-agentstate or else proceed directly toverify.restart-agent: The agent triggers a self-restart and immediately proceeds toawait-agent-restartstate.await-agent-restart: Verify whether the restart succeeded.verify: The agent calls the plugin'sverifycommand (builtin:config_update:verify) to confirm the update was applied correctly. On success, work directory is deleted and proceed tosuccessfulstate. On failure, the workflow proceeds torollback.rollback(on error): The agent calls the plugin'srollbackcommand (builtin:config_update:rollback) to restore the previous configuration. Irrespective of the success or failure of this step, proceed to thefailedstate, after deleing the work directory.
For file-based config types defined in tedge-configuration-plugin.toml,
the built-in file plugin handles all plugin commands.
Throughout the process, the agent updates the command status via MQTT
by publishing a retained message to the same <root>/<identifier>/cmd/config_update/<id> topic
where the command is received.
The payload contains all the received data along with the path information.
Upon receiving a new config update command, the agent updates the status to executing.
After successfully completing all operation steps, the agent updates the status to successful.
If any unexpected error occurs,
the agent updates the status to failed along with a comprehensive reason for the failure.
As a result, the operation status update message for the example above looks like this.
- tedge
- mosquitto
- mqtt
tedge mqtt pub -r 'te/device/main///cmd/config_update/1234' '{
"status": "successful",
"tedgeUrl": "http://127.0.0.1:8000/te/v1/files/example/config_update/mosquitto-1234",
"remoteUrl": "http://www.my.url",
"type": "mosquitto",
"path": "/etc/mosquitto/mosquitto.conf"
}'
mosquitto_pub -r -t 'te/device/main///cmd/config_update/1234' -m '{
"status": "successful",
"tedgeUrl": "http://127.0.0.1:8000/te/v1/files/example/config_update/mosquitto-1234",
"remoteUrl": "http://www.my.url",
"type": "mosquitto",
"path": "/etc/mosquitto/mosquitto.conf"
}'
te/device/main///cmd/config_update/1234
{
"status": "successful",
"tedgeUrl": "http://127.0.0.1:8000/te/v1/files/example/config_update/mosquitto-1234",
"remoteUrl": "http://www.my.url",
"type": "mosquitto",
"path": "/etc/mosquitto/mosquitto.conf"
}
Flowβ
Refresh Supported Config Typesβ
To ensure that any newly installed services or configuration sources are immediately available for configuration management,
tedge-agent automatically reloads the plugins and refreshes the supported config types on the following events:
- A new config plugin is installed in the plugin directory (
/usr/share/tedge/config-plugins) - The
tedge-config-plugin.tomlfile is updated - A new software is installed with the agent (via the
software_updatecommand)
A refresh can also be triggered manually by sending sync signals to the agent as follows:
tedge mqtt pub te/device/main/service/tedge-agent/signal/sync_config '{}'
The agent reacts to all these events by gathering the latest supported config types from all the installed plugins
by invoking the list command on them,
and publishes the aggregated types to the te/device/main///cmd/config_snapshot and te/device/main///cmd/config_update meta topics.