Files
seaweedfs/docs/remote-storage-yandex.md
T
fb0a734dc4 feat(remote_storage): add Yandex Disk as a remote storage backend (#13012)
* feat(remote_storage): add a Yandex Disk backend

Yandex Disk joins s3/gcs/azure as a remote storage type, so it can back
remote mounts and sink replication (filer.remote.sync, filer.remote.gateway)
without a separate sink.

The Disk API has no buckets and no place for a file's mtime: a top-level
folder under yandex_root plays the bucket, and the entry's modification time
and content encoding travel as custom resource properties (seaweedfs_modified,
seaweedfs_content_encoding; rclone_modified is read too). The client also
handles the API's asynchronous operations (202 + operation polling), the
short-lived, single-use download links (a fresh link per read and per retry),
single-PUT uploads, mkdir -p of an S3-style key's parents, server-side copy
for a remote-only rename, and a ranged read that refuses a short body.

A caller-supplied endpoint goes through the guarded client like the s3 and
azure endpoints.

* feat(shell): configure and issue Yandex Disk tokens

remote.configure gains the yandex flags (token, client_id, client_secret,
root, trash, app_folder, endpoint). A refreshable token is issued in two
steps without a browser on the server: -yandex.oauth_url prints the
authorization url and keeps the app credentials, -yandex.code exchanges the
copied code for a token and stores it. The token and the client secret are
masked in the configuration listing.

docs/remote-storage-yandex.md walks through the OAuth app, both token flows,
the mount and replication commands, and the platform's limits.

* fix(remote_storage): handle missing Yandex folders on stat, copy and upload

A missing object is confirmed against the bucket folder rather than its
immediate parent, as the gcs client does: a key whose subfolder does not
exist yet (a rename destination) is a missing object, not a vanished mount,
and the sync only proceeds on ErrRemoteObjectNotFound.

CopyFile creates the destination's parent folders, so a remote-only rename
into a folder the remote does not have yet succeeds. The Disk API answers a
missing parent with 409 DiskPathDoesntExistsError; upload and copy treat it
like a 404, and the fake answers the way the API does.

An operation poll refreshes the token once on 401 and then fails, instead of
polling without a pause until the operation deadline.

* fix(remote_storage): retry a locked Yandex resource

A folder that is still being deleted asynchronously answers a write with
423 DiskResourceLockedError for a moment. The client now retries it with the
same backoff as 429/5xx/509, and the error stays transient for the sync's
upload retry when the client's retries run out.

* fix(remote_storage): harden the Yandex backend after review

Traverse reports objects only, like the s3, gcs and azure clients: its
callers (remote.cache, remote.copy.local) read the stamp of every entry, and
a folder came with none.

Deletes no longer reach what they were not meant for. A Disk API delete is
recursive, so DeleteFile keeps a folder that took a file's place on the
remote, and DeleteBucket removes an empty bucket folder only, the rule S3 and
GCS apply to a bucket.

CopyFile keeps the destination until its replacement exists: it copies with
overwrite and removes the old object (to the trash when configured) only when
the service kept it anyway. It refuses to replace a folder, treats a copy
onto itself as done, and carries the source's resolved modification time,
including rclone_modified and the service's own time.

Every metadata request and operation poll has a deadline that covers
reading the answer, and a token refresh or code exchange has its own, so a
stalled endpoint cannot block the client. Redirects are checked like the
transfer links, an endpoint that would send the token over plain http is
refused unless it is on a loopback host, a 202 without an operation link is
an error, and a read with an offset and no size starts at the offset.

* chore(seaweed-volume): keep only the Yandex fields in the remote.proto copy

* yandex: retry a failed operation poll

One throttled, failed or timed-out status poll ended a wait of up to 30
minutes while the operation kept running on the service, so a large
delete or copy was reported failed and redone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* yandex: refresh a token once for concurrent 401s

Every request rejected with the same access token replaced the token
source, so N concurrent 401s refreshed, and rotated the refresh token,
N times.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* yandex: retry an operation poll whose answer was cut short

A status poll that got its 200 headers but lost the connection before the
JSON body ended failed with io.ErrUnexpectedEOF, which the poll retry did
not treat as transient, so the wait ended while the operation kept running.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Konstantin Lebedev <whitefox@mayflower.work>
Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 17:31:14 -08:00

6.8 KiB

Yandex Disk as a remote storage

SeaweedFS can mount a Yandex Disk and mirror buckets to it, the same way it uses S3, Google Cloud Storage, or Azure Blob Storage. The storage type is yandex.

Yandex Disk has no buckets: a top-level folder under yandex.root plays the bucket, and the folder holds the objects. A file's modification time and content encoding, which the Disk API cannot store natively, travel as custom resource properties (seaweedfs_modified, seaweedfs_content_encoding). The client also reads rclone_modified, so objects uploaded by rclone keep their mtime.

Limitations to know first

  • The public Disk API has no multipart upload: an object is one PUT. Very large objects are limited by the plan's maximum file size (see GET / quota) and need a long HTTP timeout.
  • Writes are expensive: one upload is an upload-link request, the PUT, a metadata PATCH, and a stat.
  • Yandex applies rate limits; the client retries 423, 429, 5xx and 509 with a backoff, the sync retries a failed upload from a fresh reader.
  • The Disk API lists one folder per request, so remote.cache and remote.copy.local, which walk a whole tree, cost one request per folder.
  • S3 keys that contain characters Yandex rejects in a path fail; there is no key-encoding layer. S3 keys are not folders: a prefix that only appears as part of object names is created on demand.
  • This is a consumer product: it fits backups and small mirrors, not millions of objects or a high request rate.

1. Register an OAuth app

  1. Open https://oauth.yandex.ru/client/new and create an app.
  2. Pick the Web services platform.
  3. Set the redirect URI to https://oauth.yandex.ru/verification_code. That page shows the authorization code (or the token) for the operator to copy, so no browser is needed on the server.
  4. Grant the app the permissions you need:
    • cloud_api:disk.write — write anywhere on the disk (needed for buckets and for -yandex.root outside the app folder),
    • cloud_api:disk.read — read the disk,
    • cloud_api:disk.info — read the quota,
    • cloud_api:disk.app_folder — app folder only; then the configuration needs -yandex.app_folder=true.
  5. Copy the ClientID (and the Client secret if you want a refreshable token).

A Yandex Mail account is required for a working Disk subscription; a token issued for an account without one fails with 403 DiskUnsupportedUserAccountTypeError.

2. Get a token

# 1. print the authorization url and keep the app credentials
weed shell -master=... <<< "remote.configure -name=disk -type=yandex \
  -yandex.client_id=<client id> -yandex.client_secret=<client secret> -yandex.oauth_url"

# 2. open the printed url, allow the app, copy the code from the page
# 3. store the token
weed shell -master=... <<< "remote.configure -name=disk -yandex.code=<code>"

The stored value is a token JSON document ({"access_token","refresh_token","token_type","expiry"}, the same shape rclone stores), so a token can also be copied from an existing rclone configuration.

Debug token (one year, no refresh)

Open https://oauth.yandex.ru/authorize?response_type=token&client_id=<client id> in a browser, allow the app, and copy the token. Then:

weed shell -master=... <<< "remote.configure -name=disk -type=yandex -yandex.token=<token>"

To try the backend without registering an app, the Disk API polygon (https://yandex.ru/dev/disk/poligon/) issues a one-year token for its own OAuth app: sign in, click "Получить OAuth-токен", allow the access, and copy access_token from the address the page lands on. That token cannot be refreshed; use the code flow above for anything long-lived.

3. Configure

remote.configure -name=disk -type=yandex -yandex.token=<token> [-yandex.root=/seaweedfs]
flag meaning
-yandex.token token JSON or a bare access token
-yandex.client_id, -yandex.client_secret OAuth app credentials, needed to refresh the token and for -yandex.code
-yandex.root folder that holds the buckets, default /
-yandex.app_folder the token only reaches the app folder: paths are addressed under app:
-yandex.trash move deleted files to the trash instead of deleting them permanently (the trash keeps occupying quota)
-yandex.endpoint override the API endpoint, e.g. for a proxy (default https://cloud-api.yandex.net/v1/disk); it must be https, plain http is accepted on a loopback host only, since every request carries the OAuth token

A dedicated root (-yandex.root=/seaweedfs) is recommended: with the default /, remote.mount.buckets treats every top-level folder of the disk, personal folders included, as a bucket.

4. Mount or mirror

# mount one folder as a local directory
remote.mount -dir=/buckets/photos -remote=disk/photos

# mount every folder under the root as a bucket and pull its metadata
remote.mount.buckets -remote=disk -apply

# pull remote changes into the local metadata later
remote.meta.sync -dir=/buckets/photos

# mirror local buckets to the disk
weed filer.remote.gateway -filer=<filer host>:<filer port> -createBucketAt=disk

weed filer.remote.sync -filer=... -dir=/buckets uploads changes made under the mounted directories.

Deleting a local bucket deletes its remote folder only when that folder is empty, the same rule S3 and GCS apply to a bucket: a Disk API delete is recursive, and the folder may hold files SeaweedFS never saw.

Token lifetime and refresh

An access token and its refresh token both live about a year. The client refreshes the access token when it expires or when the API answers 401, and uses the rotated refresh token Yandex returns. The refreshed token is kept in memory only: a client cannot write the configuration back to the filer. A restart within the token's lifetime keeps working with the stored refresh token; once Yandex rejects it (invalid_grant), issue a new one with -yandex.oauth_url and -yandex.code above. Yandex recommends refreshing a long-lived token every three months.

Not covered

  • weed filer.backup and the legacy weed/replication/sink sinks have no Yandex backend; use filer.remote.sync / filer.remote.gateway.
  • The Rust volume server (seaweed-volume) supports only S3-compatible remote storage; a Yandex remote cannot back a tiered volume there.

Troubleshooting

  • 403 DiskUnsupportedUserAccountTypeError — the account has no Yandex Mail / Disk subscription.
  • 401 on every request — the token is wrong or revoked; reissue it.
  • invalid_grant while refreshing — the refresh token expired or was rotated elsewhere; reissue it.
  • 500 right after an upload — Yandex finalizes an upload asynchronously; the client retries the stat, and a retry of the whole upload succeeds.