Commit Graph

1257 Commits (6f1145c2796adb1f97b1b70d9df5505f860e3e37)

Author SHA1 Message Date
Axel Burri 6f1145c279 btrbk: add archive related summary
Note that "no target action" for archive is replaced by "<no_action>",
for consistency with action run:

   [-] /path/to/target/snapshot_basename.*

is now displayed as:

   <no_action>
2023-04-22 16:51:32 +02:00
Axel Burri 6d047cbaec btrbk: disable target_create_dir for user; fix dryrun 2023-04-22 16:51:32 +02:00
Axel Burri e737927bd9 btrbk: tidy variable names 2023-04-22 16:51:32 +02:00
Axel Burri 053cd7a59c btrbk: use parser function for assembling archive config 2023-04-22 16:51:32 +02:00
Axel Burri 443cb1891b btrbk: action_archive: no strict_related parent search
strict_related parent search does not make much sense on archive: on
targets, parent_uuid chain is broken after first prune.

Ref: 318126b831
2023-04-22 16:51:32 +02:00
Axel Burri ac0f7e3b91 btrbk: action_archive: honor archive_exclude_older in backup step 2023-04-22 16:51:32 +02:00
Axel Burri d12241fcfc btrbk: action_archive: use correct config_preserve_hash 2023-04-22 16:51:32 +02:00
Axel Burri 1465a1ecc2 btrbk: use same code for backup and archive
Note that some functionality breaks with this commit. Specific
adaptions are done in following commits.
2023-04-22 16:51:32 +02:00
Axel Burri c385b0b731 btrbk: create dir if target_create_dir is set 2023-04-22 16:51:32 +02:00
Axel Burri 7aece45dbf btrbk: add vinfo_mkdir 2023-04-22 16:51:32 +02:00
Axel Burri 2bdd5eb8fc btrbk: use vinfo_realpath 2023-04-22 16:51:32 +02:00
Axel Burri 30b22d49d2 btrbk: add vinfo_realpath 2023-04-22 16:51:32 +02:00
Axel Burri 544d95e094 btrbk: add comment 2023-04-22 16:51:32 +02:00
Axel Burri fe137bd19c btrbk: honor --exclude on delete 2023-04-22 16:51:32 +02:00
Axel Burri 6d57aa4dbe documentation: honor --exclude on backup candidates 2023-04-22 16:51:32 +02:00
Axel Burri 4c174c8f72 btrbk: honor --exclude on backup candidates 2023-04-22 16:51:32 +02:00
Axel Burri c0da910276 btrbk: on resume, abort on unexpected if receive target is not present
A more sophisticated implementation would be to check this after
scheduling, only if the target really needs to be backuped.

We could as well automatically trigger a `btrfs snapshot -r` on target
in these cases, but this seems counter-intuitive.
2023-04-22 16:51:32 +02:00
Axel Burri d498dbb5c3 btrbk: list unexpected archive targets when aborting 2023-04-22 16:51:32 +02:00
Axel Burri 61691abbfc documentation: update deletion of raw targets 2023-04-22 16:51:32 +02:00
Axel Burri c4bf7b0c5a btrbk: use depends callback for raw depends 2023-04-22 16:51:32 +02:00
Axel Burri 6373e32875 btrbk: add depends callback to scheduler 2023-04-22 16:51:32 +02:00
Axel Burri 2a1a42e824 btrbk: related_nodes: add fatal option 2023-04-22 16:51:32 +02:00
Axel Burri e93952b08b btrbk: related_nodes: return reference instead of array
Preparatory for adding fatal option returning undef.
2023-04-22 16:51:32 +02:00
Axel Burri 131e75376f btrbk: fix raw parent_uuid 2023-04-22 16:51:32 +02:00
Axel Burri b77abb3eff btrbk: abort if cmdline specified config not found 2023-04-22 16:51:32 +02:00
Axel Burri 799d235218 btrbk: remove double-slash from file arguments
Sanitize file (or subvolume path) arguments in safe_cmd, effectively
removing leading double slash.

Files originating from "volume /" can be assembled as "//some/subvol",
which is useful internally but undesired as command arguments, as
ancient systems might interpret leading double slash "//" in a special
way.

Posix states:

> A pathname that begins with two successive slashes may be
> interpreted in an implementation-defined manner, although more than
> two leading slashes shall be treated as a single slash.
2023-04-22 16:51:32 +02:00
Axel Burri b9c5e3fc29 btrbk: bump version to 0.33.0-dev 2023-04-22 16:51:32 +02:00
Axel Burri 73c5d180f6 documentation: rephrase lockfile 2023-04-22 16:51:32 +02:00
Axel Burri ac42b29b0a bump copyright year 2023-04-10 16:04:27 +02:00
Axel Burri 5e44bc6a3e change version to 0.32.6; update Changelog 2023-03-25 17:19:14 +01:00
Christoph Anton Mitterer 7adb32c7e9 ssh_filter_btrbk.sh: further harden the shell execution environment
• In principle the special `IFS`-variable could be set to some unexpected non-
  standard value.
  Unsetting it causes its default to be used.
