Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
77e2dab
feat(server): Add resumable upload API
jan-auer Aug 6, 2026
0c6f8f3
fix(server): Refine resumable upload protocol
lcian Aug 28, 2026
0df3274
ref(resumable): Dispatch requests through dedicated handlers
lcian Aug 28, 2026
d094ee7
ref(resumable): Defer route error responses
lcian Aug 28, 2026
b4b4f87
fix(resumable): Reject declared wildcard request bodies
lcian Aug 28, 2026
3f41938
ref(server): Centralize protocol error responses
lcian Aug 28, 2026
69a0db5
fix(resumable): Enforce session request contracts
lcian Aug 28, 2026
a53faae
ref(resumable): Extract targets from request parts
lcian Aug 28, 2026
910b019
ref(server): Keep protocol headers in endpoints
lcian Aug 28, 2026
d9a56f9
ref(server): Simplify object handler extraction
lcian Aug 28, 2026
8528024
improve
lcian Aug 28, 2026
17d21b9
improve
lcian Aug 28, 2026
25b7b0f
improve
lcian Aug 28, 2026
8fe6160
ref(resumable): Treat session tokens as opaque
lcian Aug 28, 2026
f0eefde
improve
lcian Aug 31, 2026
f537fdc
improve
lcian Aug 31, 2026
a62a39d
ref(resumable): Simplify session operation results
lcian Aug 31, 2026
83db069
improve
lcian Aug 31, 2026
1869939
test(service): Remove redundant resumable wrapper tests
lcian Aug 31, 2026
07fe113
ref(resumable): Scope token encoding to query parameters
lcian Aug 31, 2026
f47758e
improve
lcian Aug 31, 2026
01a2072
test(server): Remove unsupported resumable assertions
lcian Aug 31, 2026
1a7af5b
wip
lcian Sep 1, 2026
7a48a37
ref(resumable): Apply mechanical review cleanups
lcian Sep 1, 2026
6ce5be1
wip
lcian Sep 1, 2026
38f5b47
use typedheader
lcian Sep 1, 2026
e7ab29c
ref(resumable): Clarify resumable upload contracts
lcian Sep 1, 2026
cf53698
ref(server): Simplify resumable request dispatch
lcian Sep 1, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ async-compression = "0.4.42"
async-stream = "0.3.6"
async-trait = "0.1.89"
axum = "0.8.9"
axum-extra = { version = "0.12.6", default-features = false }
base64 = "0.22.1"
bigtable_rs = { git = "https://github.com/getsentry/bigtable_rs.git", rev = "4cb75bc5e5f87204363973f6302107768e64972e" }
bytes = "1.12.0"
Expand Down
2 changes: 2 additions & 0 deletions objectstore-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ anyhow = { workspace = true }
argh = { workspace = true }
async-stream = { workspace = true }
axum = { workspace = true, features = ["multipart"] }
axum-extra = { workspace = true, features = ["typed-header"] }
base64 = { workspace = true }
bytes = { workspace = true }
ed25519-dalek = { workspace = true, features = ["pem"] }
elegant-departure = { workspace = true, features = ["tokio"] }
Expand Down
53 changes: 10 additions & 43 deletions objectstore-server/docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,49 +7,16 @@ core storage operations.

## Endpoints

All object operations live under the `/v1/` prefix:

| Method | Path | Description |
|----------|-------------------------------------------|------------------------------|
| `POST` | `/v1/objects/{usecase}/{scopes}/` | Insert with server-generated key |
| `GET` | `/v1/objects/{usecase}/{scopes}/{*key}` | Retrieve object |
| `HEAD` | `/v1/objects/{usecase}/{scopes}/{*key}` | Retrieve metadata only |
| `PUT` | `/v1/objects/{usecase}/{scopes}/{*key}` | Insert or overwrite with key |
| `DELETE` | `/v1/objects/{usecase}/{scopes}/{*key}` | Delete object |
| `POST` | `/v1/objects:batch/{usecase}/{scopes}/` | Batch operations (multipart) |

### Multipart Upload Endpoints

