Commit Graph

146 Commits

Author SHA1 Message Date
Thomas Waldmann 43a20b052e
add ConnectionBrokenWithHint for BrokenPipeErrors and similar, see #7016
no traceback, but error message and specific exit code.
2024-02-20 00:17:55 +01:00
Thomas Waldmann 45815554ce
check_can_create_repository: deal with PermissionErrors, see #7016
borg init calls this. If there is a PermissionError, it is
usually fs permission issue at path or its parent directory.

Don't give a traceback, but rather an error msg and a specific exit code.
2024-02-20 00:07:43 +01:00
Thomas Waldmann ab0b111af0
give clean error msg for invalid nonce file, see #7967
this is a fwd port from 1.4-maint. as we don't have nonce files
any more in master, only the generally useful stuff has been ported.

- add Error / ErrorWithTraceback exception classes to RPC layer.
- add hex_to_bin helper
2024-02-18 14:47:52 +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 9de07ebd46
update "modern" error RCs (docs and code) 2024-02-13 22: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 5013121bd8
fix E501 2023-07-26 01:24:20 +02:00
Thomas Waldmann 3aec98ada9
remote logging/progress: use callback to send queued records, fixes #7662 2023-06-22 20:09:29 +02:00
Thomas Waldmann ae97584218
fix logging, add some comments
shutting down logging is problematic as it is global
and we do multi-threaded execution, e.g. in tests.

thus, rather just flush the important loggers and keep
them alive.
2023-06-06 21:13:31 +02:00
Thomas Waldmann ffc59dd071
implement unix domain (ipc) socket support
server (listening) side:
borg serve --socket  # default location
borg serve --socket=/path/to/socket

client side:
borg -r socket:///path/to/repo create ...
borg --socket=/path/to/socket -r socket:///path/to/repo ...

served connections:
- for ssh: proto: one connection
- for socket: proto: many connections (one after the other)

The socket has user and group permissions (770).

skip socket tests on win32, they hang infinitely, until
github CI terminates them after 60 minutes.

socket tests: use unique socket name

don't use the standard / default socket name, otherwise tests
running in parallel would interfere with each other by using
the same socket / the same borg serve process.

write a .pid file, clean up .pid and .sock file at exit

add stderr print for accepted/finished socket connection
2023-06-06 21:12:54 +02:00
Thomas Waldmann 48c7879887
RemoteRepository: add .close method
- tears down logging (so no new log output is generated afterwards)
- sends all queued log output
- then returns

also: make stdin_fd / stdout_fd instance variables
2023-05-29 22:40:55 +02:00
Thomas Waldmann ac4b5c35da
borg serve: shutdown server after sending all queued log records 2023-05-29 22:40:52 +02:00
Thomas Waldmann e351e67aee
RepositoryServer: do not use stderr for logging, see #7604
Instead, install a handler that sends the LogRecord dicts to a queue.
That queue is then emptied in the borg serve main loop and
the LogRecords are sent msgpacked via stdout to the client,
similar to the RPC results.

On the client side, the LogRecords are recreated from the
received dicts and fed into the clientside logging system.

As we use msgpacked LogRecord dicts, we don't need JSON for
this purpose on the borg serve side any more.
On the client side, the LogRecords will then be either formatted
as normal text or as JSON log output (by the clientside log
formatter).
2023-05-29 22:40:42 +02:00
Thomas Waldmann 89297398c4
fix borg.remote._resolve_path
this used to call get_base_dir (and would have needed
legacy=True now to work like expected).

rather implemented the desired behaviour locally and
got rid of the legacy call (which was a bit strange
anyway as it also considered BORG_BASE_DIR, which is
unexpected when resolving ~).
2023-05-24 17:01:45 +02:00
Thomas Waldmann 90c6b7f794
remote exceptions: simplify sysinfo processing
in the sysinfo function, there is a way to suppress
all sysinfo output via an env var and just return an
empty string.

