Simon Ruderich [Tue, 1 Jun 2021 05:59:59 +0000 (07:59 +0200)]
remote: guard against symlinks in earlier path components
This was only an issue when syncing files to directories where other
users have write access to the parent directory. For example when
copying files to /home/user/.ssh/authorized_keys the user could replace
.ssh with a symlink which permitted overwriting authorized_keys anywhere
on the system.
Fix possible attacks by using *at syscalls and disallowing symlinks in
all path components except for the last of synced paths. Syncing
symlinks is obviously still permitted.
Simon Ruderich [Mon, 31 May 2021 20:31:13 +0000 (22:31 +0200)]
safcm: add commit date to version output
Simon Ruderich [Sat, 29 May 2021 15:34:57 +0000 (17:34 +0200)]
.builds: openbsd/latest updated to 6.9, remove manual Go download
Simon Ruderich [Wed, 26 May 2021 07:20:04 +0000 (09:20 +0200)]
remote: use defer to replace multiple dh.Close()
Simon Ruderich [Tue, 25 May 2021 06:43:00 +0000 (08:43 +0200)]
remote: remove double Close() on error in WriteTemp()
Simon Ruderich [Sun, 23 May 2021 10:33:06 +0000 (12:33 +0200)]
remote: treat paths as slash separated in triggerPaths()
Remotes are only supported on UNIX systems which use slashes as path
separators so this had no direct effect. Change it to make the code more
obvious.
This was forgotten in
afb7e8e (safcm: use only slash separated paths for
the configuration, 2021-05-13).
Simon Ruderich [Tue, 18 May 2021 16:51:47 +0000 (18:51 +0200)]
safcm: move logEvent() to frontend package
Simon Ruderich [Tue, 18 May 2021 16:36:11 +0000 (18:36 +0200)]
frontend: add Loop.HostSyncMsg()
Simon Ruderich [Tue, 18 May 2021 16:36:06 +0000 (18:36 +0200)]
frontend: add Loop.HostInfoMsg()
Simon Ruderich [Tue, 18 May 2021 16:24:02 +0000 (18:24 +0200)]
safcm: move sync.sendRecv to frontend package
Simon Ruderich [Tue, 18 May 2021 16:15:23 +0000 (18:15 +0200)]
safcm: move sync_changes.go and term.go to frontend package
Simon Ruderich [Tue, 18 May 2021 15:52:14 +0000 (17:52 +0200)]
safcm: add ParseLogLevel()
Simon Ruderich [Tue, 18 May 2021 15:46:59 +0000 (17:46 +0200)]
go fmt
Simon Ruderich [Tue, 18 May 2021 15:46:56 +0000 (17:46 +0200)]
Move synchronization loop into new package frontend
This is in preparation for other programs (besides cmd/safcm) using the
safcm library. To reduce code duplication useful functions will be
provided by the frontend package. Its use is optional. All core
functionality is provided by the regular safcm packages.
The logging setup was slightly modified. Log messages are now no longer
filtered by Sync.log() but by the new log function Loop.LogEventFunc (or
its implementation logEvent()). This is also the reason why one test was
removed from sync_sync_test.go which is no longer relevant.
Simon Ruderich [Tue, 18 May 2021 10:29:48 +0000 (12:29 +0200)]
Move implementation of cmd/safcm-remote/ to remote/
This permits users of the safcm library to easily "implement"
`safcm-remote` simply by calling safcm/remote.Main(). They cannot use
the existing cmd/safcm-remote/ because the source tree is not directly
available when importing the library.
Simon Ruderich [Tue, 18 May 2021 09:03:05 +0000 (11:03 +0200)]
Move embedded remote helpers to cmd/safcm/
To permit using safcm as an actual library the helpers must be passed to
rpc.DialSSH() and not directly embedded.
Simon Ruderich [Tue, 18 May 2021 08:50:43 +0000 (10:50 +0200)]
safcm: don't hang on error before a connection is established
Simon Ruderich [Tue, 18 May 2021 08:10:09 +0000 (10:10 +0200)]
rpc: use SSHConfig struct as argument to DialSSH()
In preparation to add more arguments to DialSSH().
Simon Ruderich [Mon, 17 May 2021 06:37:23 +0000 (08:37 +0200)]
config: config.yaml: add global "ssh_user" option
This option is used as default value when the host option "ssh_user" is
empty. Like the host option it defaults to an empty value which tells
`ssh` to use the current user.
Simon Ruderich [Sun, 16 May 2021 20:42:51 +0000 (22:42 +0200)]
ci: build for Windows
Only added to Gitlab-CI because we just want to test if building works
in general.
Simon Ruderich [Thu, 13 May 2021 11:55:47 +0000 (13:55 +0200)]
safcm: add experimental support to sync from Windows hosts
This is _very_ experimental. The testsuite doesn't yet run on Windows
and only a few manual tests were run. Basically this is only present
because it was used to verify our changes to always use slash-separated
paths in the configuration on a real system. It seemed a waste to just
throw it away.
To build the binary for windows use (empty GOFLAGS to disable -race):
make GOOS=windows GOFLAGS=
Simon Ruderich [Thu, 13 May 2021 11:40:54 +0000 (13:40 +0200)]
safcm: use only slash separated paths for the configuration
This change is in preparation to support running synchronizations from
Windows systems. However, Windows remotes won't be supported in the
foreseeable future.
Simon Ruderich [Wed, 12 May 2021 06:35:59 +0000 (08:35 +0200)]
safcm: simplify Sync.logf to take the log message as string
logf() is not directly called by regular code which makes the format
string less useful.
Also rename it to log().
Simon Ruderich [Wed, 12 May 2021 06:32:51 +0000 (08:32 +0200)]
Consistently use %v when (s)printing errors
Most of the code already used %v.
Simon Ruderich [Wed, 12 May 2021 06:25:08 +0000 (08:25 +0200)]
sync: go fmt
Simon Ruderich [Wed, 12 May 2021 06:22:17 +0000 (08:22 +0200)]
sync: shorten log messages by removing "info/sync remote:" prefix
The prefix provides little value as it already obvious what's happening
on the remote side and in which phase (info/sync). Keeping the log
messages shorter helps the user to focus on the important parts of the
message.
Simon Ruderich [Wed, 12 May 2021 06:17:39 +0000 (08:17 +0200)]
sync: simplify LogFunc to take the log message as string
LogFunc is not directly called by regular code which makes the format
string less useful.
Simon Ruderich [Wed, 12 May 2021 06:14:26 +0000 (08:14 +0200)]
sync: replace log.Logger interface with struct
PrefixLogger is the only implementation of Logger. Simply remove the
interface and rename PrefixLogger to Logger.
Simon Ruderich [Wed, 12 May 2021 05:40:56 +0000 (07:40 +0200)]
Makefile: add lint target to run shellcheck
Simon Ruderich [Sun, 9 May 2021 19:19:42 +0000 (21:19 +0200)]
sync: remove "detected" log message in packages/services
Don't waste one full log message to show the detected system. Instead,
append it to an existing log message.
Reorder log call in syncPackagesDebian() so the log message comes before
calling debianInstalledPackages(). This way errors from this function
show clearly where they originate.
Simon Ruderich [Sun, 9 May 2021 18:44:02 +0000 (20:44 +0200)]
remote: tests: hide testRunner functions in test output
This is not perfect because they are called from files like
cmd/safcm-remote/sync/commands.go which is not very helpful to figure
out which test case failed. However, it's better than showing
cmd/safcm-remote/sync/sync_test.go which was the previous behavior.
Simon Ruderich [Sun, 9 May 2021 18:38:37 +0000 (20:38 +0200)]
tests: improve another comment
Simon Ruderich [Sun, 9 May 2021 18:20:16 +0000 (20:20 +0200)]
changes: add "(hidden)" to commands with no output and quiet mode
This should make it more obvious why these commands are not shown.
Simon Ruderich [Sun, 9 May 2021 18:15:09 +0000 (20:15 +0200)]
safcm: tests: remove empty line
Simon Ruderich [Sun, 9 May 2021 18:14:39 +0000 (20:14 +0200)]
rpc: remove empty line
Simon Ruderich [Sun, 9 May 2021 18:02:31 +0000 (20:02 +0200)]
config: disallow negative permissions
Simon Ruderich [Sun, 9 May 2021 17:51:02 +0000 (19:51 +0200)]
rpc: replace append to sshOpts with assignment in DialSSH()
sshOpts is empty by default and assigned only once. Don't suggest that
this line is supposed to add to an existing value.
Simon Ruderich [Sun, 9 May 2021 10:55:54 +0000 (12:55 +0200)]
safcm: shorten error message on file conflict
It's obvious that the message talks about "files" because the path is
given immediately afterwards.
Simon Ruderich [Sun, 9 May 2021 10:47:40 +0000 (12:47 +0200)]
safcm: use better variable name in hostsToSync()
Having nameMatched and hostMatched is confusing. Follow the comment and
use hostAdded which describes the meaning more clearly.
Simon Ruderich [Sun, 9 May 2021 10:46:18 +0000 (12:46 +0200)]
safcm: don't color output if stderr is redirected
All log messages are printed to stderr. It's confusing to still get
colored output when redirecting stderr to a file; only redirecting
stdout as well fixed this.
Simon Ruderich [Sun, 9 May 2021 10:44:29 +0000 (12:44 +0200)]
changes: change dry-run messages to use "will"
Don't suggest that the change already took place. "dry-run" is still
printed to make it clear why no changes were made.
Simon Ruderich [Sun, 9 May 2021 10:39:30 +0000 (12:39 +0200)]
changes: tests: remove output for dry-run commands
Commands during a dry-run have no output. Don't use incorrect test
input.
Simon Ruderich [Sun, 9 May 2021 10:34:44 +0000 (12:34 +0200)]
config: tests: fix typo in group name
Simon Ruderich [Sun, 9 May 2021 10:32:53 +0000 (12:32 +0200)]
config: return map from TransitivelyDetectedGroups()
This is less clean than the original slice of strings. However, it
removes unnecessary code as the caller requires a map instead of a
slice.
Simon Ruderich [Sun, 9 May 2021 10:31:26 +0000 (12:31 +0200)]
config: use more explicit variable name in ResolveHostGroups()
Simon Ruderich [Sun, 9 May 2021 10:31:08 +0000 (12:31 +0200)]
config: rewrap line in ResolveHostGroups()
Simon Ruderich [Sun, 9 May 2021 10:29:08 +0000 (12:29 +0200)]
config: tests: replace FullPermToFileMode() with fs constants
FullPermToFileMode() is necessary in a few places but the tests should
use the common way in Go to set permissions. This is less confusing for
the reader.
Simon Ruderich [Sun, 9 May 2021 10:28:33 +0000 (12:28 +0200)]
sync: remove duplicate code in triggerPaths()
Simon Ruderich [Sun, 9 May 2021 10:27:28 +0000 (12:27 +0200)]
sync: include size in binary "diff"
Simon Ruderich [Sun, 9 May 2021 10:24:12 +0000 (12:24 +0200)]
sync: tests: use variable to reduce line wrapping
Simon Ruderich [Sun, 9 May 2021 10:20:39 +0000 (12:20 +0200)]
sync: tests: use "..." instead of `...` for regular strings
Simon Ruderich [Sun, 9 May 2021 10:15:58 +0000 (12:15 +0200)]
sync: tests: use strict perm for os.WriteFile() in CreateFile()
This parameter is modified by the umask. The proper permissions are set
by os.Chmod() afterwards. Don't confuse the reader by using a value
which is not relevant.
Simon Ruderich [Sun, 9 May 2021 10:15:42 +0000 (12:15 +0200)]
sync: tests: wrap overlong line
Simon Ruderich [Sun, 9 May 2021 10:14:16 +0000 (12:14 +0200)]
sync: tests: use CreateDirectoryExists()
Simon Ruderich [Sun, 9 May 2021 10:13:37 +0000 (12:13 +0200)]
sync: tests: check return value of setDefaults()
Simon Ruderich [Sun, 9 May 2021 10:12:22 +0000 (12:12 +0200)]
sync: tests: properly scope err variable
Simon Ruderich [Sun, 9 May 2021 09:42:31 +0000 (11:42 +0200)]
sync: tests: go fmt
Simon Ruderich [Sun, 9 May 2021 09:41:57 +0000 (11:41 +0200)]
sync: tests: rename triggers to expTriggers
Simon Ruderich [Sun, 9 May 2021 09:38:42 +0000 (11:38 +0200)]
safcm: tests: test detected groups with leading/trailing space
Simon Ruderich [Sun, 9 May 2021 09:38:27 +0000 (11:38 +0200)]
safcm: go fmt
Simon Ruderich [Sun, 9 May 2021 09:36:44 +0000 (11:36 +0200)]
safcm: strip invalid characters from detected os/arch groups
Handle them like any other detected group because the remote can send
invalid values. The current code can handle arbitrary group names just
fine but it's better to treat all untrusted input the same.
Simon Ruderich [Sun, 9 May 2021 08:10:56 +0000 (10:10 +0200)]
Improve and add comments
Simon Ruderich [Sun, 9 May 2021 08:03:34 +0000 (10:03 +0200)]
ci: suppress shellcheck warnings
$flags can contain multiple flags and we must expand them here.
Simon Ruderich [Sun, 9 May 2021 08:02:35 +0000 (10:02 +0200)]
README: mention root/wheel on BSD systems
Simon Ruderich [Sun, 9 May 2021 08:02:30 +0000 (10:02 +0200)]
README: fix typo
Simon Ruderich [Sat, 8 May 2021 08:20:57 +0000 (10:20 +0200)]
tests: run commands without side effects in end-to-end tests
Simon Ruderich [Thu, 29 Apr 2021 05:43:05 +0000 (07:43 +0200)]
README: multiple improvements
Simon Ruderich [Wed, 28 Apr 2021 10:29:50 +0000 (12:29 +0200)]
tests: add end-to-end test with configuration without any changes
Simon Ruderich [Wed, 28 Apr 2021 10:26:18 +0000 (12:26 +0200)]
sync: run most tests which modify the host only in CI
This is especially important in case the user executes the tests as root
(no recommended but not prevented either). Permissions on paths like /
or /tmp which differ from those expected by the test could otherwise be
modified by the tests.
However, the end-to-end SSH tests which write /tmp/safcm-remote-$uid
(but no other paths) are still run so we get proper coverage of basic
features.
Simon Ruderich [Wed, 28 Apr 2021 06:29:49 +0000 (08:29 +0200)]
tests: use filetest.CreateFifo() in config tests
Simon Ruderich [Wed, 28 Apr 2021 05:57:52 +0000 (07:57 +0200)]
sync: remove duplicate "priority" from group priority log message
Now that the configuration option is called "group_priority" we can
remove the second "priority" and spell out "descending" (takes less
space than before).
Simon Ruderich [Wed, 28 Apr 2021 05:51:16 +0000 (07:51 +0200)]
safcm: group_priority: use increasing priority values internally
It feels more natural that groups with higher priority have a higher
numeric value.
Simon Ruderich [Wed, 28 Apr 2021 05:48:59 +0000 (07:48 +0200)]
go fmt
Simon Ruderich [Wed, 28 Apr 2021 05:48:18 +0000 (07:48 +0200)]
config: rename group_order to group_priority
"Priority" describes the actual function better and it was already used
internally in the code anyway.
Simon Ruderich [Wed, 28 Apr 2021 05:32:37 +0000 (07:32 +0200)]
safcm: group_order: higher priority for listed groups over remaining groups
The priority for all groups listed in `group_order` was properly
respected: Early entries had the highest priority. However, groups which
were not listed in `group_order` had a higher priority and overwrote
files from all groups configured in `group_order`.
The priority is now as expected (from high to low): host itself, groups
in group_order (from high to low), remaining groups.
Markus Petri [Sun, 25 Apr 2021 13:33:56 +0000 (15:33 +0200)]
README: multiple improvements
Simon Ruderich [Sun, 25 Apr 2021 07:57:37 +0000 (09:57 +0200)]
changes: display "no changes" when nothing was changed
It's confusing to show nothing at all when no changes occur on a host.
To inform the user that the sync was successful but nothing changed
display a short message.
Simon Ruderich [Wed, 21 Apr 2021 06:28:08 +0000 (08:28 +0200)]
Makefile: move command to test target
The permissions are only relevant when running tests.
Simon Ruderich [Wed, 21 Apr 2021 06:28:00 +0000 (08:28 +0200)]
go fmt
Simon Ruderich [Wed, 21 Apr 2021 06:16:40 +0000 (08:16 +0200)]
tests: add very basic end-to-end test with real ssh server
At the moment only the helper upload without any actual configuration is
tested.
Simon Ruderich [Wed, 21 Apr 2021 06:16:03 +0000 (08:16 +0200)]
rpc: always create remote helper with user's group
If the group does not match the current user's group then the remote
helper will be uploaded again on each run.
Simon Ruderich [Tue, 20 Apr 2021 17:53:07 +0000 (19:53 +0200)]
Revert "ci: run tests with verbose output"
This reverts commit
444e9874424580361e00547b597d213370045057.
Turns out this is too noisy and less useful than I expected.
Simon Ruderich [Tue, 20 Apr 2021 17:52:01 +0000 (19:52 +0200)]
ci: use ./* in `rm -rf` to guard against option-like filenames
This won't be an issue in our case but it's good practice anyway.
Found by shellcheck
Simon Ruderich [Tue, 20 Apr 2021 14:17:53 +0000 (16:17 +0200)]
safcm: print unfinished hosts on Ctrl-C
Simon Ruderich [Tue, 20 Apr 2021 09:44:16 +0000 (11:44 +0200)]
remote: go fmt
Simon Ruderich [Tue, 20 Apr 2021 09:43:02 +0000 (11:43 +0200)]
remote: show group/trigger in verbose log for commands
This helps the user to figure out why the command was executed.
Simon Ruderich [Tue, 20 Apr 2021 09:21:10 +0000 (11:21 +0200)]
safcm: use Command struct instead of string to run commands
Simon Ruderich [Sun, 18 Apr 2021 09:13:48 +0000 (11:13 +0200)]
README: mention group and remove obvious sentence
Simon Ruderich [Sun, 18 Apr 2021 08:24:48 +0000 (10:24 +0200)]
README: mention why YAML was chosen
Simon Ruderich [Sun, 18 Apr 2021 07:57:30 +0000 (09:57 +0200)]
ci: run tests with verbose output
Simon Ruderich [Sun, 18 Apr 2021 07:52:20 +0000 (09:52 +0200)]
ci: check for untracked and unignored files
Simon Ruderich [Sun, 18 Apr 2021 07:51:35 +0000 (09:51 +0200)]
ci: build.sr.ht: run all tests also as root
Simon Ruderich [Sun, 18 Apr 2021 07:42:43 +0000 (09:42 +0200)]
config: only skip "invalid sticky" tests for non-root users
Simon Ruderich [Sat, 17 Apr 2021 12:48:42 +0000 (14:48 +0200)]
Add basic support for OpenBSD
Installing packages and starting/enabling services is not yet supported.
There are minor limitations when handling symlinks (see README.adoc).
/var/tmp is a symlink on OpenBSD so just remove this test.
Simon Ruderich [Sat, 17 Apr 2021 07:43:27 +0000 (09:43 +0200)]
Makefile: set -race via GOFLAGS= variable
Simon Ruderich [Sat, 17 Apr 2021 06:42:52 +0000 (08:42 +0200)]
config: groups: use "member" in "not found" error message
"group" was confusing, especially because "group" occurs at the
beginning of the error marking the group where the error occurred.
Simon Ruderich [Sat, 17 Apr 2021 06:36:05 +0000 (08:36 +0200)]
ci: also run tests with strict umask
Simon Ruderich [Sat, 17 Apr 2021 06:10:17 +0000 (08:10 +0200)]
Add basic support for FreeBSD
Installing packages and starting/enabling services is not yet supported.
There are minor limitations when handling symlinks (see README.adoc).
Simon Ruderich [Wed, 14 Apr 2021 11:47:28 +0000 (13:47 +0200)]
rpc: prepare to support more operating systems
Simon Ruderich [Thu, 15 Apr 2021 21:23:06 +0000 (23:23 +0200)]
Add build manifest for build.sr.ht