Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
840752a
feat(gcs): Add resumable uploads
lcian Sep 1, 2026
a6411cf
fix(resumable): Harden GCS session handling
lcian Sep 1, 2026
acb8bf8
fix(resumable): Always encrypt session tokens
lcian Sep 2, 2026
5d89b28
fix(resumable): Limit backend support to GCS
lcian Sep 2, 2026
d9c6f82
docs(resumable): Describe protected session tokens
lcian Sep 2, 2026
e62c9c0
ref(resumable)!: Clarify upload completion semantics
lcian Sep 2, 2026
9289e52
fix(gcs): Honor completion after resumable offset gaps
lcian Sep 2, 2026
8044720
wip
lcian Sep 2, 2026
62762a3
wip
lcian Sep 2, 2026
4f9e7c3
test(server): Restore resumable routing coverage
lcian Sep 2, 2026
d5f882e
ref(resumable): Store the active encryption key directly
lcian Sep 2, 2026
c7e184c
ref(resumable): Encapsulate token encryption key use
lcian Sep 2, 2026
c830653
ref(resumable): Simplify token AEAD key storage
lcian Sep 2, 2026
9470202
ref(gcs): Inline resumable protocol values
lcian Sep 2, 2026
3049751
ref(resumable): Remove session format versioning
lcian Sep 2, 2026
d4e0d06
ref(gcs): Name resumable session storage path
lcian Sep 2, 2026
6606025
ref(gcs): Type resumable session URI as URL
lcian Sep 2, 2026
c245f19
ref(resumable): Bind sessions at service boundary
lcian Sep 3, 2026
b9f9c73
ref(gcs): Simplify resumable session tokens
lcian Sep 3, 2026
154fef5
improve gcs
lcian Sep 3, 2026
ab2cf80
Merge branch 'main' into feat/gcs-resumable-uploads
lcian Sep 3, 2026
c197ce1
fix
lcian Sep 3, 2026
2c54836
improve
lcian Sep 4, 2026
8ab626a
improve
lcian Sep 4, 2026
9220555
improve
lcian Sep 4, 2026
ab34dbb
ref(gcs): Parse resumable responses in a free function
lcian Sep 4, 2026
88c4a1c
improve
lcian Sep 4, 2026
9bd703b
improve
lcian Sep 4, 2026
288b1ff
improve
lcian Sep 4, 2026
b95332a
improve
lcian Sep 4, 2026
b50835d
improve
lcian Sep 4, 2026
14c71ab
fix
lcian Sep 4, 2026
286890b
improve
lcian Sep 7, 2026
eef49be
improve
lcian Sep 7, 2026
9293adf
improve
lcian Sep 7, 2026
a33db72
wip
lcian Sep 7, 2026
1432a07
ref(service)!: Require encryptor at construction
lcian Sep 7, 2026
154d35a
remove unneeded test
lcian Sep 7, 2026
7fc509e
feat(config): Load resumable keys via serde-vars
lcian Sep 7, 2026
7f24a20
ref(config): Keep resumable keys as strings
lcian Sep 7, 2026
34228bf
ref(config): Deserialize raw resumable keys
lcian Sep 7, 2026
4b5bcf7
ref(config): Simplify raw key serialization
lcian Sep 7, 2026
f65fe9a
fix(gcs): Report recovered resumable writes
lcian Sep 7, 2026
5528055
rename session -> token
lcian Sep 8, 2026
4e64ddc
use an enum for progress in gcs
lcian Sep 8, 2026
7aa8f33
inline function, use question mark
lcian Sep 8, 2026
ef91dae
question mark more
lcian Sep 8, 2026
a4160ad
reject length 0 and enforce via types
lcian Sep 8, 2026
d928593
improve
lcian Sep 8, 2026
8dd3aa5
change error messages
lcian Sep 8, 2026
8042b46
add code comments
lcian Sep 8, 2026
234289d
comment
lcian Sep 8, 2026
d2a1b20
improve
lcian Sep 8, 2026
96f3415
simplify key deserialization, remove unnecessary test
lcian Sep 8, 2026
9da72f2
versioning for token encryption
lcian Sep 8, 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
5 changes: 4 additions & 1 deletion 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 @@ -80,6 +80,7 @@ rand = "0.10.1"
rand_distr = "0.6.0"
regex = "1.12.4"
reqwest = { version = "0.13.4", default-features = false }
ring = "0.17.14"
rustls = { version = "0.23.40", default-features = false }
secrecy = "0.10.3"
sentry = "0.48.3"
Expand Down
3 changes: 1 addition & 2 deletions objectstore-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ 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 }
bytes = { workspace = true, features = ["serde"] }
ed25519-dalek = { workspace = true, features = ["pem"] }
elegant-departure = { workspace = true, features = ["tokio"] }
figment = { workspace = true, features = ["env", "test", "yaml"] }
Expand Down
14 changes: 7 additions & 7 deletions objectstore-server/src/auth/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,33 +208,33 @@ impl AuthAwareService {
pub async fn put_chunk(
&self,
id: ObjectId,
session: SessionToken,
token: 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)
.put_chunk(id, token, offset, content_length, body)
.await?)
}

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