so we can expect it is always in unpacked, but it
might be the empty string.
2023-05-24 15:30:20 +02:00
Thomas Waldmann 2331341b74
simplify handle_error 2023-05-24 14:38:30 +02:00
Thomas Waldmann 4b796a7337
remote repos: remove support for borg < 1.1.0 ($LOG, logging setup)
log output:

always expect json, remove $LOG format support.

we keep limited support for unstructured format also,
just not to lose anything from remote stderr.
2023-05-24 14:38:24 +02:00
Thomas Waldmann 51177b9f06
remote repos: remove support for borg < 1.1.0 (exceptions)
exception infos:
ancient borg gave only limited infos about exceptions,
but recent ones give more.
2023-05-24 02:13:30 +02:00
Thomas Waldmann 591d8efac4
remote repos: remove support for borg < 1.1.0 (rpc data format, version)
rpc format:
ancient borg used tuples in the rpc protocol,
but recent ones use easier-to-work-with dicts.

version info:
we expect dicts with server/client version now.
2023-05-24 02:13:01 +02:00
Thomas Waldmann e02d9edc34
remove nonce management, related repo methods
not needed for borg2 repos (we derive a new session key for each borg
invocation and start counting from 0).

also not needed for borg 1.x repos because we only read them (borg transfer)
and won't write new encrypted data to them.
2023-05-11 17:51:49 +02:00
Paul D 253d8e8d4e Docs grammar fixes
joined split infinitives, and relocated adverbs appropriately.
2022-12-29 22:26:54 +00:00
Thomas Waldmann 8747644540
remove --save-space
this option did not change behaviour since longer,
we only had kept it for API compatibility.

as a borg2 repo server won't have old clients talking to it,
we can safely remove this everywhere now.
2022-12-17 16:48:54 +01:00
Thomas Waldmann c326b9d160 fix repository.scan api minimum requirement 2022-10-02 23:47:50 +02:00
Thomas Waldmann c4e54ca44e repository.scan: use same end_segment within same scan
achieved by putting it into the state that is now used instead of the marker.
2022-09-19 21:14:25 +02:00
Thomas Waldmann b28d6ee657 recompress: only read metadata to check for ctype/clevel 2022-09-08 20:47:40 +02:00
Thomas Waldmann 06eab6a228 RepositoryCache: cache complete and meta-only chunks separately 2022-09-08 19:38:18 +02:00
Thomas Waldmann 106abbe4d9 new read_data param for repository.get() and .get_many()
True (default): return full chunk (client can decrypt meta and data)

False: return enough so client can decrypt only the meta
2022-09-08 18:31:56 +02:00
Thomas Waldmann 4c9ed2a6c6 refactor compressors to new api
legacy: add/remove ctype/clevel bytes prefix of compressed data

new: use a separate metadata dict

compressors: use an int as ID, not a len 1 bytestring
2022-09-07 19:23:47 +02:00
Thomas Waldmann fa986a9f19 repoobj: add a layer to format/parse repo objects
borg < 2:

obj = encrypted(compressed(data))

borg 2:

obj = enc_meta_len32 + encrypted(msgpacked(meta)) + encrypted(compressed(data))

handle compr / decompr in repoobj

move the assert_id call from decrypt to RepoObj.parse

also:
- for AEADKeyBase, add a dummy assert_id (not needed here)
- only test assert_id for other if not AEADKeyBase instance
- remove test_getting_wrong_chunk. assert_id is called elsewhere
  and is not needed any more anyway with the new AEAD crypto.
- only give manifest (includes key, repo, repo_objs)
- only return manifest from Manifest.load (includes key, repo, repo_objs)
2022-09-04 00:49:38 +02:00
Thomas Waldmann 90ca04f535 repository api: flags support, fixes #6982
- .list: only return IDs for objects where flags & mask == value.
- .flags(_many) (new) to set/query flags
2022-08-22 18:16:59 +02:00
Thomas Waldmann 0ab82d57e4 ctrl-c must not kill the ssh subprocess, fixes #6912 2022-08-06 23:27:00 +02:00
Thomas Waldmann 47c2672a64 ssh:// URLs: remove support for /~otheruser/, see #6855
If you used this, just replace it by:

