Commit Graph

2772 Commits

Author SHA1 Message Date
Thomas Waldmann 9de07ebd46
update "modern" error RCs (docs and code) 2024-02-13 22:58:02 +01:00
Thomas Waldmann 1b09d0efd7
BORG_EXIT_CODES=modern can be set to get more specific process exit codes
If not set, it will default to "legacy" (always return 2 for errors).

This commit only changes the Error exception class and its subclasses.

The more specific exit codes need to be defined via .exit_mcode in the subclasses.
2024-02-13 19:53:17 +01:00
Thomas Waldmann 48afc4c519
requirements are defined in pyproject.toml 2024-02-09 17:37:42 +01:00
TW a4c8d52ca0
Merge pull request #8086 from ThomasWaldmann/index-check-value-errors-master
check: fix return code for index entry value discrepancies
2024-02-09 02:29:46 +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 f43c1f56e9
check: fix return code for index entry value discrepancies
Also: use ERROR loglevel for these (not WARNING).

A different amount of index entries was already logged as error
and led to "error_found = True" in repository.check.

Different values in the rebuilt index vs. the on-disk index were
only logged on warning level, but did not lead to error_found = True.

Guess there is no reason why these should not be errors and lead to
error_found = True, so this was fixed in this commit.

Minor related change: change report_error function args, so it can be
called like logger.error - including giving a format AND args.
2024-02-09 00:43:06 +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
Thomas Waldmann ba2e8f2dec
borg.logger: use same method params as python logging 2024-01-15 21:40:27 +01:00
TW 812eb352f6
Merge pull request #7955 from ThomasWaldmann/improve-session-key-gen-master
crypto: use a one-step kdf for session keys, fixes #7953
2024-01-04 18:42:22 +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 e1fbd7d42e
fix mypy complaints 2024-01-02 20:57:42 +01:00
Thomas Waldmann 6720ab3aab
move conftest.py to src/borg/testsuite, see #6386
there, it will be packaged and installed, so
that when one runs the testsuite after installing
the pypi package, it will find the conftest.py.
2024-01-02 20:39:14 +01:00
Thomas Waldmann 73284db53f
PATH: do not accept empty strings, fixes #4221 2024-01-02 19:17:55 +01:00
Thomas Waldmann a4602c6f61
remove unused hkdf_hmac_sha512 and related tests 2023-12-02 20:35:14 +01:00
Thomas Waldmann 64ce6d5923
crypto: use a one-step kdf for session keys, fixes #7953
also:
- fixes, simplifies, speeds up _get_session_key
- convert sessionid memoryview to bytes before calling _get_cipher,
to avoid TypeError in (crypt_key + sessionid + domain) operation.
- add docstring and comments
2023-12-02 20:33:07 +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 2d86b7e1ac
add type annotation for mypy 2023-11-18 18:31:43 +01:00
Thomas Waldmann 046f9fe392
LockRoster.modify: no KeyError if element was already gone, fixes #7937
The intention of LockRoster.modify(key, REMOVE) is to remove self.id.

Using set.discard will just ignore it if self.id is not present there anymore.

Previously, using set.remove triggered a KeyError that has been frequently
seen in tracebacks of teardowns involving Repository.__del__ and Repository.__exit__.

I added a REMOVE2 op to serve one caller that needs to get the KeyError if
self.id was not present.

Thanks to @herrmanntom for the workaround!
2023-11-18 17:39:30 +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
TW e431b838f4
Merge pull request #7910 from ThomasWaldmann/fix-shadow-index-master
Fix shadow index (master)
2023-11-05 20:17:48 +01:00
TW fba3e388aa
Merge pull request #7909 from ThomasWaldmann/sort-by-aliases-master
--sort-by: support "archive" as alias of "name", fixes #7873
2023-11-05 19:08:25 +01:00
Thomas Waldmann 57f3dd1dae
check --repair: recreate shadow index, see #6687
before this fix, borg check --repair just created an
empty shadow index, which can lead to incomplete
entries if entries are added later.