/// Auth-aware wrapper around [`StorageService::cancel_upload`].
pub async fn cancel_upload(&self, id: ObjectId, session: SessionToken) -> ApiResult<()> {
pub async fn cancel_upload(&self, id: ObjectId, token: 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?)
Ok(self.service.cancel_upload(id, token).await?)
}
}
108 changes: 108 additions & 0 deletions objectstore-server/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,11 @@ use std::path::{Path, PathBuf};
use std::time::Duration;

use anyhow::Result;
use bytes::Bytes;
use figment::providers::{Env, Format, Serialized, Yaml};
use objectstore_service::backend::local_fs::FileSystemConfig;
use objectstore_service::change_stream::CostTrackerConfig;
use objectstore_service::resumable::Encryptor;
use objectstore_types::auth::Permission;
use secrecy::{CloneableSecret, SecretBox, SerializableSecret, zeroize::Zeroize};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -575,6 +577,8 @@ pub struct Config {
/// - `OS__SERVICE__CONCURRENCY_QUEUE`
/// - `OS__SERVICE__CONCURRENCY_TIMEOUT`
/// - `OS__SERVICE__BULK_CONCURRENCY_PCT`
/// - `OS__SERVICE__RESUMABLE_TOKEN_ENCRYPTION__ACTIVE_KEY_ID`
/// - `OS__SERVICE__RESUMABLE_TOKEN_ENCRYPTION__KEYS`
#[derive(Debug, Deserialize, Serialize)]
#[serde(default)]
pub struct Service {
Expand Down Expand Up @@ -629,6 +633,62 @@ pub struct Service {
///
/// `60`
pub bulk_concurrency_pct: u32,

/// Persistent encryption keys for resumable-upload session tokens returned to clients.
///
/// Tokens are always encrypted. When this is absent, Objectstore generates a fresh in-memory
/// AES-256 key at startup, so resumable sessions become invalid after a restart. Configure a
/// persistent keyring for sessions that must survive restarts. Keep old keys configured while
/// their sessions may still be active; removing a key intentionally invalidates those sessions.
/// Values must be raw AES-256 key bytes.
///
/// ```yaml
/// service:
/// resumable_token_encryption:
/// active_key_id: v1
/// keys:
/// v1: ${file:/var/run/secrets/objectstore/resumable-upload-v1}
/// ```
pub resumable_token_encryption: Option<ResumableTokenEncryptionConfig>,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest to make this configuration independent of resumable uploads. This is a key that can be used for any symmetric encryption business, which includes but does not have to be limited to resumable uploads.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to do this in a follow-up, along with making the Encryptor generic or at least more general.

}

impl Service {
/// Loads and validates the configured resumable token encryption keys.
pub(crate) fn resumable_token_encryption(&self) -> Result<Option<Encryptor>> {
Comment thread
lcian marked this conversation as resolved.
Resolved
let Some(config) = &self.resumable_token_encryption else {
return Ok(None);
};

let keys = config
.keys
.iter()
.map(|(key_id, key)| (key_id.clone(), key.to_vec()))
.collect();

Encryptor::new(config.active_key_id.clone(), keys).map(Some)
}
}

/// AES-256-GCM keys used to protect externally visible resumable session tokens.
#[derive(Clone, Deserialize, Serialize)]
pub struct ResumableTokenEncryptionConfig {
/// Key used to encrypt newly created sessions.
pub active_key_id: String,
/// Raw, exactly 32-byte AES-256 keys, indexed by rotation ID.
///
/// File-backed secrets should use `${file:PATH}` so they are loaded during configuration
/// deserialization.
#[serde(default)]
pub keys: BTreeMap<String, Bytes>,
}

impl fmt::Debug for ResumableTokenEncryptionConfig {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("ResumableTokenEncryptionConfig")
.field("active_key_id", &self.active_key_id)
.field("key_ids", &self.keys.keys().collect::<Vec<_>>())
.finish()
}
}

impl Default for Service {
Expand All @@ -638,6 +698,7 @@ impl Default for Service {
concurrency_queue: 0,
concurrency_timeout: Duration::from_secs(1),
bulk_concurrency_pct: 60,
resumable_token_encryption: None,
}
}
}
Expand Down Expand Up @@ -866,6 +927,40 @@ mod tests {
});
}

