use hmac in balanced preferred content

This deals with the possible security problem that someone could make an
unusually low UUID and generate keys that are all constructed to hash to
a number that, mod the number of repositories in the group, == 0.
So balanced preferred content would always put those keys in the
repository with the low UUID as long as the group contains the
number of repositories that the attacker anticipated.
Presumably the attacker than holds the data for ransom? Dunno.

Anyway, the partial solution is to use HMAC (sha256) with all the UUIDs
combined together as the "secret", and the key as the "message". Now any
change in the set of UUIDs in a group will invalidate the attacker's
constructed keys from hashing to anything in particular.

Given that there are plenty of other things someone can do if they can
write to the repository -- including modifying preferred content so only
their repository wants files, and numcopies so other repositories drom
them -- this seems like safeguard enough.

Note that, in balancedPicker, combineduuids is memoized.
This commit is contained in:
Joey Hess 2024-08-10 16:32:54 -04:00
parent bde58e6c71
commit bd5affa362
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
10 changed files with 68 additions and 47 deletions

View file

@ -1,6 +1,6 @@
{- git-annex repo groups
-
- Copyright 2012, 2019 Joey Hess <id@joeyh.name>
- Copyright 2012-2024 Joey Hess <id@joeyh.name>
-
- Licensed under the GNU AGPL version 3 or higher.
-}
@ -15,6 +15,7 @@ module Types.Group (
import Types.UUID
import Utility.FileSystemEncoding
import Annex.Balanced
import qualified Data.Map as M
import qualified Data.Set as S
@ -32,7 +33,8 @@ toGroup = Group . encodeBS
data GroupMap = GroupMap
{ groupsByUUID :: M.Map UUID (S.Set Group)
, uuidsByGroup :: M.Map Group (S.Set UUID)
, balancedPickerByGroup :: M.Map Group BalancedPicker
}
emptyGroupMap :: GroupMap
emptyGroupMap = GroupMap M.empty M.empty
emptyGroupMap = GroupMap M.empty M.empty M.empty