btrbk: add supoort for "backend btrfs-progs-sudo" option; adaptions in ssh_filter_btrbk.sh

pull/135/head
Axel Burri 2016-11-21 14:15:57 +01:00
parent d02f67a924
commit cb82bd5fa4
5 changed files with 54 additions and 29 deletions

View File

@ -1,6 +1,7 @@
btrbk-current btrbk-current
* Allow converting backup disks to source disks (close #114). * Allow converting backup disks to source disks (close #114).
* Add "backend btrfs-progs-sudo" configuration option (close #115).
* Show aggregate "size" and "used" for "usage" action (close #119). * Show aggregate "size" and "used" for "usage" action (close #119).
* raw_target_encrypt: Always set "gpg --no-random-seed-file": * raw_target_encrypt: Always set "gpg --no-random-seed-file":
prevents creation of "~/.gnupg/random_seed" with slight perfomance prevents creation of "~/.gnupg/random_seed" with slight perfomance

View File

@ -406,15 +406,21 @@ Please refer to [ssh_filter_btrbk(1)] for a description of the
of the "authorized_keys" file format. of the "authorized_keys" file format.
Also consider setting up ssh access for a user dedicated to btrbk and Also consider setting up ssh access for a user dedicated to btrbk and
either set suid root on ssh_filter_btrbk.sh or use the "--sudo" option choose either:
and configure /etc/sudoers accordingly. For even more security, you
can setup a chroot environment in /etc/ssh/sshd_config (see - `backend btrfs-progs-btrbk` to completely get rid of
[sshd_config(5)]). ssh_filter_btrbk.sh, in conjunction with [btrfs-progs-btrbk],
- `backend btrfs-progs-sudo`, configure /etc/sudoers, and consider
using "ssh_filter_btrbk.sh --sudo" option.
For even more security, set up a chroot environment in
/etc/ssh/sshd_config (see [sshd_config(5)]).
[ssh_filter_btrbk(1)]: http://digint.ch/btrbk/doc/ssh_filter_btrbk.html [ssh_filter_btrbk(1)]: http://digint.ch/btrbk/doc/ssh_filter_btrbk.html
[sshd(8)]: http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man8/sshd.8 [sshd(8)]: http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man8/sshd.8
[sshd_config(5)]: http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man5/sshd_config.5 [sshd_config(5)]: http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man5/sshd_config.5
[btrfs-progs-btrbk]: https://github.com/digint/btrfs-progs-btrbk
Restoring Backups Restoring Backups

13
btrbk
View File

@ -124,9 +124,9 @@ my %config_options = (
group => { default => undef, accept_regexp => qr/^$group_match(\s*,\s*$group_match)*$/, split => qr/\s*,\s*/ }, group => { default => undef, accept_regexp => qr/^$group_match(\s*,\s*$group_match)*$/, split => qr/\s*,\s*/ },
backend => { default => "btrfs-progs", accept => [ "btrfs-progs", "btrfs-progs-btrbk" ] }, backend => { default => "btrfs-progs", accept => [ "btrfs-progs", "btrfs-progs-btrbk", "btrfs-progs-sudo" ] },
backend_local => { default => undef, accept => [ "no", "btrfs-progs", "btrfs-progs-btrbk" ] }, backend_local => { default => undef, accept => [ "no", "btrfs-progs", "btrfs-progs-btrbk", "btrfs-progs-sudo" ] },
backend_remote => { default => undef, accept => [ "no", "btrfs-progs", "btrfs-progs-btrbk" ] }, backend_remote => { default => undef, accept => [ "no", "btrfs-progs", "btrfs-progs-btrbk", "btrfs-progs-sudo" ] },
# deprecated options # deprecated options
btrfs_progs_compat => { default => undef, accept => [ "yes", "no" ], btrfs_progs_compat => { default => undef, accept => [ "yes", "no" ],
@ -219,6 +219,13 @@ my %backend_cmd_map = (
"btrfs send" => [ "btrfs-send" ], "btrfs send" => [ "btrfs-send" ],
"btrfs receive" => [ "btrfs-receive" ], "btrfs receive" => [ "btrfs-receive" ],
}, },
"btrfs-progs-sudo" => { "btrfs subvolume list" => [ "sudo", "-n", "btrfs", "subvolume", "list" ],
"btrfs subvolume show" => [ "sudo", "-n", "btrfs", "subvolume", "show" ],
"btrfs subvolume snapshot" => [ "sudo", "-n", "btrfs", "subvolume", "snapshot" ],
"btrfs subvolume delete" => [ "sudo", "-n", "btrfs", "subvolume", "delete" ],
"btrfs send" => [ "sudo", "-n", "btrfs", "send" ],
"btrfs receive" => [ "sudo", "-n", "btrfs", "receive" ],
},
); );
my %url_cache; # map URL to btr_tree node my %url_cache; # map URL to btr_tree node

View File

@ -279,18 +279,29 @@ If set, make sure the deletion of snapshot and backup subvolumes are
committed to disk when btrbk terminates. Defaults to \[lq]no\[rq]. committed to disk when btrbk terminates. Defaults to \[lq]no\[rq].
.RE .RE
.PP .PP
\fBbackend\fR btrfs-progs|btrfs-progs-btrbk \fI*experimental*\fR \fBbackend\fR btrfs-progs|btrfs-progs-btrbk|btrfs-progs-sudo
.RS 4 .RS 4
Btrfs filesystem utilities to be used for subvolume operations. If set Backend filesystem utilities to be used for btrfs specific operations. The
default \[lq]btrfs-progs\[rq] simply executes btrfs(8) commands groups
(e.g. "btrfs subvolume show").
.IP \[bu] 2
If set
to \[lq]btrfs-progs-btrbk\[rq], specific btrfs(8) commands groups to \[lq]btrfs-progs-btrbk\[rq], specific btrfs(8) commands groups
needs to be separated by a dash instead of a whitespace needs to be separated by a dash instead of a whitespace
(e.g. "btrfs-subvolume-show" instead of "btrfs subvolume (e.g. "btrfs-subvolume-show" instead of "btrfs subvolume
show"). Useful for setting suid or file capabilities (setcap) on show"). Useful for setting suid or file capabilities (setcap) on
specific btrfs commands, as implemented in specific btrfs commands, as implemented in
<https://github.com/digint/btrfs-progs-btrbk>. For convenience, it is <https://github.com/digint/btrfs-progs-btrbk>.
also possible to set \fIbackend_local\fR or \fIbackend_remote\fR, .IP \[bu] 2
which will override the \fIbackend\fR option for local or remote If set to \[lq]btrfs-progs-sudo\[rq], btrfs commands are prefixed with
sources/targets. Defaults to \[lq]btrfs-progs\[rq]. "sudo -n" (e.g. "sudo -n btrfs subvolume show" instead of "btrfs
subvolume show"). Make sure to have apropriate (root) permissions for
"btrfs" command groups in /etc/sudoers.
.PP
For convenience, it is also possible to set \fIbackend_local\fR or
\fIbackend_remote\fR options, which will override the backend only for
local or remote sources/targets (e.g. "backend_remote
btrfs-progs-btrbk").
.RE .RE
.PP .PP
Lines that contain a hash character (#) in the first column are Lines that contain a hash character (#) in the first column are

View File

@ -6,7 +6,6 @@ set -u
export PATH=/sbin:/bin:/usr/sbin:/usr/bin export PATH=/sbin:/bin:/usr/sbin:/usr/bin
enable_log= enable_log=
use_sudo=
restrict_path_list= restrict_path_list=
allow_list= allow_list=
allow_exact_list= allow_exact_list=
@ -41,7 +40,7 @@ reject_and_die()
run_cmd() run_cmd()
{ {
log_cmd "auth.info" "btrbk ACCEPT" log_cmd "auth.info" "btrbk ACCEPT"
eval " $use_sudo $SSH_ORIGINAL_COMMAND" eval " $SSH_ORIGINAL_COMMAND"
} }
reject_filtered_cmd() reject_filtered_cmd()
@ -83,10 +82,8 @@ reject_filtered_cmd()
} }
# FIXME: "--sudo" must be set before all other options!
allow_cmd "btrfs subvolume show"; # subvolume queries are always allowed sudo_prefix=
allow_cmd "btrfs subvolume list"; # subvolume queries are always allowed
while [[ "$#" -ge 1 ]]; do while [[ "$#" -ge 1 ]]; do
key="$1" key="$1"
@ -96,7 +93,7 @@ while [[ "$#" -ge 1 ]]; do
;; ;;
--sudo) --sudo)
use_sudo="sudo" sudo_prefix="sudo -n "
;; ;;
-p|--restrict-path) -p|--restrict-path)
@ -105,12 +102,12 @@ while [[ "$#" -ge 1 ]]; do
;; ;;
-s|--source) -s|--source)
allow_cmd "btrfs subvolume snapshot" allow_cmd "${sudo_prefix}btrfs subvolume snapshot"
allow_cmd "btrfs send" allow_cmd "${sudo_prefix}btrfs send"
;; ;;
-t|--target) -t|--target)
allow_cmd "btrfs receive" allow_cmd "${sudo_prefix}btrfs receive"
# the following are needed if targets point to a directory # the following are needed if targets point to a directory
allow_cmd "readlink" allow_cmd "readlink"
allow_exact_cmd "cat /proc/self/mounts" allow_exact_cmd "cat /proc/self/mounts"
@ -121,24 +118,24 @@ while [[ "$#" -ge 1 ]]; do
;; ;;
-d|--delete) -d|--delete)
allow_cmd "btrfs subvolume delete" allow_cmd "${sudo_prefix}btrfs subvolume delete"
;; ;;
-i|--info) -i|--info)
allow_cmd "btrfs subvolume find-new" allow_cmd "${sudo_prefix}btrfs subvolume find-new"
allow_cmd "btrfs filesystem usage" allow_cmd "${sudo_prefix}btrfs filesystem usage"
;; ;;
--snapshot) --snapshot)
allow_cmd "btrfs subvolume snapshot" allow_cmd "${sudo_prefix}btrfs subvolume snapshot"
;; ;;
--send) --send)
allow_cmd "btrfs send" allow_cmd "${sudo_prefix}btrfs send"
;; ;;
--receive) --receive)
allow_cmd "btrfs receive" allow_cmd "${sudo_prefix}btrfs receive"
;; ;;
*) *)
@ -149,6 +146,9 @@ while [[ "$#" -ge 1 ]]; do
shift shift
done done
allow_cmd "${sudo_prefix}btrfs subvolume show"; # subvolume queries are always allowed
allow_cmd "${sudo_prefix}btrfs subvolume list"; # subvolume queries are always allowed
# remove leading "|" on alternation lists # remove leading "|" on alternation lists
allow_list=${allow_list#\|} allow_list=${allow_list#\|}
allow_exact_list=${allow_exact_list#\|} allow_exact_list=${allow_exact_list#\|}