#[test]
fn resumable_token_encryption_rejects_invalid_configuration() {
let mut valid = tempfile::NamedTempFile::new().unwrap();
valid.write_all(&[7; 32]).unwrap();
let mut short = tempfile::NamedTempFile::new().unwrap();
short.write_all(&[7; 31]).unwrap();
for yaml in [
"service:\n resumable_token_encryption:\n active_key_id: v1\n".to_owned(),
format!(
"service:\n resumable_token_encryption:\n active_key_id: missing\n keys:\n v1: ${{file:{}}}\n",
valid.path().display(),
),
format!(
"service:\n resumable_token_encryption:\n active_key_id: bad_key\n keys:\n 'bad key': ${{file:{}}}\n",
valid.path().display(),
),
format!(
"service:\n resumable_token_encryption:\n active_key_id: v1\n keys:\n v1: ${{file:{}}}\n",
short.path().display(),
),
] {
let mut tempfile = tempfile::NamedTempFile::new().unwrap();
tempfile.write_all(yaml.as_bytes()).unwrap();
figment::Jail::expect_with(|_jail| {
let config = Config::load(Some(tempfile.path())).unwrap();
assert!(
config.service.resumable_token_encryption().is_err(),
"accepted {yaml}"
);
Ok(())
});
}
}

