com.limdm.files (list)¶
Console: Files.
{"files": [{"path": "/etc/motd", "content": "...", "mode": "0644", "owner": "root", "group": "root"}]}
| Field | Type | Rules |
|---|---|---|
files[].path |
text | absolute and clean, not /, not below /home, /tmp, /var/tmp, /run/user, /dev/shm, /var/mail or /var/spool |
files[].content |
text | the whole file |
files[].mode |
text | octal 0000 to 0777, default 0644; no setuid, setgid or sticky bits |
files[].owner |
text | user name, default root |
files[].group |
text | group name, default root |
files[].template |
true or false | render content per device (see Templates) |
Merged by path, a later item wins. Owner and group must exist on the device. Files removed from the declaration are deleted from the device: the agent remembers the paths it wrote (since 0.16) with the SHA-256 sum of their content and removes the undeclared ones, except while a files declaration is invalid. It removes a file only when it is still a regular file reached without symlinks and its content still matches the sum; a file someone changed, a link, or a file written by an agent before the sums existed is left in place and reported as kept.
On devices enrolled without allow_scripts (the opt in remote scripts need) only plain text
locations are accepted: /etc/motd, /etc/issue, /etc/issue.net, and files below
/etc/motd.d, /srv, /etc/opt and /var/opt. Everything else is refused, because almost
every other system path is read as code by something running as root (cron, systemd, sudo,
PAM, shell profiles, the dynamic linker, D-Bus, package manager hooks …). There the agent
also refuses files with an execute bit. With allow_scripts any allowed absolute path works.
On every device, with or without allow_scripts, a path with a symlink in any component,
the file itself included, is refused, so a local user who owns a parent directory cannot
redirect the write, owner change or removal (declare the real path, for example
/usr/bin/x instead of /bin/x on merged /usr systems). The agent opens each directory
from / with O_NOFOLLOW, writes a temporary file in the opened directory, sets mode and
owner on the open file and renames it in place, so swapping a directory for a link between
check and write has no effect.
Templates¶
With template set, the server renders content (files) or every rule text (firewall) for
each device with Go text/template before it sends the declaration, so the agent only ever
gets the result and the declarations token changes when a value changes. The values are:
| Value | Content |
|---|---|
{{.Hostname}} |
host name the device reported |
{{.ID}} |
device ID |
{{.Tags}} |
tags (list) |
{{.Tenant}} |
tenant name |
{{.PrimaryUser}} |
mail address of the primary user, empty without one |
{{.Attributes.name}} |
custom device attribute, set in the console under Edit on the device page or with PATCH /api/v1/devices/{id} (attributes) |
{{.Serial}} |
DMI system serial number the device reported, empty for a vendor placeholder |
{{.MAC}} |
MAC address of the primary interface (the interface of the default route) |
{{.Vendor}}, {{.Model}} |
hardware vendor and model the device reported |
Functions: lower, upper, trim, replace s old new, join list sep,
hasTag .Tags "x", default "fallback" value, plus the built in if, with, range,
eq, index, len, and, or, not. A missing attribute is an error; for an optional
one write {{default "none" (index .Attributes "site")}}. Nothing outside these values is
reachable: no files, commands or environment. define, block and template are refused
(recursion), range only works over .Tags or .Attributes, printf and call are not
available, and the output is limited to 1 MiB. The syntax is checked when the item is saved;
the editor shows a preview for one device (POST /api/v1/config/library/render).
When a template does not render for a device (a missing attribute, a firewall rule that is not valid afterwards), that file or the whole firewall declaration goes out still marked as template and the agent leaves the device as it is and reports the problem. A template file is never written with its raw template text.
Field reference¶
Generated from the payload schema of the server (GET /api/v1/schemas/{type}), the same reference the console editor shows. Unknown fields are rejected.
com.limdm.files¶
Console: Files. Files with fixed content, owner and mode.
| Field | Type | Meaning | Limits |
|---|---|---|---|
files |
list of object | Files | |
files[].path |
string | Path Absolute path of the file. | |
files[].content |
string | Content | |
files[].mode |
string | Mode Octal file mode, for example 0644. | |
files[].owner |
string | Owner User name, root when empty. | |
files[].group |
string | Group Group name, root when empty. | |
files[].template |
boolean | Template Render the content per device: {{.Hostname}}, {{.ID}}, {{.Tenant}}, {{.PrimaryUser}}, {{.Tags}}, {{.Attributes.name}}; check it with the preview. |