]> ruderich.org/simon Gitweb - safcm/safcm.git/blob - README.adoc
README: multiple improvements
[safcm/safcm.git] / README.adoc
1 = README
2
3 Simple and fast configuration management (safcm) is written in Go and licensed
4 under GPLv3+. It is:
5
6 - *simple*: to use and implement, obvious concepts and less bugs
7 - *fast*: to learn and to use, quickly apply new configurations to your hosts
8 - *configuration management*: sync files, packages, services and run commands
9   on remote hosts
10
11 The goal is that even unexperienced users (with safcm or configuration
12 management in general) should be able to apply configuration with safcm
13 quickly. This means all key concepts of safcm must be easy to grasp and for
14 each task there should be one obvious way.
15
16 It can also be read as "saf(e) configuration management" as it combines
17 simplicity and safety in the following principles:
18
19 - *fail fast*: catch (user) errors as soon as possible; host configuration
20   (including templates) is evaluated locally to prevent partial configuration;
21   errors immediately abort the synchronization
22 - *remote hosts are untrusted*: clear security boundary between local and
23   remote host; data used from remote hosts is marked tainted (detected
24   groups); all output from remote hosts is escaped to prevent terminal
25   injection attacks; each host only receives its own configuration and no data
26   from other hosts
27 - *safety and security*: create files with "write to temporary file", "sync",
28   "rename", "sync directory" for atomicity and durability; guard against
29   symlink and other TOCTOU attacks; extensive test suite
30
31
32 == Overview
33
34 This section describes the general concepts, behavior and terminology of
35 safcm.
36
37 Safcm _synchronizes_ _files_, _packages_, _services_ and _commands_ to remote
38 _hosts_. All hosts are explicitly configured. Hosts can be put into _groups_
39 to apply the same configuration to multiple hosts. The host itself is also
40 considered a group for host-specific configuration. In addition to manual
41 group assignment _detected groups_ assign hosts to groups depending on the
42 output of custom commands on the remote host. The configuration for a group
43 contains the files, packages, services and commands which should be applied to
44 all hosts which are members of this group.
45
46 The configuration of all managed hosts is stored in a directory on the local
47 host. Safcm uses https://yaml.org/[YAML] for all configuration files. Strict
48 type checks prevent potential pitfalls due to the complex YAML syntax. Tasks
49 like copying a file require no explicit configuration.
50
51 Files (regular files and symbolic links) and directories, including
52 permissions, user/group and content are kept in a regular filesystem tree on
53 the local host. Files can use _templates_ for dynamic content depending on the
54 host or its groups. Each path can have _trigger_ commands which are executed
55 when the path itself or any sub-paths are modified during synchronization.
56 Packages are package names of the remote operating system. Services are
57 service names of the remote operating system. Commands are shell commands
58 passed to `/bin/sh`.
59
60 When files with the same path are present in multiple groups of a host, an
61 explicit _group order_ must be configured to resolve the conflict. Conflicts
62 do not apply to packages and services which are simply merged from all groups.
63 Commands are appended so that the same command can be executed multiple times.
64
65 To sync the configuration to a remote host, the local `safcm` binary connects
66 to it via `ssh`. It then copies a _remote helper_ binary to `/tmp` on the
67 remote host to perform the actual sync later. If the remote helper is already
68 present, has the proper checksum, permissions and user/group then the copying
69 step is skipped. `safcm` then queries the remote host for information,
70 including operating system, architecture and detected groups. With all
71 relevant data collected, it assigns the host to its groups, evaluates the
72 configuration including templates and finally sends the new configuration to
73 the remote helper which then applies it to the remote host.
74
75 The synchronization happens in the following order which cannot be changed:
76
77 . Collect information from remote helper including detected groups
78 . Build configuration for the host and send it to the remote helper
79 . Apply the configuration using the remote helper
80 .. Synchronize files
81 .. Install packages
82 .. Enable/Start services
83 .. Run triggers
84 .. Run commands
85
86 After the synchronization is complete (or on the first error) the applied
87 changes are displayed. Multiple hosts are synchronized in parallel.
88
89
90 == Limitations & Gotchas
91
92 Besides some obvious limitations due to the simplicity of safcm there are a
93 few issues the user should be aware of. Some of these might get fixed in the
94 future, others are due to the design of safcm.
95
96 - Commands are executed with `/bin/sh -c` on the remote host which might leak
97   sensitive information to other users via the command line (unless `/proc` is
98   mounted with `hidepid=`). Store sensitive data in a file and execute or
99   source it as a workaround.
100
101 - Permissions of existing files and directories will be overwritten with the
102   default (root/root, 0644 for files, 0755 for directories) unless manually
103   configured via `permissions.yaml`. This includes important paths like
104   `/root` which often have strict permissions by default, so carefully check
105   the diff output for unwanted changes.
106
107 - The full file content of all files is sent to the remote during
108   synchronization. This makes it impractical to synchronize large files with
109   safcm. Since most configuration files are small this shouldn't be an issue
110   for common scenarios.
111
112 - Quoted strings in the output are quoted using Go's `%q` format string. The
113   result is similar -- but not identical -- to quoted strings in regular shell
114   scripts which can be confusing.
115
116 - Permissions of symlinks are ignored on BSD systems. They are always shown to
117   have `0777` as permissions even though the current umask controls the actual
118   permissions when creating new symlinks. Existing symlinks with different
119   permissions are not updated. Most BSDs ignore the permissions when following
120   symlinks which should reduce the impact of this limitation.
121
122
123 == Requirements
124
125 - to build the `safcm` binary and remote helper:
126   * Go >= 1.16
127   * GNU make
128
129 - local host:
130   * Go support for architecture and operating system, see the "$GOOS and
131     $GOARCH" section in the official
132     https://golang.org/doc/install/source#environment[Go installation guide]
133
134 - *remote hosts*:
135   * Go support for architecture and operating system
136   * Supported operating system:
137     ** GNU/Linux with common commands (`uname`, `id`, `stat`, `sha512sum`,
138        `cat`, `mktemp`, `rm`, `ln`, `chmod`)
139     ** FreeBSD (same commands, but uses `sha512`)
140     ** OpenBSD (same commands, but uses `sha512`)
141   * SSH server
142   * to install packages:
143     ** `apt-get` (Debian or derivative)
144   * to sync services:
145     ** `systemd`
146
147 Adding support for other operating systems (e.g. BSDs) or distributions
148 including package managers (e.g. Arch, Gentoo) is easy. Please send patches.
149
150
151 == Authors
152
153 Written by Simon Ruderich <simon@ruderich.org>.
154
155
156 == License
157
158 This program is licensed under GPL version 3 or later.
159
160 Copyright (C) 2021  Simon Ruderich
161
162 This program is free software: you can redistribute it and/or modify
163 it under the terms of the GNU General Public License as published by
164 the Free Software Foundation, either version 3 of the License, or
165 (at your option) any later version.
166
167 This program is distributed in the hope that it will be useful,
168 but WITHOUT ANY WARRANTY; without even the implied warranty of
169 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
170 GNU General Public License for more details.
171
172 You should have received a copy of the GNU General Public License
173 along with this program.  If not, see <http://www.gnu.org/licenses/>.