hasher: optionally encrypt the checksum database

Aperta
#10,120 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 5 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
go

Direzione di ricerca

Start with backend/hasher/object.go and backend/hasher/kv.go to trace database lookups and prefix operations, then read backend/crypt/crypt.go for the exported crypt.NewCipher API. The issue proposes a separate encrypted database, a wrong-password verifier, and an encryptdb migration command; done means these protections and migration work without silently treating an unreadable database as an empty cache.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

enhancement hashing Remote: Crypt Remote: Hasher
Before you start
  • I have searched the forum and the existing issues and this hasn't already been requested.
  • I have checked the latest beta and this feature doesn't already exist.
Associated forum post URL

No response

rclone version
rclone v1.76.0-beta.10567.17df19341
- os/version: darwin 26.6.2 (64 bit)
- os/kernel: 25.6.0 (arm64)
- os/type: darwin
- os/arch: arm64 (ARMv8 compatible)
- go/version: go1.27.2
- go/linking: dynamic
- go/tags: cmount
What problem are you trying to solve?

hasher is the usual answer to "crypt has no checksums" (#3667): put a hasher in front of a crypt remote and it remembers the MD5s of the plaintext. But the database it keeps for that, <cache-dir>/kv/<remote>~hasher.bolt (named after the wrapped remote), stores everything in the clear:

key:    Music/Demos/song.wav
value:  gob(hashRecord{Fp: "<size>,<modtime>,-", Hashes: {md5: "9e107d9d…"}, Created: …})

The key is path.Join(f.Fs.Root(), remote), and the value is a gob-encoded hashRecord.

So for a crypt user, the hasher database is a plaintext index of the encrypted remote: every decrypted path, size, and modtime, plus the plaintext MD5 of every file. On my machine that's about 160,000 decrypted paths in one 91 MB file. The paths are the obvious leak. The hashes are the less obvious one. (#3667: "we'd probably want to encrypt them otherwise that is a definite info leak.")

The cache directory is easy to overlook. Nobody treats it as sensitive, and it can end up in backups or copies of a home directory. Crypt users have chosen to keep names and contents away from whoever can read the storage, and the hasher quietly gives both back to whoever can read the cache.

How do you think rclone should be changed to solve that?

Two new hasher options, db_password and db_password2 (salt), both IsPassword like crypt's. When they're set, the hasher encrypts its database.

Keys: crypt's standard name encryption, segment by segment. Each segment of the key is encrypted with EME, exactly as crypt's standard mode does for file names (crypt.NewCipher is already exported), and encoded with crypt's base64 option to keep keys short:

key:    ql2WaLdtsr9wInLWxJ8eCw/2NMk6dRiQjKp1sTH-26aTA/9lv5RZWRmRlAuFRiDj01yg

This has to be deterministic, and it can be: the hasher only ever looks records up by path, never by content, so a lookup encrypts the path it was given and does an exact get.

Encrypting each segment, rather than hashing the whole path, is what keeps the existing operations working. DirMove, Purge, and pruning all work on key prefixes:

https://github.com/rclone/rclone/blob/35a03a47e00e2cadec744f977e5fa9d851127016/backend/hasher/kv.go#L114-L117

Because each segment is encrypted independently, Music/Demos/ encrypts to the same prefix wherever it appears, so a directory move is still "rewrite every key under this prefix". A single HMAC of the full path would lose the prefix structure, and a directory rename would orphan every record under it. Using reversible encryption rather than a one-way hash also means dump and fulldump keep printing real paths for anyone with the password.

Values: the whole record sealed with secretbox (random nonce, as crypt uses for file contents). That covers the hashes, the fingerprint's size and modtime, and Created. Values don't need to be deterministic. Binding each value to its key (as associated data, or by sealing the key inside the record) stops records being swapped between paths. Moves then re-seal each value, which is cheap, since kvMove already rewrites every record it touches.

A separate database file. Use a different kv facility (e.g. hasher-enc), so the encrypted database is <remote>~hasher-enc.bolt and never mixes formats with an existing plaintext one.

Safety: a wrong password must not look like an empty cache

The dangerous failure here is silent. If the hasher can't read its records, every lookup is a miss, and with auto_size set, a miss means downloading the file to hash it again. With a large auto_size, that can mean downloading a whole remote. So:

  • Verifier record. On creation, store one fixed record sealed with the key. On start, open it, and if it doesn't decrypt, fail with "wrong db_password" instead of carrying on. This also catches two hasher remotes that wrap the same remote (and so share one database file) but were given different passwords.
  • Refuse to start next to an unmigrated plaintext database. If db_password is set, no encrypted database exists yet, but a plaintext one does, fail with a message pointing to the migration command (or telling the user to delete the old file if they really want to start over). Otherwise, turning the option on throws away every cached hash and, with auto_size, starts downloading again.
  • Migration command: rclone backend encryptdb hasher: reads every plaintext record, writes it to the encrypted database, verifies the count, and leaves deleting the plaintext file to the user.
What it doesn't hide

The same things crypt's file names don't: the number of records, the number of path segments, segment lengths rounded up to the EME block size, and the fact that two files in different folders share a name (deterministic per-segment encryption). The B-tree order is the order of the ciphertext, so it reveals nothing.

It protects the database file at rest, not a running rclone: anyone who can read rclone.conf (and its config password, if any) can decrypt it. That's the same trust boundary as crypt itself, which is the right one.

Alternatives considered
  • Encrypt the whole bolt file. bbolt works on a memory-mapped file with page-level random access and cross-process locking, so the file would have to be decrypted into memory on every open. That's expensive for a database of hundreds of MB, and much more invasive.
  • Reuse the wrapped crypt remote's keys automatically. Convenient (no new passwords), but hasher can wrap anything, including a non-crypt remote someone still wants kept private, and coupling the two backends' internals seems worse than two more config options. This could be an auto mode later.
  • Store the hashes on the remote instead (#3667's crypt v1 header, or a sidecar or metadata overlay as discussed in #1710 and #7535). That's the bigger and better long-term fix, since the hashes would travel with the files. It doesn't remove the need for this, though: reading a header or a sidecar per object is far too slow for listing large remotes, so a local cache remains, and it should be encrypted too. (For what it's worth, an encrypted MD5 is small enough for drive's 124-byte property limit, which ruled out AppleDouble in #7535: a 24-byte nonce, the 16-byte MD5, and a 16-byte tag, base64 encoded, come to 76 characters before the key name.)
Open questions
  1. Option names: db_password / db_password2, or something that reads better next to max_age and auto_size?
  2. Is binding values to keys worth the extra work in kvMove, or is key-only encryption plus sealed values enough?
  3. Should import / stickyimport warn when used with an encrypted database? Their SUM files contain plaintext paths.
Getting involved
  • I'm willing to help implement, test or fund this feature.
Lingua principale
Go
Stelle
61.1k
Fork
5.7k
Merge medio
6g 15h
PR unite (30g)
51

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di rclone/rclone

Tutte le issue di rclone/rclone

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.