and such incomplete (but present) entries can lead to
compact_segments() resurrecting old PUTs by accidentally
dropping related DELs.
2023-11-05 18:45:22 +01:00
Thomas Waldmann 7892e4212b
check --repair: test if shadow index is recreated
still failing here, because it is not.
2023-11-05 18:41:31 +01:00
Thomas Waldmann 5d28992b51
shadow index: add more comments 2023-11-05 18:30:00 +01:00
Thomas Waldmann 3ba533ac50
shadow index updates: simplify and more comments
no functional change here.
2023-11-05 18:28:48 +01:00
Thomas Waldmann 6d9513f507
update shadow index when doing a double-put, fixes #5661
this fixes the test added in previous commit (avoids
that the PUT reappears after index rebuild).
2023-11-05 18:25:06 +01:00
Thomas Waldmann 3b1c0df7c8
test the shadowing-by-double-put behaviour, see #5661
the new test is currently failing due to a bug in the
repository code.
2023-11-05 18:22:57 +01:00
Thomas Waldmann fa1e9df0d1
--sort-by: support "archive" as alias of "name", fixes #7873 2023-11-05 18:05:27 +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 f86a13c438
fix invalid pattern argument error msg 2023-11-05 17:54:07 +01:00
Felix Schwarz c350c1b36d include unistd.h in _chunker.c
With Python 3.13, Python.h no longer includes the <unistd.h> standard header file:
https://docs.python.org/3.13/whatsnew/3.13.html#id8
2023-11-05 11:48:16 +01:00
Thomas Waldmann f0e9999768
zlib legacy decompress: fix tests 2023-10-24 23:33:42 +02:00
Thomas Waldmann 0ac525bb05
zlib legacy decompress: call check_fix_size method
so we also have the decompressed size in the metadata.
2023-10-24 19:45:21 +02:00
Thomas Waldmann 0cfdf6da91
zlib legacy decompress: return meta dict, fixes #7883
for the other compression methods, this is done in
the base class, but the zlib legacy does not call
that method as it also removes the header bytes,
which zlib legacy does not have.
2023-10-24 19:37:24 +02:00
Thomas Waldmann b78f330024
mypy: ignore attr-defined for errno.ENOATTR/ENODATA 2023-10-10 20:50:25 +02:00
TW 8fc0944950
Merge pull request #7830 from ThomasWaldmann/typed-repoobjs
replace TAMs by typed repo objects, fixes #7670
2023-09-30 21:46:51 +02:00
Thomas Waldmann cdcab4df68
allow msgpack 1.0.7 2023-09-28 14:31:03 +02:00
Thomas Waldmann d1fde11645
tests: borg check must not add a spoofed archive to manifest
also: do a small optimisation in borg check:

if the type of the repo object is not ROBJ_ARCHIVE_META, we
can skip the object, it can not contain valid archive meta data.