#[test]
fn configured_with_env_and_yaml() {
let mut tempfile = tempfile::NamedTempFile::new().unwrap();
Expand Down Expand Up @@ -1026,6 +1121,7 @@ mod tests {

let dir = tempfile::tempdir().unwrap();
std::fs::write(dir.path().join("relative-password"), "hunter3").unwrap();
std::fs::write(dir.path().join("resumable-token-key"), [255; 32]).unwrap();

let config_path = dir.path().join("config.yml");
std::fs::write(
Expand All @@ -1040,6 +1136,11 @@ mod tests {
from.env: ${{KAFKA_SASL_PASSWORD}}
from.relative.file: ${{file:relative-password}}
from.absolute.file: ${{file:{}}}
service:
resumable_token_encryption:
active_key_id: v1
keys:
v1: ${{file:resumable-token-key}}
"#,
absolute_secret.display()
),
Expand All @@ -1064,6 +1165,13 @@ mod tests {
sink.override_params["not.a.reference"], "prod-${NOT_A_VAR",
"a value that is not a reference is left alone"
);
assert!(
config
.service
.resumable_token_encryption()
.unwrap()
.is_some()
);

Ok(())
});
Expand Down
12 changes: 7 additions & 5 deletions objectstore-server/src/endpoints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@
//! 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.
//! byte and completes the upload 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.
//! Session creation returns an opaque token encoded once as unpadded base64url; that value can be
//! placed directly in the `session` query parameter.
//! The object is named by the request path as usual, and [`objectstore_types::resumable`]
//! holds the protocol types.
//!
Expand All @@ -57,14 +57,16 @@
//! `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.
//! `201 Created` with `{"key"}` once the upload is complete and the object is available through
//! the normal object endpoints. The session is terminal at that point.
//! 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.
//! An offset query can finish pending backend publication work, 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.
//!
Expand Down
28 changes: 17 additions & 11 deletions objectstore-server/src/endpoints/resumable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ use objectstore_service::id::{ObjectContext, ObjectId};
use objectstore_service::stream::ClientStream;
use objectstore_types::metadata::Metadata;
use objectstore_types::resumable::{
CommitResponse, CreateSessionResponse, HEADER_UPLOAD_OFFSET, UploadOffset, UploadProgress,
CompleteUploadResponse, CreateSessionResponse, HEADER_UPLOAD_OFFSET, UploadOffset,
UploadProgress,
};

use crate::auth::AuthAwareService;
Expand Down Expand Up @@ -113,16 +114,21 @@ async fn create_session_for_id(
///
/// [`HEADER_UPLOAD_OFFSET`] selects between the two. A concrete offset submits the request
/// body as the chunk starting there; the `*` wildcard submits nothing and asks where the
/// server stands, which also commits an object that was assembled but not yet committed.
/// server stands. A status query can observe completion when the final chunk succeeded but its
/// response was lost. A composed backend can also finish pending idempotent publication work
/// before reporting completion.
/// Chunks require `Content-Length`, including over HTTP/2. Offset queries may omit it, but the
/// body stream is checked and any bytes are rejected as a malformed request.
///
/// Both answer `204 No Content` with the authoritative offset while bytes remain, and
/// `201 Created` with the key once the object is committed.
/// `201 Created` with the key once the upload is complete, the session is terminal, and the object
/// is available through the normal object endpoints.
/// The acknowledged offset may be lower than the submitted chunk's end, so clients should continue
/// from this response (or from a later explicit offset query), never from local byte accounting alone.
pub(super) async fn continue_session(
service: AuthAwareService,
Xt(id): Xt<ObjectId>,
Session(session): Session,
Session(token): Session,
TypedHeader(UploadOffsetHeader(offset)): TypedHeader<UploadOffsetHeader>,
content_length: Option<TypedHeader<ContentLength>>,
MeteredBody(body): MeteredBody,
Expand All @@ -135,7 +141,7 @@ pub(super) async fn continue_session(
.map(|TypedHeader(ContentLength(length))| length)
.ok_or_else(|| ApiError::client("content-length header is required"))?;
service
.put_chunk(id, session, offset, content_length, body)
.put_chunk(id, token, offset, content_length, body)
.await
}
UploadOffset::Unknown => {
Expand All @@ -148,7 +154,7 @@ pub(super) async fn continue_session(
)
.await?;

service.upload_offset(id, session).await
service.upload_offset(id, token).await
}
};

Expand All @@ -159,9 +165,9 @@ pub(super) async fn continue_session(
pub(super) async fn cancel_session(
service: AuthAwareService,
Xt(id): Xt<ObjectId>,
Session(session): Session,
Session(token): Session,
) -> ApiResult<Response> {
service.cancel_upload(id, session).await?;
service.cancel_upload(id, token).await?;
Ok(StatusCode::NO_CONTENT.into_response())
}

Expand Down Expand Up @@ -189,8 +195,8 @@ fn progress_response(progress: ApiResult<UploadProgress>, key: String) -> ApiRes
[(HEADER_UPLOAD_OFFSET, http::HeaderValue::from(offset))],
)
.into_response(),
UploadProgress::Committed => {
(StatusCode::CREATED, Json(CommitResponse { key })).into_response()
UploadProgress::Complete => {
(StatusCode::CREATED, Json(CompleteUploadResponse { key })).into_response()
}
};

Expand Down Expand Up @@ -229,7 +235,7 @@ mod tests {

#[tokio::test]
async fn commit_answers_created_with_the_key() {
let response = progress_response(Ok(UploadProgress::Committed), "my-key".into()).unwrap();
let response = progress_response(Ok(UploadProgress::Complete), "my-key".into()).unwrap();

let (status, offset, body) = parts_of(response).await;
assert_eq!(status, StatusCode::CREATED);
Expand Down
6 changes: 5 additions & 1 deletion objectstore-server/src/extractors/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ mod tests {
use axum::routing::{get, post};
use objectstore_service::StorageService;
use objectstore_service::backend::in_memory::InMemoryBackend;
use objectstore_service::resumable::Encryptor;
use tower::ServiceExt;

use crate::auth::PublicKeyDirectory;
Expand All @@ -239,7 +240,10 @@ mod tests {
use crate::web::RequestCounter;

async fn test_state(config: Config) -> ServiceState {
let service = StorageService::new(Box::new(InMemoryBackend::new("in-memory")));
let service = StorageService::new(
Box::new(InMemoryBackend::new("in-memory")),
Encryptor::ephemeral().unwrap(),
);
let key_directory = Arc::new(PublicKeyDirectory::from_config(&config.auth).await.unwrap());
let rate_limiter = RateLimiter::new(config.rate_limits.clone());

Expand Down
Loading
Loading