From a server to its declaration
Most servers were never written down: they were set up by hand, one
change at a time, and what they are exists only on the server. Lemano
reads that, and lemano state pull writes it as a declaration: one
readable document that names what defines the server, made from what was
read, with nothing for you to write first.
This guide shows the commands that read a server’s state, what they list
and what they only count, how the declaration is laid out, and how to keep
it in Git. It assumes a first lemano discover is done. All of it reads the
store: none of it connects to a server or changes one.
The declaration is read-only for now. Nothing reads it back and it changes no server; what it is for today is at the end.
What defines a server
A server holds thousands of objects, and most of them are the system’s own:
900 kernel parameters at their defaults, packages pulled in as
dependencies, files that match the package they came from. A list of all of
them hides the few that make the server what it is. So lemano state list
lists what defines the server and counts the rest:
$ lemano state list debian-12
KIND IDENTITY CONDITIONS NOTES
Package openssh-server - -
Package sudo - -
Service cron - -
Service kmod NeedsDaemonReload -
Service ssh - -
...
User lemano - -
User root - -
...
SudoRule /etc/sudoers.d/lemano PermitsAll -
...
File /etc/hostname - -
File /etc/hosts - -
File /etc/ssh/sshd_config - -
...
Cron /etc/cron.daily/dpkg - -
...
listed 93 of 1520 objects; 1427 counted (--all lists them):
Package 138 installed with the system, or only as dependencies of others
User 19 system accounts with no login shell and no password
Group 43 system groups without members
...
The kinds come in one fixed order, packages and services first, so that what a reader looks at first comes first. Each line under the table says how many objects of a kind were left out, and the rule that left them out. The rules are in State.
Counted is not forgotten. Everything stays recorded and compared: a change
in any object shows in lemano diff, and an object that differs from the
baseline, or that has a condition, is always listed, whatever its kind.
--all lists every object, and --kind and --flagged narrow the list:
$ lemano state list debian-12 --flagged
KIND IDENTITY CONDITIONS NOTES
Service kmod NeedsDaemonReload -
SudoRule /etc/sudoers.d/lemano PermitsAll -
lemano state list -A does the same for every server and adds a TARGET
column.
An object is named as lemano diff prints it, its kind and its identity:
Service/ssh, File//etc/hostname. lemano state show prints one object
as recorded, with every field the kind reads:
$ lemano state show debian-12 Service/ssh
# Service/ssh: generation 0 of debian-12
Service "ssh" {
activeState = "active"
after = [
"lemano-lab-hostkeys.service",
"systemd-pcrphase-sysinit.service",
]
fragmentPath = "/lib/systemd/system/ssh.service"
loadState = "loaded"
needsDaemonReload = false
restart = "on-failure"
triggeredBy = [
"ssh.socket",
]
type = "notify"
unitFileState = "enabled"
}
The declaration
lemano state pull writes the same objects as a declaration:
$ lemano state pull debian-12
# Declaration of the 83 of the 1520 objects read on debian-12 that define the
# server.
# The others are counted, not listed:
# Package 138: installed with the system, or only as dependencies of others
# Service 80: static, disabled or idle units that are not running, not failed
# and defined by the vendor
...
# lemano state pull debian-12 --all gives every object, as it was recorded.
apiVersion: lemano.dev/v1alpha1
kind: Spec
metadata:
name: debian-12
annotations:
lemano.dev/generated-from: debian-12, generation 0 (2026-11-24T21:57:44Z)
spec:
targets:
names: [debian-12]
resources:
- kind: Package
items:
- name: openssh-server
spec:
version: 1:9.2p1-2+deb12u10
- name: sudo
spec:
version: 1.9.13p3-1+deb12u4
- kind: Service
...
It has the shape of a Kubernetes object: apiVersion, kind, metadata
and a spec. It is YAML; -o json gives the same data as JSON, which has
no comments. It describes one generation, the latest unless -g names
another.
Its head is a comment that counts what was left out and why, the same
counts as state list, so the data below stays a declaration. It lists 83
objects where state list lists 93: the others are listed but cannot be
written as a resource. The rules a container engine creates for its own
networks and a sudoers file with nothing in it but comments are counted at
the head instead, each with its reason.
Groups, defaults and names
Under spec.resources there is one group for each kind. Writing every
service as a block of its own would repeat the same line a hundred times,
so a group says the conventional values of its kind once:
- kind: Service
defaults:
state: running
names:
- dbus
- systemd-journal-flush
- systemd-journald
- systemd-logind
items:
- name: cron
spec:
enabled: true
- name: console-getty
spec:
state: stopped
masked: true
- name: getty@
spec:
state: null
enabled: truedefaultshold the values the kind fixes as conventional, when at least one resource of the group has them. A file’s areowner: root,group: rootandmode: "0644"; a service’s isstate: running; a cron entry’s isuser: root; a firewall rule’s isbackend: nftables. The other kinds have none. The lists are fixed, not worked out from the server, so they are the same on every server.nameslists the resources that match the defaults exactly, and have nothing else to say.dbusis a running service and that is all.itemsare every other resource: itsname, and aspecwith only the fields that differ from the defaults.cronis running, as the default says, and enabled.console-gettyoverridesstate.nullremoves a default for one resource.getty@is a template unit that is never running or stopped, so itsstateisnull, and it has none.- A resource that is absent (
ensure: absent, a package’s file that is gone) takes no defaults and counts towards none: it is an item with a spec of its own.
Apply the defaults, then an item’s spec, and you get back that resource’s
own declaration, field for field. The values a file holds (content,
source) are never defaults, and neither is a kind’s own default value,
which is never written. The fields each kind writes are in
State.
A file group works the same way:
- kind: File
defaults:
owner: root
group: root
mode: "0644"
items:
- name: /etc/hostname
spec:
content: |
debian-12
- name: /etc/localtime
spec:
type: symlink
target: /usr/share/zoneinfo/Etc/UTC
mode: "0777"
# content not written: the file may hold secrets, it is not world-readable
- name: /etc/shadow
spec:
group: shadow
mode: "0640"What a comment says
A line that starts with # above a resource tells you something the data
cannot: why a part is missing, and, once you have accepted a baseline, what
changed since. Above /etc/shadow it says its content is not written. Above
a key in authorized_keys it says the key itself is not recorded, only its
fingerprint. A resource that changed since the baseline says in which
generation, and by whom when the host’s own logs record it:
# changed in generation 1, not attributed
- name: /etc/motdA resource with a comment is always an item, never only a name.
File content
A text file’s content is written under content as a literal block, when
the file may be shown: it is readable by every user, it is not binary, and
neither its name nor its content looks like it holds secrets. These are the
rules lemano diff follows, described in the security
model. Any other file is written
without content, and a comment says why. /etc/shadow, a private key and
the sudoers files never have content in a declaration.
A declaration of a real server is long if it holds the text of every file.
A file larger than --inline-limit (16384 bytes by default) is written
without its content, and a comment says so. --out-dir keeps the content
of every file out of the document and into a folder beside it, under the
same limit:
$ lemano state pull debian-12 --out-dir declarations
$ find declarations | sort | head
declarations
declarations/debian-12.yaml
declarations/files
declarations/files/etc
declarations/files/etc/apt
declarations/files/etc/apt/apt.conf.d
declarations/files/etc/apt/apt.conf.d/docker-clean
declarations/files/etc/apt/sources.list.d
declarations/files/etc/apt/sources.list.d/debian.sources
declarations/files/etc/environment
The document is declarations/debian-12.yaml, and each file the server
has is declarations/files/<its path>. The resource names it instead of
holding it:
- name: /etc/hostname
spec:
source: files/etc/hostnameThe folders and files are readable by their owner alone, are written one at
a time, and the document comes last, so a reader never finds a document that
names a file not there yet. A file already in the folder that the document
does not name is left as it is: if the server drops a file, remove its copy
yourself. --out FILE writes the document alone, atomically, and prints
nothing else. --out and --out-dir exclude each other.
Commands
A cron entry’s command is kept in the store, encrypted, and written when the file that holds it is readable by every user and the text does not look like it holds a secret:
- kind: Cron
defaults:
user: root
items:
- name: /etc/cron.d/e2scrub_all/606b6eec61d0
spec:
minute: "10"
hour: "3"
command: test -e /run/systemd/system || SERVICE_MODE=1 /sbin/e2scrub_all -A -r
location: cron.d
- name: /etc/cron.daily/apt-compat
spec:
command: /etc/cron.daily/apt-compat
period: dailyA schedule field that is * is not written, as * is its default: the
entry above runs at 03:10 every day. A script in /etc/cron.daily or its
siblings has no schedule of its own, since the system runs it, so its period
names the folder instead.
A user’s crontab is not readable by every user, so its commands are left out, and the comment on the resource says so. It names the rule that matched, never the text. A pass made before Lemano kept commands has none to write: read the server again.
The system crontab is declared with location: crontab, as above with
cron.d, and its entries keep their user.
Who can get in, and what is exposed
A declaration says first what readers of a server check first: the keys that let someone in, who may run what as root, and what the firewall lets through.
An authorized key is written whole, with its comment and its options in the order of the line. The forced command and the environment settings are written back into their options unless their text looks like it holds a secret, as the second key below, whose option is left out and named:
- kind: SshAuthorizedKey
items:
- name: deploy/SHA256:Wf9WDjPVTSf6x8iZqfyqUaRLn3mPwiiDNTk3CwZviA8
spec:
user: deploy
key: ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBcTErgpQZz4CA6r/Ng0lc7twxoYLQYRp+hK1O1H3hzJ
comment: ci@build
options:
- from="10.0.0.0/8"
- no-pty
- command="/usr/local/bin/deploy-release --flag"
- environment="TZ=UTC"
# option command left out: it looks like it holds a secret: credential assignment
- name: deploy/SHA256:tWAYh2uaKkbUUfrH3kb1tuJJdSn8D8e9hQBdh04hwDs
spec:
user: deploy
key: ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIASjvKM4M4ES8WHzYjKNEU37Tx+CMnV/2pF28lOOnVmw
comment: backupA sudoers file that holds one plain rule is written by the fields of a
rule: users or group, hosts, runAs, nopasswd and commands. Any
other file is written as its content, in the order of the file: its
Defaults lines, its aliases, its rules and its includes. The commands are
written unless they look like a secret, whoever can read the file; one that
does is left out of its rule or alias, which stays, and a comment names it:
- kind: SudoRule
items:
- name: /etc/sudoers
spec:
defaults:
- Defaults env_reset
- Defaults use_pty
rules:
- users: [root]
runAs: ALL:ALL
commands: [ALL]
- users: ['%sudo']
runAs: ALL:ALL
commands: [ALL]
includes:
- '@includedir /etc/sudoers.d'
# alias PUSH: 1 command left out: it looks like it holds a secret: GitHub token
- name: /etc/sudoers.d/ops
spec:
aliases:
- type: User_Alias
name: ADMINS
members: [alice, root]
- type: Cmnd_Alias
name: PUSH
rules:
- users: [ADMINS]
runAs: root
tags: [NOPASSWD]
commands: [/usr/bin/systemctl restart ssh]
- users: ['%deploy']
runAs: ALL:ALL
tags: [SETENV]
commands: [/usr/bin/journalctl, PUSH]runAs is the run-as list as sudoers writes it, and absent for root.
A default policy is a resource of its own, with the direction it applies
to: for a chain of nftables, the one of its hook; for ufw, its incoming,
outgoing or routed traffic; for firewalld, a zone. A ufw rule is written
by the fields of ufw’s own command (direction and interface, or route
with interfaceIn and interfaceOut; application, or protocol and
port; source, destination, log, action). An nftables rule that its
direction, protocol, port and source say whole is written by them and its
action; any other (a connection state, a jump to another chain, a NAT
statement) is written by its action and the normalised expression the
record holds, so that what it matches is not lost:
- kind: FirewallRule
defaults:
backend: nftables
items:
- name: in/tcp/22/
spec:
direction: in
protocol: tcp
port: "22"
action: accept
- name: inet/filter/forward/
spec:
direction: forward
policy: drop
- name: inet/filter/input/80686e46aa79
spec:
action: accept
expression: ct state in {established,related} accept
- name: ufw/incoming/
spec:
direction: in
policy: reject
backend: ufw
- name: ufw/rules/85c39ac11f63
spec:
direction: in
interface: lo
action: accept
backend: ufw
- name: in/tcp/2222/
spec:
direction: in
protocol: tcp
port: "2222"
action: limit
backend: ufwSome of what a firewall holds is not what its administrator set, and is
counted at the head instead, with its reason: the accept policy of a nat or
route chain, which is the default of the chain (a filter chain keeps its
policy, since an accept on an input chain is what NoDefaultDropPolicy
flags); the rules and chains firewalld writes into its own nftables table;
and the zones as firewalld ships them. A firewalld zone is declared when it
is the default zone, is bound to an interface or a source, or has a file
under /etc/firewalld/zones. On a Rocky Linux host the zones in use are
all there is of firewalld:
- kind: FirewallRule
items:
- name: firewalld/public/
spec:
policy: default
zone: public
backend: firewalld
- name: firewalld/public/0f751af1ebd9
spec:
action: accept
expression: service ssh
backend: firewalld
- name: firewalld/public/66934db6d203
spec:
action: accept
expression: service cockpit
backend: firewalldThe order of the rules in their chain, which a first-match firewall follows, is not part of the declaration.
Keeping it in Git
A declaration is a plain text file, so Git can keep its history and your team can review it. Write one folder, commit it after each pass:
lemano discover debian-12
lemano state pull debian-12 --out-dir declarations
git -C declarations add --all
git -C declarations commit -m "debian-12: after the pass of $(date -u +%F)"A pass that changed nothing writes no generation, and a pull of the same generation writes the same files, so Git sees no change. Put the commands in the script your scheduled pass runs. One document for each server, named after it, keeps each server’s history apart.
When something changes, the commit shows it. This is the same server after one file was edited and one cron entry added by hand:
-# Declaration of the 83 of the 1520 objects read on debian-12 that define the
+# Declaration of the 85 of the 1522 objects read on debian-12 that define the
# server.
...
metadata:
name: debian-12
annotations:
- lemano.dev/generated-from: debian-12, generation 0 (2026-11-24T22:41:51Z), baseline generation 0
+ lemano.dev/generated-from: debian-12, generation 1 (2026-11-24T22:41:55Z), baseline generation 0
...
+ # added in generation 1, not attributed
+ # content not written: the file may hold secrets, it holds commands, keys or mount options that Lemano keeps sealed
+ - name: /etc/cron.d/backup
...
+ # changed in generation 1, not attributed
- name: /etc/motd
spec:
- content: |2
-
- The programs included with the Debian GNU/Linux system are free software;
...
+ content: |
+ Welcome to debian-12
+ Authorised use only
...
+ # added in generation 1, not attributed
+ - name: /etc/cron.d/backup/6953be92c50b
+ spec:
+ minute: "0"
+ hour: "3"
+ command: /usr/local/bin/backup --all
+ location: cron.dOnly the head, the lines of the resources that changed, and their comments differ. The defaults of a group are the fixed values of its kind, so a new resource never moves a default or the lines of another resource.
The declaration holds what Lemano keeps encrypted in its store, in plain text: the content of the files it may show. Keep it in a repository that is as private as the servers’ configuration, and review it as you would configuration. It never holds a value Lemano treats as sealed or a file that looks like it has secrets.
What it cannot do yet
state pull is read-only. The declaration describes a server as it is. Nothing
reads it back, and it makes no change to a server: to put a file back as it
was, use lemano revert. Today it is a
readable, reviewable record of what each server is, and a document your own
tools can read.
Next
- Reading the history: what changed between two generations
- State: every rule of the lists and of the declaration
- Running discovery on a schedule: the pass that feeds it