| Method | Path | Description |
|-----------|--------------------------------------------------------------|--------------------------------------|
| `POST` | `/v1/objects:multipart/{usecase}/{scopes}/` | Initiate upload (server-generated key) |
| `PUT` | `/v1/objects:multipart/{usecase}/{scopes}/{*key}` | Initiate upload (user-provided key) |
| `PUT` | `/v1/objects:multipart:parts/{usecase}/{scopes}/{*key}` | Upload a part (`uploadId`, `partNumber` query params) |
| `GET` | `/v1/objects:multipart:parts/{usecase}/{scopes}/{*key}` | List uploaded parts (`uploadId` query param) |
| `POST` | `/v1/objects:multipart:complete/{usecase}/{scopes}/{*key}` | Complete upload (`uploadId` query param) |
| `DELETE` | `/v1/objects:multipart/{usecase}/{scopes}/{*key}` | Abort upload (`uploadId` query param) |

The initiate POST endpoint accepts both trailing-slash and non-trailing-slash forms.

The complete endpoint returns `200 OK` immediately, with a streaming body that
will contain the error (if any) as JSON. Whitespace is sent in the streaming body
to keep the connection open.
Clients must parse the body to determine the actual outcome, and not rely on the
status code.

Scopes are encoded in the URL path using Matrix URI syntax:
`org=123;project=456`. An underscore (`_`) represents empty scopes.

### Internal Endpoints

Internal endpoints are exempt from authentication, rate limiting, and the web
concurrency limit so they remain available when the server is under load.

