Commit Graph

236 Commits

Author SHA1 Message Date
Vladimir Malinovskii 0c1df415d7
changed insufficiently reserved length for log message (#8152)
changed log message reserved length
2024-04-06 20:24:10 +02:00
Thomas Waldmann da285b15d2
benchmark: inherit options --rsh --remote-path, fixes #8099 2024-02-22 21:48:13 +01:00
Thomas Waldmann a13b5d1b79
benchmark: fix return value, fixes #8113 2024-02-21 13:20:55 +01:00
Thomas Waldmann e7bd18d7f3
create: add the slashdot hack, fixes #4685 2024-02-20 04:08:09 +01:00
Thomas Waldmann 334fbab897
refactor: use less binascii
our own hex_to_bin / bin_to_hex is more comfortable to use.

also: optimize remaining binascii usage / imports.
2024-02-19 02:16:19 +01:00
Thomas Waldmann 930ecd845a
fix CommandError args, fixes 8029
this is a fwd port from 1.4-maint and most of it was
already done in master, so only a minor change in here.
2024-02-18 14:18:33 +01:00
kmille 1f5cc355a3
borg with-lock: catch exception, print error msg, fixes #8022 2024-02-18 13:36:10 +01:00
Thomas Waldmann ed28eb9e03
fix: Error/CommandError have a output format for 1 argument 2024-02-18 04:40:32 +01:00
Thomas Waldmann a0a07ab464
use get_reset_ec to internally re-init ec/warnings
if we do multiple calls to Archiver.do_something(),
we need to reset the ec / warnings after each call,
otherwise they will keep growing (in severity, in length).
2024-02-17 22:37:44 +01:00
Thomas Waldmann abe6545853
do not return the rc from Archiver methods
this is not needed and getting rid of it makes
the code / behaviour simpler to understand:

if a fatal error is detected, we throw an exception.

if we encounter something warning worthy, we emit and collect the warning.

in a few cases, we directly call set_ec to set the
exit code as needed, e.g. if passing it through
from a subprocess.

also:
- get rid of Archiver.exit_code
- assert that return value of archiver methods is None
- fix a print_warning call to use the correct formatting method
2024-02-17 22:07:47 +01:00
Thomas Waldmann 97dd287584
raise BackupOSError subclasses 2024-02-15 17:53:53 +01:00
Thomas Waldmann 4adc782100
print_warning*: support warning msgids, fixes #7080 2024-02-14 02:22:35 +01:00
Thomas Waldmann e8fa4986cc
BackupError->BackupWarning, BackupOSError->BackupOSWarning 2024-02-14 01:59:08 +01:00
Thomas Waldmann c704e5ea9e
new warnings infrastructure to support modern exit codes
- implement updating exit code based on severity, including modern codes
- extend print_warning with kwargs wc (warning code) and wt (warning type)
- update a global warnings_list with warning_info elements
- create a class hierarchy below BorgWarning class similar to Error class
- diff: change harmless warnings about speed to rc == 0
- delete --force --force: change harmless warnings to rc == 0

Also:

- have BackupRaceConditionError as a more precise subclass of BackupError
2024-02-14 01:26:12 +01:00
Thomas Waldmann 0504dee0d9
fix dealing with remote repo Locking Exceptions
previously, this was handled in RPCError handler and always resulted in rc 2.

now re-raise Lock Exceptions locally, so it gives rc 2 (legacy) or 7x (modern).
2024-02-13 23:33:30 +01:00
Thomas Waldmann cb8b718a96
refactor set_ec usage
- msgpack version check: raise Error instead of calling set_ec
2024-02-13 23:16:46 +01:00
Thomas Waldmann bec02a36c8
use print_warning also in borg delete ::archive --force --force 2024-02-13 23:13:25 +01:00
Thomas Waldmann 9de07ebd46
update "modern" error RCs (docs and code) 2024-02-13 22:58:02 +01:00
Thomas Waldmann 48afc4c519
requirements are defined in pyproject.toml 2024-02-09 17:37:42 +01:00
TW 03e4494d84
Merge pull request #8084 from ThomasWaldmann/init-message-master
init: better borg key export instructions
2024-02-09 02:29:32 +01:00
Thomas Waldmann 08bf0f741c
init: better borg key export instructions 2024-02-09 00:33:06 +01:00
Thomas Waldmann b6a23ee1bc
implement "borg version", fixes #7829
Additional new command "borg -r <REPO> version" which shows client and server version.
2024-02-09 00:16:29 +01:00
kmille 865de9fcee
improve docs for borg with-lock (#8024)
docs: add example for borg with-lock
2024-01-03 23:42:29 +01:00
Thomas Waldmann 73284db53f
PATH: do not accept empty strings, fixes #4221 2024-01-02 19:17:55 +01:00
Thomas Waldmann fe17ce2bba
fix typos
Thanks go to:
Author: Andrea Gelmini <andrea.gelmini@gelma.net>
2023-12-01 21:58:26 +01:00
Thomas Waldmann f3ddaaf001
create --*-from-command: run subcommands with a clean environment, fixes #7916
When borg invokes a system command, it needs to prepare the environment
for that. This is especially important when using a pyinstaller-made
borg fat binary that works with a modified env var LD_LIBRARY_PATH -
system commands may crash with that.

borg already had calls to prepare_subprocess_env at some places (e.g.
when invoking ssh for the remote repo connection), but they were
missing for:

borg create --content-from-command ...
borg create --paths-from-command ...
2023-11-09 00:04:03 +01:00
Thomas Waldmann 77cf77ec38
fix rc and msg if arg parsing throws an exception, fixes #7885
get_args() exception handling before this fix only dealt with
subclasses of "Error", but we have to expect other exceptions
there, too.

In any case, if we have some fatal exception here, we must
terminate with rc 2.

ArgumentTypeError: emit a short error message - usually this is
a user error, invoking borg in a wrong way.

Other exceptions: full info and traceback.
2023-11-05 17:58:02 +01:00
Thomas Waldmann 1b6f928917
ro_type: typed repo objects, see #7670
writing: put type into repoobj metadata
reading: check wanted type against type we got

repoobj metadata is encrypted and authenticated.
repoobj data is encrypted and authenticated, also (separately).
encryption and decryption of both metadata and data get the
same "chunk ID" as AAD, so both are "bound" to that (same) ID.

a repo-side attacker can neither see cleartext metadata/data,
nor successfully tamper with it (AEAD decryption would fail).

also, a repo-side attacker could not replace a repoobj A with a
differently typed repoobj B without borg noticing:
- the metadata/data is cryptographically bound to its ID.
  authentication/decryption would fail on mismatch.
- the type check would fail.

thus, the problem (see CVEs in changelog) solved in borg 1 by the
manifest and archive TAMs is now already solved by the type check.
2023-09-24 20:10:50 +02:00
Thomas Waldmann 15c24cbe7e
recreate: remove --recompress option
For many use cases, the repo-wide "rcompress" is more efficient.

Also, recreate --recompress calls add_chunk with overwrite=True,
which is unsupported with the AdHocCache.
2023-09-23 00:01:39 +02:00
Thomas Waldmann 1ed7f29572
avoid tarfile deprecation warning for py312 2023-09-14 03:04:36 +02:00
Thomas Waldmann 21d4407170
always implicitly require manifest TAMs
remove a lot of complexity from the code that was just there to
support legacy borg versions < 1.0.9 which did not TAM authenticate
the manifest.

since then, borg writes TAM authentication to the manifest,
even if the repo is unencrypted.
if the repo is unencrypted, it did not check the somehow pointless
authentication that was generated without any secret, but
if we add that fake TAM, we can also verify the fake TAM.

if somebody explicitly switches off all crypto, they can not
expect authentication.

for everybody else, borg now always generates the TAM and also
verifies it.
2023-09-03 22:01:46 +02:00
Thomas Waldmann 32d7222e67
docs: remove zstd compat hint
borg2 repos are not compatible with borg1 anyway,
so no need to mention that.
2023-09-02 14:30:34 +02:00
Thomas Waldmann b1c38ef23e
docs: improve rcreate / related repos docs 2023-08-24 12:42:24 +02:00
Thomas Waldmann c99b849abe
create: do not try to read parent dir of recursion root, fixes #7746 2023-07-29 23:31:16 +02:00
Thomas Waldmann 5013121bd8
fix E501 2023-07-26 01:24:20 +02:00
Thomas Waldmann 6151b369c4
fix E741 2023-07-26 01:24:00 +02:00
Thomas Waldmann 3017701958
simplify flake8 configuration
we use black since a while, so some stuff does not need to be ignored any more.
2023-07-25 23:56:31 +02:00
Thomas Waldmann 3051473168
BORG_WORKAROUNDS=authenticated_no_key to extract from authenticated repos without key, fixes #7700 2023-07-20 17:17:28 +02:00
Daniel Rudolf 2647673dc8
Docs: Improve `borg check` docs 2023-07-10 22:41:24 +02:00
Daniel Rudolf a661da13ee
Docs: Improve explanation of `borg check --max-duration`'s side effects 2023-07-06 00:42:57 +02:00
Daniel Rudolf 9d59146de4
Docs: Remove technical description from `borg check` docs 2023-07-06 00:19:48 +02:00
Daniel Rudolf 9edbf4e931
Docs: Rewrite `borg check` docs
Fixes #7578
2023-07-06 00:17:55 +02:00
Thomas Waldmann 420eae6138
benchmark cpu: use sanitized path, fixes #7654 2023-06-22 21:22:18 +02:00
Tarrailt 616d5e7330
Add --format option to `borg diff`, resolve issue #4634 (#7534)
diff: add --format option

also: refactoring/improvements of BaseFormatter
2023-06-11 22:41:36 +02:00
TW 4f76f595a9
Merge pull request #7635 from eoli3n/master
Improve patterns help
2023-06-10 14:39:31 +02:00
eoli3n 095d5f463b improve patterns help: added declarative includes sample 2023-06-10 14:00:06 +02:00
eoli3n ba922d2e0a improve patterns help: define a pattern style 2023-06-10 14:00:06 +02:00
eoli3n 9bbb38d9ab improve patterns help 2023-06-10 14:00:06 +02:00
Thomas Waldmann db96c0c487
subclass MakePathSafeAction from Highlander 2023-06-10 11:41:31 +02:00
Peter Gerber 438cf2e7ef
Sanitize paths during archive creation/extraction/...
Paths are not always sanitized when creating an archive and,
more importantly, never when extracting one. The following example
shows how this can be used to attempt to write a file outside the
extraction directory:

$ echo abcdef | borg create -r ~/borg/a --stdin-name x/../../../../../etc/shadow archive-1 -
$ borg list -r ~/borg/a archive-1
-rw-rw---- root   root          7 Sun, 2022-10-23 19:14:27  x/../../../../../etc/shadow
$ mkdir borg/target
$ cd borg/target
$ borg extract -r ~/borg/a archive-1
x/../../../../../etc/shadow: makedirs: [Errno 13] Permission denied: '/home/user/borg/target/x/../../../../../etc'

Note that Borg tries to extract the file to /etc/shadow and the
permission error is a result of the user not having access.

This patch ensures file names are sanitized before archiving.
As for files extracted from the archive, paths are sanitized
by making all paths relative, removing '.' elements, and removing
superfluous slashes (as in '//'). '..' elements, however, are
rejected outright. The reasoning here is that it is easy to start
a path with './' or insert a '//' by accident (e.g. via --stdin-name
or import-tar). '..', however, seem unlikely to be the result
of an accident and could indicate a tampered repository.

With paths being sanitized as they are being read, this "errors"
will be corrected during the `borg transfer` required when upgrading
to Borg 2. Hence, the sanitation, when reading the archive,
can be removed once support for reading v1 repositories is dropped.
V2 repository will not contain non-sanitized paths. Of course,
a check for absolute paths and '..' elements needs to kept in
place to detect tempered archives.

I recommend treating this as a security issue. I see the following
cases where extracting a file outside the extraction path could
constitute a security risk:

a) When extraction is done as a different user than archive
creation. The user that created the archive may be able to
get a file overwritten as a different user.
b) When the archive is created on one host and extracted on
another. The user that created the archive may be able to
get a file overwritten on another host.
c) When an archive is created and extracted after a OS reinstall.
When a host is suspected compromised, it is common to reinstall
(or set up a new machine), extract the backups and then evaluate
their integrity. A user that manipulates the archive before such
a reinstall may be able to get a file overwritten outside the
extraction path and may evade integrity checks.

Notably absent is the creation and extraction on the same host as
the same user. In such case, an adversary must be assumed to be able
to replace any file directly.

This also (partially) fixes #7099.
2023-06-07 23:23:53 +02:00