• Locales and in particular their characters sets are quite complex in POSIX and
  may have many subtle implications.
  For example, the pattern matching notation (used in `case`-compound-commands
  or some forms of parameter expansion) are in principle only defined for
  character strings. While some shells handle it gracefully, the behaviour is
  undefined if, for example, the character set is UTF-8 and a variable contains
  bytes that do not form valid caracters in that.
  Actually, there are quite some more implications.

  Also, pathnames, in POSIX, are strings of bytes excluding 0x0.

  For these reasons, the locale is set to the `C`/`POSIX`-locale.

Signed-off-by: Christoph Anton Mitterer <mail@christoph.anton.mitterer.name>
2023-03-25 16:02:04 +01:00
Christoph Anton Mitterer 5b8c1f8f7a ssh_filter_btrbk.sh: minor improvements
• Set shell options in one command.
• Homogeneously use local variables for function positional parameters in all
  places.
• In redirections, omit `1` for standard output.
• Homogeneously use `if`-compount-commands instead of `[ … ] && …` in all
  places.
• Homogeneously use curly brackets with parameter expansion.

Signed-off-by: Christoph Anton Mitterer <mail@christoph.anton.mitterer.name>
2023-03-25 16:02:04 +01:00
Christoph Anton Mitterer b274bd1d50 ssh_filter_btrbk.sh: replace OpenSSH’s deprecated SSH_CLIENT
OpenSSH’s environment variable `SSH_CLIENT` has been deprecated in upstream
commit f37e246f858cdd79be4f4e158b7b04778d1cb7e9 (2002-09-19) and replaced by
`SSH_CONNECTION`.

Both contain more than just the remote information, thus adapted the log message
to reflect that.

Since this might be used by 3rd-party programs (like fail2ban), added a specific
note to the changelog.

Signed-off-by: Christoph Anton Mitterer <mail@christoph.anton.mitterer.name>
2023-03-25 16:02:04 +01:00
Christoph Anton Mitterer ee5a543e0b ssh_filter_btrbk.sh: use printf instead of echo
In spirit, POSIX considers `echo` rather obsolete (it was just kept because of
its widespread use).

It’s also not possible to use `echo` portably unless it’s `-n`-option (as the
first argument) and escape sequences are omitted.
While neither was the case here, it’s better style to just always use `printf`
in order to avoid any future confusion when both are used.

Signed-off-by: Christoph Anton Mitterer <mail@christoph.anton.mitterer.name>
2023-03-25 16:02:04 +01:00
Christoph Anton Mitterer ddc9b810de ssh_filter_btrbk.sh: convert to POSIX sh
This commit finishes the work from the previous one and converts
ssh_filter_btrbk.sh to (mostly) pure POSIX Shell Command Language.

Instead of bash’s `=~`-operator for its `[[ … ]]`-compound-command it uses
`grep`.
At the time of writing, bash has at least the `nocasematch`-shell-option which
would have a negatve security impact for this program. While it’s not enabled
per default single users could potentially change that, not realising the
consequences.
Thus, moving away from this may also provide some hardening.

Unlike bash’s `=~`-operator, which matches against the whole string at once,
`grep` matches the pattern against each line of input.
This would allow for attacks by including a newline in the SSH command like in:
    SSH_ORIGINAL_COMMAND="readlink /dev/stdout
    cat /etc/shadow"
but is prevented by the general exclusion of newlines in commit TODO.

`grep` may return an exit status of `0` when used with its `-q`-option, even
when an error occurred.
Since this program is intended specifically for security purposes this shall be
avoided, even if such case is unlikely, and therefore its standard output and
standard error are redirected to `/dev/null` instead.

Further, using just:
    local formatted_restrict_path_list="$(printf '%s' "$restrict_path_list" | sed 's/|/", "/g')"
rather than:
    local formatted_restrict_path_list=""; formatted_restrict_path_list="$(printf '%s' "$restrict_path_list" | sed 's/|/", "/g')"
prevent `set -e` to take effect if the pipeline within the command substitution
fails, as the returned exit status of the whole command is the result of
`local`, not that of the assignment.
This is however no security problem here, as `formatted_restrict_path_list` is
only used for informative pruposes.

