Commit Graph

146 Commits

Author SHA1 Message Date
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 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 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 277b0b81a8
cache sync: check archive TAM 2023-08-30 00:58:00 +02:00
Thomas Waldmann 5013121bd8
fix E501 2023-07-26 01:24:20 +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 ec1f2dfbf1
--files-cache=size: fix crash, fixes #7658 2023-06-29 23:09:24 +02:00
Thomas Waldmann 989b0a2847
use correct path for security dir when accessing legacy repos (v1)
while on macOS the new and old security dir location is the same path,
this is not the case on e.g. Linux, it could move from .config/borg/security to
.local/share/borg/security .

See #5760.
2023-05-19 21:12:59 +02:00
Divyansh Singh 7dd186ccf3 feat: add cache dir to --debug 2023-02-26 23:48:35 +05:30
Thomas Waldmann b92f4aa487
remove --consider-part-files, related stats code, update docs
we now just treat that one .borg_part file we might have inside
checkpoint archives as a normal file.

people can recognize via the file name it is a partial file.

nobody cares for statistics of checkpoint files and the final
archive now does not contain any partial files any more, thus
no needs to maintain statistics about count and size of part
files.
2023-02-01 13:04:18 +01:00
TW be1048abfe
Merge pull request #7277 from jdchristensen/chunks-cache-output
cache.py: be less verbose during cache sync
2023-01-19 02:45:50 +01:00
Thomas Waldmann 1843990172
use os.replace rather than os.rename
more consistent behaviour on all OSes, incl. windows.
2023-01-19 01:57:03 +01:00
Dan Christensen 530bd4c298 cache.py: consistenly use "chunks index" 2023-01-18 19:51:01 -05:00
Dan Christensen 6f7bc89627 cache.py: minor updates to output 2023-01-18 16:59:44 -05:00
Dan Christensen 7dad4a6992 cache.py: be less verbose during cache sync 2023-01-17 15:21:18 -05:00
Thomas Waldmann 491f898612
borg2 archive names and comments are always pure unicode 2023-01-16 17:45:48 +01:00
Thomas Waldmann cf333cef91 upgrader fixes for new api 2022-09-07 20:27:03 +02:00
Thomas Waldmann 1e156ca02b fix upgrader 2022-09-07 19:23:11 +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 9beaced33c move manifest module from helpers to borg.manifest 2022-08-13 21:55:12 +02:00
Thomas Waldmann fb74fdb710 massively increase per archive metadata stream size limit, fixes #1473
implemented by introducing one level of indirection, the limit is now
very high, so it is not practically relevant any more.

we always use the indirection (storing the metadata stream chunk ids list not
directly into the archive item, but into some repo objects referenced by the new
ArchiveItem.item_ptrs list).

