The gdrive backend (backend-gdrive) speaks Google Drive REST API v3 directly without external SDK bloat. It pairs Desktop PKCE loopback OAuth 2.0 (never the deprecated OOB flow) or RS256 Service Account JWTs with SQLite-backed incremental changes.list directory caching, CUBIC adaptive rate limiting, and bit-exact 308 resumable uploads.
Authorization Recipes#
# Opens browser on http://127.0.0.1:<ephemeral-port>/callback
rship auth gdrive gdrive \
--client-id "<YOUR_CLIENT_ID>.apps.googleusercontent.com" \
--client-secret "<YOUR_CLIENT_SECRET>" \
--scope drive
# Move tokens into macOS/Windows/Linux OS Keyring
rship auth keyring-migrate
rship about gdrive:OAuth 2.0 Setup#
You can also print this setup guide in your terminal anytime with rship auth gdrive --guide.
Choosing Your Authorization Path#
| Path | Best For | Google Review / CASA Audit? | Setup Time |
|---|---|---|---|
| Path A: Bring Your Own Client ID (Recommended) | Personal use, teams, self-hosted servers, power users | None (Testing or Workspace Internal, up to 100 test users) | ~5 minutes |
| Path B: Public Verified OAuth App | Distributing a shared default Client ID to third-party users | Yes for drive / drive.readonly (Restricted Scopes + annual CASA Tier 2). drive.file is Non-Sensitive (no CASA audit). | 2–6 weeks |
| Path C: Service Account (RS256 JWT) | Automated CI/servers accessing Shared Drives or Workspace Domain-Wide Delegation | None | ~5 minutes |
Path A: Create Your Own Desktop Client ID (5 Minutes)#
- Create Project & Enable API: Open Google Cloud Console, create/select a project (e.g.
rship-personal-drive), go to APIs & Services → Library, search Google Drive API, and click Enable. - Configure Auth Platform: Open Google Auth Platform → Overview → Get Started (or OAuth consent screen), set App name to
rship, add your support email, and choose Internal (Google Workspace, never expires) or External (personal@gmail.com). - Add Scopes & Test Users: Open Data Access → Add or Remove Scopes and pick the narrowest scope you need:
https://www.googleapis.com/auth/drive(--scope drive) — Full Drive access for syncing existing folders.https://www.googleapis.com/auth/drive.file(--scope drive.file) — App-created files only (Non-Sensitive, zero CASA audit).https://www.googleapis.com/auth/drive.readonly(--scope drive.readonly) — Read-only backup/mirror. Add every Google email you will authorize under Audience → Test users.
- Create Desktop App Credentials: Under Google Auth Platform → Clients → Create Client, pick Desktop app (required so Google permits
http://127.0.0.1:<port>/callbackloopback redirects) and copy the generated Client ID and Client Secret. - Authorize & Verify: Run
rship auth gdrive gdrive --client-id ... --client-secret ..., then verify withrship config test gdriveandrship about gdrive:. Running on a headless server? See Headless VPS, Docker & Keyring.
Path B: Public Verified OAuth App Checklist#
If you host a shared public Client ID for third-party users:
- Verified Domain & Public Homepage: Verify your domain in Google Search Console and host this standalone
rshipsite (website/). - Public Privacy Policy URL: Link directly to the Privacy Policy hosted on the same verified domain.
- App Logo (
120×120PNG): Published at/logo-120.png(fromassets/logo-120.png). - Scope Choice: Prefer
drive.file(Non-Sensitive, fast verification, zero CASA fee) for shared public clients, while letting power users plug in their own Client ID via Path A for fulldriveaccess. - Unlisted YouTube Demo Video: 60–90 s screencast showing
rship auth gdrive ..., the visibleclient_id& scopes in the consent screen, clicking Allow, and runningrship about,rship copy, andrship ls.
Path C: Service Account Notes#
Flags Reference (rship auth gdrive)#
| Flag | Default | Description |
|---|---|---|
<REMOTE> | — | Logical remote name (e.g. gdrive, work-drive) |
--client-id | None | Google Cloud OAuth 2.0 Desktop app client_id |
--client-secret | None | OAuth 2.0 client_secret (required by Google Desktop OAuth token exchange) |
--scope | drive | Alias (drive, drive.file, drive.readonly) or full scope URL |
--root-folder-id | root | Pin operations to a specific folder ID inside My Drive |
--shared-drive-id | None | Shared Drive (team_drive) ID; enables corpora=drive & supportsAllDrives=true |
--service-account-file | None | Non-interactive RS256 JWT key file for CI / servers |
--impersonate | None | Domain-Wide Delegation subject email (sub) |
--guide | false | Print complete Cloud Console setup instructions and exit |
Metadata Cache Modes & Tuning#
Because Google Drive is an ID-graph filesystem that permits duplicate sibling names, rship combines an in-process L0 IndexedDirLru (16,384 entries, cascading subtree invalidation) with an optional persistent L1 SQLite inventory (<state_dir>/inventory/*.db, schema v3 delta_nodes + scope_meta) kept current via changes.list and leased Shadow Generation MVCC.
metadata_cache Modes#
Configure metadata_cache in [remotes.<name>], via --metadata-cache <auto|sparse|full|off>, or via RSHIP_METADATA_CACHE:
| Mode | When the L1 delta_nodes mirror is built | Best For |
|---|---|---|
auto (default) | Built only on full-tree reconciliation commands (sync, bisync, check, dedupe) targeting a shallow prefix (depth <= 1) when not in overflow cooldown. Cold ls, ls -R | head, tree, copy, move, and deep-prefix sync (depth > 1) stream live with zero changes.list bootstrap calls. Once a mirror exists, warm listings reuse it via O(Delta) catch-up. | General use, mixed ls / copy / sync workflows |
sparse | Never builds or queries persistent L1 delta_nodes; uses in-process L0 LRU + live streaming only. Cross-process mkdir exclusion (FileScopeLocker) still runs in persistent mode without opening SQLite. Global --no-changes-feed always forces sparse. | Huge Shared Drives (> 500k nodes) or one-off transfers |
full | Always bootstraps/maintains L1 delta_nodes on listings (ignores prefix depth and the max_inventory_nodes overflow circuit breaker). | Frequent repeat full-tree sync / bisync jobs |
off | Disables both L0 in-memory cache and L1 persistent inventory (pure stateless remote lookups; cross-process mkdir locking still active in persistent mode). | Debugging or strict uncached reads |
- Legacy
use_changes_feedmapping:use_changes_feed = truenow maps tometadata_cache = "auto", anduse_changes_feed = falsemaps tometadata_cache = "sparse". Settingmetadata_cacheexplicitly overridesuse_changes_feed; passing global--no-changes-feedalways forcessparse. - Non-blocking bootstrap leases: Full bootstraps acquire a SQLite lease (
120sTTL,30sheartbeat) rather than a long-held file lock. If anotherrshipprocess is already bootstrapping the same scope, peers never wait — they stream live immediately. - L1 TTL for point operations (
l1_validation_ttl): Point operations (stat,mkdir,delete, single-file reads/uploads) trust an existing L1 mirror with zero locks and zero RPCs whilenow - validated_at <= l1_validation_ttl(default"60s"; set"0s"to disable L1 trust for point ops). When stale, point ops perform at most one non-blocking try-lock and up to10incrementalchanges.listpages (never rebuilding), falling back immediately to live lookup + L0 LRU on contention or large backlogs.
Remote Tuning & Multi-Process Coordination Keys#
[remotes.gdrive]
type = "gdrive"
client_id = "<CLIENT_ID>.apps.googleusercontent.com"
client_secret = "keyring://rship/gdrive.gdrive.client_secret"
metadata_cache = "auto" # auto | sparse | full | off
max_inventory_nodes = 500000 # auto-mode bootstrap circuit breaker (> 0)
overflow_cooldown = "7d" # skip repeat auto bootstraps after overflow
sync_changes_mem_cap = 20000 # max in-RAM incremental changes before streaming rebuild (> 0)
l1_validation_ttl = "60s" # point-op L1 cursor freshness TTL ("0s" disables)
quota_group = "corp-drive-acct" # share 429 cooldowns & process slots across aliases
max_concurrent_processes = 2 # opt-in cross-process concurrency cap (>= 1; unset = unlimited)
stop_on_upload_limit = true| Key | Default | Description |
|---|---|---|
metadata_cache | "auto" | Cache mode (auto, sparse, full, off). Propagates through crypt wrappers. |
max_inventory_nodes | 500000 | Node cap for cold auto bootstrap; exceeding it aborts staging, records overflowed_at, and falls back to streaming. |
overflow_cooldown | "7d" | Duration (>= 1s or "0s") to skip repeat auto bootstraps after hitting max_inventory_nodes. |
sync_changes_mem_cap | 20000 | Max in-RAM changes / moved-in nodes during incremental catch-up before switching to a bounded streaming rebuild (keeps release Peak RSS <= 64 MiB). |
l1_validation_ttl | "60s" | How long scope_meta.validated_at is trusted by point operations without re-checking changes.list. |
quota_group | remote name | Logical account group shared across remote aliases for <state_dir>/cooldowns/*.json and process slots (supported on all 7 HTTP backends). |
max_concurrent_processes | unset | Opt-in limit on concurrent rship processes per quota_group using <state_dir>/locks/slots/. Every remote in a quota_group must use the same value. Zero filesystem activity when unset. |
Protocol Internals, Lock-Wait Notices, Quota Failover & Dedupe#
- Chunk geometry & 308 resume: Files
<= 5 MiBuse single-shotuploadType=multipart; larger files stream in256 KiB-aligned resumable sessions (256 MiBdefault chunk size) withContent-Rangeresume persisted in SQLite WAL (journal.db). - Lock-wait notices & timeouts: Concurrent
mkdirslow-path locks (FileScopeLocker) and OAuth2<token_file>.lockrefreshes poll with bounded jitter (5..=50ms), cancel immediately onSIGINT/SIGTERM, and time out after300s(LockBusy, exit code9). Process slots (max_concurrent_processes) wait cancellably without a timeout; commands that use several remotes reserve all their slots up front in sortedquota_grouporder, so they cannot deadlock each other. Any wait exceeding1.5semits a single advisory notice onstderr(printed above the live--tui/--progressdisplay, or emitted as{"event":"notice","kind":"lock_wait",...}JSONL under--json-progress). - Write-QPS pacing, shared 429 cooldowns & 750 GiB/day limit: Writes are smoothed by an
8.0 creates/sdefault token bucket with CUBIC backoff on403/429and cross-process cooldown sharing via<state_dir>/cooldowns/(capped at30s,1sfloor). Pass global--drive-stop-on-upload-limit(RSHIP_DRIVE_STOP_ON_UPLOAD_LIMIT=1) to turn Google's daily403 userRateLimitExceeded(750 GiB/day) quota cap into an immediateErrorKind::QuotaExceeded, enabling automatic account rotation in the Rust SDKFailoverPool. - Duplicate filenames (
rship dedupe): Because Drive permits sibling files with the same name, usership dedupe gdrive:photos --mode newest(newest,oldest,largest,rename, orskip) to clean up duplicates safely by node ID. - Zero-reupload dedupe & server-side copy: Same-remote copies use
files.copy, andrship catsupports HTTPRangedownloads.