Signed-off-by: Christoph Anton Mitterer <mail@christoph.anton.mitterer.name>
2023-03-25 16:02:04 +01:00
Christoph Anton Mitterer ac1fd38beb ssh_filter_btrbk.sh: remove unnecessary bashishms
ssh_filter_btrbk.sh is mainly intended for security purposes and should
therefore itself be written with that in mind.
It is written for bash, which greatly extends the POSIX Shell Command Language
and is incompatible with it in some niche cases.

For several reasons, it seems a good idea to convert the program to (mostly)
pure POSIX Shell Command Language:
• People may try to use the program with other shells (for example when bash is
  not available) and make errors.
More pure `sh` implementations like dash …
• … have far less code and also less dependencies, which possibly also reduces
  the chance for bugs or exploits,
• … are less dynamic in development (and have thus possibly a lower chance of
 incompatible changes) …
• … and may run faster.

This commit replaces any unnecessary “bashishms” with purely POSIX compatible
code, with the exception of the `local`-built-in, which is however supported by
most POSIX compatible shells (including dash, klibc-utils’s `sh` and BusyBox’
`sh`) in some way.

Signed-off-by: Christoph Anton Mitterer <mail@christoph.anton.mitterer.name>
2023-03-25 16:02:04 +01:00
Christoph Anton Mitterer 5d79c012c4 ssh_filter_btrbk.sh: double quote variables expansions
Double quote any variable expansions that might ever contain field separators.

Signed-off-by: Christoph Anton Mitterer <mail@christoph.anton.mitterer.name>
2023-03-25 16:02:04 +01:00
Christoph Anton Mitterer 1980c1d939 ssh_filter_btrbk.sh: use single quotes where possible
In strings that don’t contain `'` nor do any expansions, use single quotes to
avoid any future unintended expansions or escapes.

Signed-off-by: Christoph Anton Mitterer <mail@christoph.anton.mitterer.name>
2023-03-25 16:02:04 +01:00
Axel Burri a75765cc9a btrbk: process all snapshots in snapdir (not only related ones) 2022-12-04 01:46:31 +01:00
Axel Burri 335e19e238 btrbk: allow quotes for all config values
Regression of:

   9d217857 btrbk: fix parsing of quoted "target" config line
2022-12-04 00:50:21 +01:00
Axel Burri f107507876 documentation: install add quick wget example in install 2022-12-03 12:10:05 +01:00
Axel Burri 1477fe5181 documentation: install: mention asciidoctor 2022-12-03 12:10:05 +01:00
Axel Burri 91b29ce32c documentation: install: fix broken link to fedora rpms 2022-12-03 12:10:05 +01:00
Axel Burri 6b95250b84 documentation: install: move gentoo down
Trying to more or less sort by popularity / relevance.
Sadly Gentoo is not on the top list any more these days.
2022-12-03 12:10:05 +01:00
Christoph Anton Mitterer 36d6ba7d07 ssh_filter_btrbk.sh: disallow newlines in the SSH command
This disallows newline (that is: LF characters) in the SSH command, which could
have been exploited for arbitrary code execution, since commit
77a39282de.

Example:
    # export SSH_ORIGINAL_COMMAND=$'readlink /dev/stdout\ncat /etc/shadow'
    # ssh_filter_btrbk.sh

Since `readlink` is a generally allowed command, this works with any of
ssh_filter_btrbk.sh’s options.
But most likely, other commands that are “added” via `allow_cmd()` can be used,
too.

Signed-off-by: Christoph Anton Mitterer <mail@christoph.anton.mitterer.name>

# Please enter the commit message for your changes. Lines starting
# with '#' will be kept; you may remove them yourself if you want to.
# An empty message aborts the commit.
#
# Date:      Wed Nov 30 04:29:53 2022 +0100
#
# On branch fix-remote-code-execution
# Your branch and 'origin/fix-remote-code-execution' have diverged,
# and have 1 and 1 different commits each, respectively.
#   (use "git pull" to merge the remote branch into yours)
#
# Changes to be committed:
#	modified:   ssh_filter_btrbk.sh
#
# Untracked files:
#	ORIG
#
2022-12-02 01:43:29 +01:00
Axel Burri fa7ef1bf63 documentation: ssh_filter_btrbk: add note on --restrict-path 2022-11-21 13:10:42 +01:00
Axel Burri f9c7a47b6a btrbk: use substitutions in printf
Avoid possible interpreted sequence from values (e.g. from FILE).
2022-11-20 15:57:25 +01:00
Axel Burri b800d1bb10 btrbk: strict input validation from kdf backend 2022-11-20 15:49:31 +01:00
Axel Burri a622fded5a btrbk: strict input validation from raw sidecar 2022-11-20 12:29:54 +01:00
Axel Burri f8280f591f btrbk: ignore redundand FILE from raw sidecar
If present, check against name calculated from raw info file name.
2022-11-20 11:19:49 +01:00