thus, the code behaves the same for all archive sizes.
2022-08-06 19:01:41 +02:00
Thomas Waldmann b8e48c5036 mypy: fixes / annotations 2022-07-15 14:54:48 +02:00
Thomas Waldmann 2d2f468410 remove legacy_cleanup
not needed any more.
2022-07-13 17:06:52 +02:00
Thomas Waldmann 7957af562d blacken all the code
https://black.readthedocs.io/
2022-07-06 16:34:38 +02:00
Thomas Waldmann 31a081f695 simplify stats output
also:
- move stats related stuff to Statistics class
- repo ops give repo / overall stats
- archive ops give archive stats
- adapt tests
2022-06-23 16:00:12 +02:00
Thomas Waldmann e0c64629d1 Merge branch 'master' into borg2
strange conflicts, automated patches seemed to not have applied correctly.
also had to fix some stuff manually, tests were failing.
2022-06-23 11:25:01 +02:00
Thomas Waldmann c01f3527e5 fix linter errors 2022-06-14 15:42:30 +02:00
Thomas Waldmann 49adb77157 calc_stats: deduplicated size now, was deduplicated csize
also: remove pre12_meta cache
2022-06-12 17:15:13 +02:00
Thomas Waldmann 19dfbe5c5c compute the deduplicated size before compression
so we do not need csize for it.
2022-06-12 17:15:13 +02:00
Thomas Waldmann 1fd571a4d0 fix comments 2022-06-12 17:15:13 +02:00
Thomas Waldmann 2c1f7951c4 remove csize from ChunkIndexEntry 2022-06-12 17:15:13 +02:00
Thomas Waldmann 0211948cac remove csize from summarize return tuple 2022-06-12 15:48:33 +02:00
Thomas Waldmann ace5957524 remove csize from item.chunks elements 2022-06-12 15:48:33 +02:00
Thomas Waldmann b9f9623a6d prepare to remove csize (set it to 0 for now) 2022-06-12 15:48:33 +02:00
Thomas Waldmann d3dfa3be30 use version 2 for new archives
but still be able to read v1 archives
for borg transfer.
2022-06-09 17:49:16 +02:00
Elmar Hoffmann c2317c4cce
make constants for files cache mode more clear (#6724)
* make constants for files cache mode more clear

Traditionally, DEFAULT_FILES_CACHE_MODE_UI and DEFAULT_FILES_CACHE_MODE
were - as the naming scheme implies - the same setting, one being the UI
representation as given to the --files-cache command line option and the
other being the same default value in the internal representation.

It happended that the actual value used in borg create always comes from
DEFAULT_FILES_CACHE_MODE_UI (because that does have the --files-cache
option) whereas for all other commands (that do not use the files cache) it
comes from DEFAULT_FILES_CACHE_MODE.

PR #5777 then abused this fact to implement the optimisation to skip loading
of the files cache in those other commands by changing the value of
DEFAULT_FILES_CACHE_MODE to disabled.
This however also changes the meaning of that variable and thus redesignates
it to something not matching the original naming anymore.

Anyone not aware of this change and the intention behind it looking at the
code would have a hard time figuring this out and be easily mislead.

This does away with the confusion making the code more maintainable by
renaming DEFAULT_FILES_CACHE_MODE to FILES_CACHE_MODE_DISABLED, making the
new intention of that internal default clear.

* make constant for files cache mode UI default match naming scheme
2022-05-30 14:01:19 +02:00
Thomas Waldmann 7903dad183 transfer: convert timestamps int/bigint -> msgpack.Timestamp, see #2323
Timestamp scales to 64 or 96bit serialization formats, that should be enough for everybody.

We use this in archived items and also in the files cache.
2022-05-18 14:20:01 +02:00
Thomas Waldmann 0e53dc040a api: enable giving already compressed data
the api already offered getting compressed data,
but not giving compressed data.

thus: cache.add_chunk and key.encrypt improved.
2022-05-03 04:15:01 +02:00
Thomas Waldmann 37430beda3 fix transaction rollback: use files cache filename as found in txn.active, fixes #6353 2022-04-18 09:03:37 +02:00
Thomas Waldmann d3b78a6cf5 minor key.encrypt api change/cleanup
we already have .decrypt(id, data, ...).
i changed .encrypt(chunk) to .encrypt(id, data).

the old borg crypto won't really need or use the id,
but the new AEAD crypto will authenticate the id in future.
2022-03-26 17:05:57 +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 25e27a1539 info: use a pre12-meta cache to accelerate stats for borg < 1.2 archives
first time borg info is invoked on a borg 1.1 repo, it can take
a rather long time computing and caching some stats values for
1.1 archives, which borg 1.2 archives have in their archive
metadata structure. be patient, esp. if you have lots of old
archives.

following invocations are much faster.
2022-02-14 18:00:02 +01:00
Romain Vimont 9ddcfaf4f7 info / create --stats: add --iec option
If --iec is passed, then sizes are expressed in powers of 1024
instead of 1000.
2021-04-28 15:17:40 +02:00
Thomas Waldmann 2211b840a3 verbose files cache logging via --debug-topic=files_cache, fixes #5659 2021-02-28 22:39:44 +01:00
Luke Dashjr dbbd3f1b63 Rather than error beginning a txn, create an empty files cache if it didn't exist before 2020-11-15 17:01:36 +00:00
Luke Dashjr a0322d241d Allow appending the files cache filename with BORG_FILES_CACHE_SUFFIX env var 2020-11-15 17:01:36 +00:00
Thomas Waldmann 9c3a572638 SecurityManager.known(): check all files, fixes #4614
Before this fix, because known() only checked the key-type file, the
location file could go missing without being automatically regenerated.

Now a save() is triggered if not all files are present.

(cherry picked from commit c68cad9727)
2019-08-09 15:05:30 +05:30
Thomas Waldmann 61b9283567 fix "all archives" stats considering part files, fixes #4329
archives with borg 1.2 metadata: quick, we have precomputed size data
in archive metadata and just need to sum up for all archives.

archives without borg 1.2 metadata: expensive, need to read all
archives' items metadata streams and sum up for all items.
2019-04-20 22:22:26 +02:00