ssh://user@host:port/home/otheruser/
2022-07-15 16:02:45 +02:00
Thomas Waldmann b8e48c5036 mypy: fixes / annotations 2022-07-15 14:54:48 +02:00
TW d5c91cd37b
Merge pull request #6859 from ThomasWaldmann/remove-attic-stuff-borg2
remove remainders of attic legacy
2022-07-13 18:17:47 +02:00
Thomas Waldmann 7bc7f01342 remove remainders of attic legacy
we expect that everybody has upgraded to borg
using borg 1.2.x or older, thus we do not need
to care about attic repos any more in borg2.
2022-07-13 16:55:29 +02:00
Thomas Waldmann 1de12eacb7 we remove scp style, also remove it for tilde expansion, fixes #6856 2022-07-13 16:42:46 +02:00
Thomas Waldmann 890d5950e7 move debug commands to archiver.debug 2022-07-09 15:13:12 +02:00
Thomas Waldmann 7957af562d blacken all the code
https://black.readthedocs.io/
2022-07-06 16:34:38 +02:00
Thomas Waldmann b0b5a2fd27 add repository.info(), giving some basic repo infos
there was no way to tell the repository version for a remote repo.
borg 2 needs that to reject doing most operations with an old repo,
except the stuff needed for borg transfer.
2022-06-30 23:55:51 +02:00
Thomas Waldmann 3fbb297fd7 compact: remove --cleanup-commits
this was a one-time fix only needed for borg 1.2.

users are expected to use borg 1.2 to cleanup the commits.
2022-06-26 00:07:07 +02:00
Thomas Waldmann 8e87f1111b cleanup msgpack related str/bytes mess, fixes #968
see ticket and borg.helpers.msgpack docstring.

this changeset implements the full migration to
msgpack 2.0 spec (use_bin_type=True, raw=False).

still needed compat to the past is done via want_bytes decoder in borg.item.
2022-06-09 17:57:28 +02:00
Thomas Waldmann f8dbe5b542 cleanup msgpack related str/bytes mess, see #968
see ticket and borg.helpers.msgpack docstring.
2022-06-09 17:57:28 +02:00
Thomas Waldmann cc3b5c062c remove algorithms package, move checksums module to borg package 2022-03-17 00:24:49 +01:00
Thomas Waldmann cbeef56454 pyupgrade --py38-plus ./**/*.py 2022-02-27 20:11:56 +01:00
Thomas Waldmann b292e158a6 rename truncate_and_unlink to safe_unlink
it usually does not truncate any more,
only under "disk full" circumstances and only if there is only one hardlink.
2022-02-15 21:08:34 +01:00
Thomas Waldmann c4116b26c8 Location: fix bad naming: rename .orig -> .processed
- .raw is the unprocessed location (as given by user / env).
- .processed is the processed location (after placeholder replacement).
2022-01-31 21:55:12 +01:00
Thomas Waldmann 6b838febe8 s/remote_(buffer|ratelimit)/upload_(buffer/ratelimit)/g 2021-04-16 15:48:10 +02:00
axapaxa b291b91962
Add remote upload buffer (--remote-buffer) (#5574)
add remote upload buffer (--remote-buffer)

- added new option --remote-buffer
- allow to_send to grow to selected size
- don't grow if wait is specified
- fill pipe on any command (including 'async_response')
- add new option to docs
- create EfficientBytesQueue to prevent recreation of buffer each time we send something
- add tests for EfficientBytesQueue
2021-01-03 17:37:16 +01:00
Thomas Waldmann 264c799c50 use allow/deny list wording 2020-07-07 23:01:55 +02:00
Thomas Waldmann c531901763 --umask is for the local borg process only, fixes #4947
The umask value is NOT transmitted from client to server any more,
so the borg client can not influence the borg server umask any more.

If one wants to have a specific umask on the server side, one needs to
use a ssh forced command in .ssh/authorized_keys file.

OTOH, as the default value is 077 (in general, for client as well as for
the server) and the server does not take the value from the client any more,
there usually should be no need to give it on the server side, IF you are
happy with the default value.
2020-06-14 18:35:03 +02:00