| Method | Path | Description |
|--------|------|-------------|
| `GET` | `/health` | Liveness probe (always returns 200) |
| `GET` | `/ready` | Readiness probe (returns 503 when `/tmp/objectstore.down` exists, enabling graceful drain) |
| `GET` | `/keda` | Prometheus text-format gauges for KEDA autoscaling (see [KEDA Metrics](#keda-metrics)) |
All object operations live under the `/v1/` prefix. Objects are addressed by a
usecase, a set of scopes, and a key; scopes are encoded in the URL path using
Matrix URI syntax (`org=123;project=456`).

Four families of routes exist: object operations, resumable uploads, multipart
uploads (being replaced by resumable uploads), and internal probes that stay
available when the server is under load.

See the [`endpoints`] module for the routing table and the request and response
shape of every route.

## Request Flow

Expand Down
51 changes: 51 additions & 0 deletions objectstore-server/src/auth/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use objectstore_service::{ClientStream, StorageService};
use objectstore_types::auth::Permission;
use objectstore_types::metadata::Metadata;
use objectstore_types::range::ByteRange;
use objectstore_types::resumable::{SessionToken, UploadProgress};

use crate::auth::AuthContext;
use crate::endpoints::common::ApiResult;
Expand Down Expand Up @@ -186,4 +187,54 @@ impl AuthAwareService {
.complete_multipart(id, upload_id, parts)
.await?)
}

// --- Resumable upload operations ---

/// Auth-aware wrapper around [`StorageService::create_upload_session`].
pub async fn create_upload_session(
&self,
id: ObjectId,
metadata: Metadata,
total_length: u64,
) -> ApiResult<Option<SessionToken>> {
self.check_permission(Permission::ObjectWrite, id.context())?;
Ok(self
.service
.create_upload_session(id, metadata, total_length)
.await?)
}

/// Auth-aware wrapper around [`StorageService::put_chunk`].
pub async fn put_chunk(
&self,
id: ObjectId,
session: SessionToken,
offset: u64,
content_length: u64,
body: ClientStream,
) -> ApiResult<UploadProgress> {
self.check_permission(Permission::ObjectWrite, id.context())?;
Ok(self
.service
.put_chunk(id, session, offset, content_length, body)
.await?)
}

/// Auth-aware wrapper around [`StorageService::upload_offset`].
pub async fn upload_offset(
&self,
id: ObjectId,
session: SessionToken,
) -> ApiResult<UploadProgress> {
// An offset query can commit an assembled object.
self.check_permission(Permission::ObjectWrite, id.context())?;
Ok(self.service.upload_offset(id, session).await?)
}

/// Auth-aware wrapper around [`StorageService::cancel_upload`].
pub async fn cancel_upload(&self, id: ObjectId, session: SessionToken) -> ApiResult<()> {
// Canceling a session discards an in-progress upload rather than deleting an object.
self.check_permission(Permission::ObjectWrite, id.context())?;
Ok(self.service.cancel_upload(id, session).await?)
}
}
6 changes: 6 additions & 0 deletions objectstore-server/src/endpoints/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ impl ApiError {
StatusCode::RANGE_NOT_SATISFIABLE
}
ApiError::Service(ServiceError::InvalidUploadId(_)) => StatusCode::BAD_REQUEST,
ApiError::Service(ServiceError::UnknownUploadSession) => StatusCode::BAD_REQUEST,
ApiError::Service(ServiceError::ChunkExceedsUploadLength { .. }) => {
StatusCode::BAD_REQUEST
}
ApiError::Service(ServiceError::UploadOffsetMismatch { .. }) => StatusCode::CONFLICT,
ApiError::Service(ServiceError::UploadSessionGone) => StatusCode::GONE,
ApiError::Service(ServiceError::AtCapacity) => StatusCode::TOO_MANY_REQUESTS,
ApiError::Service(ServiceError::NotImplemented) => StatusCode::NOT_IMPLEMENTED,
ApiError::Service(_) => StatusCode::INTERNAL_SERVER_ERROR,
Expand Down
112 changes: 112 additions & 0 deletions objectstore-server/src/endpoints/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,116 @@
//! Contains all HTTP endpoint handlers.
//!
//! This module documents the request and response shape of every route; see the [crate
//! documentation](crate) for the layers a request passes through before reaching a handler.
//!
//! Scopes are encoded in the URL path using Matrix URI syntax: `org=123;project=456`. An
//! underscore (`_`) represents empty scopes.
//!
//! # Object Endpoints
//!
//! All object operations live under the `/v1/` prefix:
//!
//! | Method | Path | Description |
//! |----------|-------------------------------------------|------------------------------|
//! | `POST` | `/v1/objects/{usecase}/{scopes}/` | Insert with server-generated key |
//! | `GET` | `/v1/objects/{usecase}/{scopes}/{*key}` | Retrieve object |
//! | `HEAD` | `/v1/objects/{usecase}/{scopes}/{*key}` | Retrieve metadata only |
//! | `PUT` | `/v1/objects/{usecase}/{scopes}/{*key}` | Insert or overwrite with key |
//! | `DELETE` | `/v1/objects/{usecase}/{scopes}/{*key}` | Delete object |
//! | `POST` | `/v1/objects:batch/{usecase}/{scopes}/` | Batch operations (multipart) |
//!
//! Object metadata travels in request and response headers; see
//! [`objectstore_types::metadata`] for the mapping.
//!
//! # Resumable Upload Endpoints
//!
//! A resumable upload transfers a single object across several requests.
//! The client opens a session, declaring the object's total size and metadata upfront, and
//! then sends the payload as a sequence of chunks at increasing byte offsets.
//! If a chunk fails, the client can ask the server which offset it holds and continue from there,
//! so an interrupted transfer resumes where it stopped instead of starting over.
//! Clients are still encouraged to send the whole payload in a single request, as that's the most
//! efficient and reliable approach.
//! The server knows the total size from the session, so it recognizes the chunk carrying the last
//! byte and commits the object itself.
//!
//! Resumable uploads use the object endpoints above, selected by a query parameter:
//! `upload_type=resumable` opens a session, and `session=<token>` addresses it from then on.
//! Session creation returns the opaque backend token unchanged; subsequent requests encode it as
//! unpadded base64url in the `session` query parameter.
//! The object is named by the request path as usual, and [`objectstore_types::resumable`]
//! holds the protocol types.
//!
//! | Method | Path | Description |
//! |----------|------------------------------------------------------------|----------------------------------------------|
//! | `POST` | `/v1/objects/{usecase}/{scopes}/?upload_type=resumable` | Create session (server-generated key) |
//! | `PUT` | `/v1/objects/{usecase}/{scopes}/{*key}?upload_type=resumable` | Create session (user-provided key) |
//! | `PUT` | `/v1/objects/{usecase}/{scopes}/{*key}?session=<token>` | Upload a chunk, or query the offset |
//! | `DELETE` | `/v1/objects/{usecase}/{scopes}/{*key}?session=<token>` | Cancel upload, discarding what was sent |
//!
//! Session creation requires an `Upload-Length` header carrying the total size of the object
//! in bytes, takes the same metadata headers as a regular upload, and requires an empty body.
//! It answers `200 OK` with `{"key", "session"}`; the session field is the token to use in
//! subsequent query parameters. Metadata is fixed at this point and does not change afterwards.
//!
//! Chunk uploads and offset queries share one request shape, distinguished by the
//! `Upload-Offset` header: a byte offset submits the body as the chunk starting there, while
//! the `*` wildcard submits an empty body and asks which offset the server holds. Both answer
//! `204 No Content` with the authoritative `Upload-Offset` while bytes remain, and
//! `201 Created` with `{"key"}` once the object is committed.
//! The offset in the response may be lower than the end of the last chunk that was sent.
//! Backends can e.g. persist only aligned prefixes and discard the remainder, so clients must
//! always continue from the returned offset.
//! Every chunk requires `Content-Length`, even over HTTP/2, while creation and offset queries
//! must not carry a request body.
//!
//! An offset query can commit an object, so it requires write permission despite being read-shaped.
//! Termination likewise needs write rather than delete permission: it releases an in-progress upload,
//! not an object.
//!
//! | Status | Meaning | Client action |
//! |--------|---------|---------------|
//! | `400` | Malformed: unknown upload session, missing `Upload-Length`, nonempty offset query, or a chunk exceeding the declared length | Terminal |
//! | `409` | A chunk's offset does not match, with the authoritative offset in `Upload-Offset` | Resynchronize |
//! | `410` | The session expired or was canceled; nothing was retained | Start a new session |
//! | `501` | The configured backend does not implement resumable uploads | Fall back to a regular upload |
//!
//! # Multipart Upload Endpoints
//!
//! Multipart uploads are being replaced by [resumable
//! uploads](#resumable-upload-endpoints) and will be removed once all consumers have
//! migrated. See [`objectstore_types::multipart`] for the protocol types.
//!
//! | Method | Path | Description |
//! |-----------|--------------------------------------------------------------|--------------------------------------|
//! | `POST` | `/v1/objects:multipart/{usecase}/{scopes}/` | Initiate upload (server-generated key) |
//! | `PUT` | `/v1/objects:multipart/{usecase}/{scopes}/{*key}` | Initiate upload (user-provided key) |
//! | `PUT` | `/v1/objects:multipart:parts/{usecase}/{scopes}/{*key}` | Upload a part (`upload_id`, `part_number` query params) |
//! | `GET` | `/v1/objects:multipart:parts/{usecase}/{scopes}/{*key}` | List uploaded parts (`upload_id` query param) |
//! | `POST` | `/v1/objects:multipart:complete/{usecase}/{scopes}/{*key}` | Complete upload (`upload_id` query param) |
//! | `DELETE` | `/v1/objects:multipart/{usecase}/{scopes}/{*key}` | Abort upload (`upload_id` query param) |
//!
//! The initiate POST endpoint accepts both trailing-slash and non-trailing-slash forms.
//!
//! The complete endpoint returns `200 OK` immediately, with a streaming body that will
//! contain the error (if any) as JSON. Whitespace is sent in the streaming body to keep the
//! connection open. Clients must parse the body to determine the actual outcome, and not rely
//! on the status code.
//!
//! # Internal Endpoints
//!
//! Internal endpoints are exempt from authentication, rate limiting, and the web concurrency
//! limit so they remain available when the server is under load. [`is_internal_route`]
//! identifies them.
//!
//! | Method | Path | Description |
//! |--------|------|-------------|
//! | `GET` | `/health` | Liveness probe (always returns 200) |
//! | `GET` | `/ready` | Readiness probe (returns 503 when `/tmp/objectstore.down` exists, enabling graceful drain) |
//! | `GET` | `/keda` | Prometheus text-format gauges for KEDA autoscaling (see [KEDA Metrics](crate#keda-metrics)) |
//!
//! # Code Usage
//!
//! Use [`routes`] to create a router with all endpoints.

use axum::Router;
Expand All @@ -14,6 +125,7 @@ mod multipart;
mod objects;
#[cfg(all(target_os = "linux", feature = "profiling"))]
mod profiling;
mod resumable;

/// Returns `true` for internal endpoints that are exempt from metrics and concurrency limits.
pub fn is_internal_route(route: &str) -> bool {
Expand Down
Loading
Loading