if the type is correct, this is already a sufficient check, so
we can be quite sure that there will be valid archive metadata
in the object.
2023-09-24 20:10:58 +02:00
Thomas Waldmann 6b4697b479
tests: borg check notices/repairs a spoofed manifest 2023-09-24 20:10:57 +02:00
Thomas Waldmann 170380c657
raise IntegrityError if ro_type is not as expected 2023-09-24 20:10:56 +02:00
Thomas Waldmann cb4676048a
remove remainders of TAM support 2023-09-24 20:10:54 +02:00
Thomas Waldmann 1cf62d8fc7
remove manifest TAMs 2023-09-24 20:10:53 +02:00
Thomas Waldmann 6a68ad5cd6
remove archive TAMs 2023-09-24 20:10:51 +02: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 0fcd3e9479
add_chunk: remove overwrite parameter 2023-09-23 00:10:35 +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 2195558eea
fix post-test permission issues 2023-09-20 22:45:57 +02:00
Thomas Waldmann 12e224613e
test_is_slow_msgpack: skip test on expected slow msgpack environments 2023-09-14 14:47:30 +02:00
Thomas Waldmann 95e75b90f1
allow msgpack 1.0.6 (which has py312 wheels), fixes #7810 2023-09-14 13:47:31 +02:00
Thomas Waldmann bc9ce99e9b
allow msgpack 1.0.6(rc1) 2023-09-14 04:08:25 +02:00
Thomas Waldmann 1ed7f29572
avoid tarfile deprecation warning for py312 2023-09-14 03:04:36 +02:00
Thomas Waldmann 55f0798b15
fix src code formatting
not sure why this changed!?
2023-09-05 00:34:03 +02:00
Thomas Waldmann 98796a2f0d
replace flake8 by ruff 2023-09-04 22:15:42 +02:00
Thomas Waldmann a0f5264cbd
rlist: remove support for {tam} placeholder
archives are now always TAM-authenticated.
2023-09-03 22:27:24 +02:00
Thomas Waldmann 2d78fa89a5
always implicitly require archive TAMs
they must be there since the upgrade to borg 1.2.6 (or other
borg versions that also have a fix for CVE-2023-36811).
2023-09-03 22:02:35 +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 1338646b9d
check: improve logging for TAM issues, fixes #7797 2023-09-03 17:15:09 +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 56da398711
add tests for archive TAMs 2023-08-30 02:28:57 +02:00
Thomas Waldmann 5cd2060345
rebuild_refcounts: keep archive ID, if possible
rebuild_refcounts verifies and recreates the TAM.
Now it re-uses the salt, so that the archive ID does not change
just because of a new salt if the archive has still the same data.
2023-08-30 01:13:52 +02:00
Thomas Waldmann 95b5604422
TAM msgs: be more specific: archives vs. manifest 2023-08-30 00:58:03 +02:00
Thomas Waldmann b23e6cb73d
list: support {tam} placeholder. check archive TAM.
list: shows either "verified" or "none", depending on
whether a TAM auth tag could be verified or was
missing (old archives from borg < 1.0.9).

when loading an archive, we now try to verify the archive
TAM, but we do not require it. people might still have
old archives in their repos and we want to be able to
list such repos without fatal exceptions.
2023-08-30 00:58:02 +02:00
Thomas Waldmann 277b0b81a8
cache sync: check archive TAM 2023-08-30 00:58:00 +02:00
Thomas Waldmann 462c1bdf2e
check: rebuild_refcounts verify and recreate TAM
This part of the archive checker recreates the Archive
items (always, just in case some missing chunks needed
repairing).

When loading the Archive item, we now verify the TAM.
When saving the (potentially modified) Archive item,
we now (re-)generate the TAM.

Archives without a valid TAM are dropped rather than TAM-authenticated
when saving them. There shouldn't be any archives without a valid TAM:

- borg writes an archive TAM since long (1.0.9)
- users are expected to TAM-authenticate archives created
  by older borg when upgrading to borg 1.2.5.

Also:

Archive.set_meta: TAM-authenticate new archive

