Commit 815031d
feat: add OneDrive and Google Drive backends via OAuth2 device code flow
Adds two new storage backends that target the substantial free tiers of
consumer cloud accounts (1 TB on OneDrive with O365, 15 GB on personal
Google Drive), making Enigma viable for personal backups without paying
for object storage.
Both providers authenticate via OAuth2 device code flow — the user enters
an 8-character code on microsoft.com/devicelogin or google.com/device once,
and refresh tokens stored AES-256-GCM-encrypted on disk handle every
subsequent operation transparently.
New module: enigma-storage/src/oauth/
- device_flow.rs: hand-rolled OAuth2 device code + refresh implementation
that handles both Microsoft Graph and Google identity endpoints
- token_store.rs: encrypted token persistence at <config_dir>/oauth_tokens.enc
(Argon2id + HKDF-SHA256(info="enigma-oauth-v1") + AES-256-GCM, same
passphrase as the keystore)
- retry.rs: with_retry helper honoring HTTP 429 + Retry-After
New backends:
- onedrive.rs: Microsoft Graph /me/drive/special/approot endpoints with
Files.ReadWrite.AppFolder scope (isolated to /Apps/Enigma/). Inline
PUT for chunks ≤ 4 MiB; upload session for larger chunks (10 MiB
segments) since FastCDC can produce ~8 MiB.
- gdrive.rs: Drive v3 with drive.file scope (app sees only its own
files). Flat folder strategy + in-memory chunk-key → file-id cache
bulk-populated on first use.
New CLI subcommand:
- enigma auth login {onedrive,gdrive} --client-id <id> [--client-secret <s>]
- enigma auth status
- enigma auth logout <provider>
Config: existing [[providers]] schema; type = "onedrive" or "gdrive";
bucket field unused (OneDrive uses approot, Drive uses fixed
"enigma-chunks" folder).
Wiring:
- ProviderType::Onedrive, ProviderType::Gdrive added to enigma-core
- enigma-cli/commands/providers.rs: lazy-open the encrypted token store
only when an OAuth provider is configured; bubble a clear error if no
passphrase is available
- backup / restore / verify / gc updated to thread base_dir + passphrase
through init_providers
Tests:
- Unit tests for retry backoff, retry-after parsing, token store
roundtrip + wrong-passphrase rejection, OneDrive URL path encoding,
Drive name flattening, multipart boundary uniqueness
Out of scope (follow-ups):
- enigma-proxy dispatch (S3 gateway) for OneDrive/GDrive — currently
bails through the existing `_ => bail` arm
- README translations (13 other languages)
- Multi-account-per-provider support
Note: this commit was not validated locally because the dev environment
lacks build-essential / gcc. CI will catch any issues; follow-up commits
will fix compile errors.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 3aa6193 commit 815031d
21 files changed
Lines changed: 2197 additions & 18 deletions
File tree
- crates
- enigma-cli
- src
- commands
- enigma-core/src
- enigma-storage
- src
- oauth
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
80 | 86 | | |
81 | 87 | | |
82 | 88 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
290 | 290 | | |
291 | 291 | | |
292 | 292 | | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
293 | 375 | | |
294 | 376 | | |
295 | 377 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
35 | | - | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
36 | 39 | | |
37 | 40 | | |
38 | 41 | | |
| |||
0 commit comments