This is also used by Archive.rename and .recreate.
2023-08-30 00:57:33 +02:00
Thomas Waldmann bfead4b288
fixup with msgpack data types related fixes 2023-08-29 22:32:30 +02:00
Thomas Waldmann a2ee13fd34
check: rebuild_manifest must verify archive TAM 2023-08-29 21:10:32 +02:00
Thomas Waldmann aa5168a21e
use skipif_acls_not_working decorator for freebsd also
use platform-specific ACLs to check.
for unsupported platform, just return False.
2023-08-27 05:07:56 +02:00
Thomas Waldmann 9c1088c95c
linux: move ACL definitions to platform_linux test module
they are only used from there.
2023-08-27 05:06:17 +02:00
Thomas Waldmann 7f8eba4fbf
freebsd: add some ACL tests, fixes #7745
enable ACL support in freebsd vagrant machine's filesystem
2023-08-27 05:05:55 +02:00
Thomas Waldmann 836b517451
get_*_dir tests: use create=False
In these tests, we only compare paths, but we do not
need to create these paths for that. By not trying to
create them, we can avoid permission issues, e.g. under
fakeroot.
2023-08-27 03:23:50 +02:00
Thomas Waldmann 590b0c68e6
get_*_dir: add create=True kw argument
... and only call ensure_dir if create is True.
2023-08-27 03:15:12 +02:00
Thomas Waldmann b1c38ef23e
docs: improve rcreate / related repos docs 2023-08-24 12:42:24 +02:00
TW 1c8da8f98a
Merge pull request #7750 from ThomasWaldmann/fix-unreadable-parent-of-root-master
do not try to read parent dir of recursion root (master)
2023-07-30 01:18:27 +02:00
Ted Lawson f29fd80311
`platform_freebsd.py` dummy test file (#7748) 2023-07-30 01:17:56 +02:00
Thomas Waldmann 08e09999d9
remove unused "flags_root" open flags 2023-07-29 23:34:52 +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 3e640a38c0
add a test for unreadable parent dir, see #7746 2023-07-29 23:21:10 +02:00
bigtedde a09c8ad940 reverted import grouping 2023-07-29 09:40:24 -07:00
bigtedde dc83735e1d Merge remote-tracking branch 'upstream/master' into remove-BaseTestCase 2023-07-28 12:31:24 -07:00
bigtedde ffebd8b044 parametrize helper.py 2023-07-28 12:30:27 -07:00
bigtedde 8eed958829 seperated platform tests into seperate modules 2023-07-27 15:38:21 -07:00
bigtedde be53037b9d linux tests converted, renamed tests for consistency 2023-07-27 11:45:58 -07:00
bigtedde d2dd792164 mac and posix tests converted, removed BaseTestCase and unittest 2023-07-26 21:59:12 -07:00
bigtedde 7b753453e5 removed BaseTestCase from chunker_slow.py 2023-07-26 14:59:45 -07:00
bigtedde 67334c4e83 removed BaseTestCase from helpers.py 2023-07-26 14:50:52 -07:00
bigtedde d2f32986f3 removed TestCaseBase from testsuite/archive.py 2023-07-26 12:18:25 -07: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 35ac39b751
fix F401 2023-07-26 01:23:37 +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 b0497499cc
fix test_disk_full, fixes #7617
- master branch has different free space requirements from 1.2-maint,
  so we now use a 700MB filesystem
- used pytest.mark.parametrize for the test passes, kind of a progress
  display
- fix bug in rcreate call, encryption arg is needed
- fix bug in lock file cleanup
- added repo space cleanup
- updated docstring with current linux instructions (ubuntu)
- stopped using the "reserved" files, the "input" files are good enough
  to get some space freed.
-
2023-07-25 22:13:36 +02:00
Thomas Waldmann b97c3d3a55
simplify BaseTestCase.assert_raises 2023-07-25 15:14:46 +02:00
Thomas Waldmann a2e7854911
simplify changedir with @contextmanager 2023-07-25 15:12:32 +02:00
Thomas Waldmann 02fcabe31f
remove unused methods of BaseTestCase
also: clean up imports / comments
2023-07-25 15:07:53 +02:00
Thomas Waldmann b8a52a4769
tests: remove usage of environment_variable context manager
rather use monkeypatch.setenv/delenv.
2023-07-25 13:29:02 +02:00
Ted Lawson 2e59a702f6
`cmd` function now creates repo_location argument (#7734)
f'repo={repo_location}' moved to 'cmd' function
2023-07-24 23:54:47 +02:00
TW e1cd38a0df
Merge pull request #7722 from bigtedde/archiver-tests
Archiver folder - all tests converted from unittest to pytest
2023-07-23 15:07:03 +02:00
bigtedde 6f35f5b0a4 simplified remote repo check 2023-07-22 23:39:10 -07:00
bigtedde b8b80c5fef get_kind added to ArchiverSetup 2023-07-20 21:32:23 -07:00