feat: add public spaces with unauthenticated read endpoints#23
Merged
Conversation
…rage quota Implement the public spaces feature for TinyCloud. Spaces with name "public" are recognized as public and served via unauthenticated REST endpoints. - New GET/HEAD/OPTIONS endpoints at /public/<space_id>/kv/<key> and /public/<space_id>/kv?prefix=<p> for unauthenticated KV reads - is_public_space() detection based on space name == "public" - Per-IP token bucket rate limiter (default 60 req/min, burst 10) - If-None-Match / ETag conditional request support (304 Not Modified) - CORS headers (Access-Control-Allow-Origin: *) on all public responses - Cache-Control: public, max-age=60 on all public responses - Separate storage quota for public spaces (default 10MB vs regular limit) - Configurable via [public_spaces] config section
Rocket's PathBuf rejects path segments starting with dots (e.g. .well-known/profile). Replace PathBuf with a KVKey FromRequest guard that extracts the key from the raw request URI, and a RawKeyPath FromSegments type for route matching.
Rocket's PathBuf rejects dot-prefixed path segments like .well-known/ as a security measure. Replace with RawKeyPath (custom FromSegments) that joins segments without filtering. Also merge duplicate OPTIONS handlers into a single route to avoid collision.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
GET/HEAD /public/{spaceId}/kv/{key},GET /public/{spaceId}/kv?prefix=) for spaces namedpublicspace_id.name() == "public")Cache-Control: public, max-age=60, full CORS (Access-Control-Allow-Origin: *)If-None-Match→ 304 Not Modified)[public_spaces]config sectionFiles changed
src/routes/public.rs— new public endpoint handlerssrc/routes/mod.rs— module declarationsrc/lib.rs— route mounting and rate limiter statesrc/config.rs— PublicSpacesConfig structtinycloud-core/src/db.rs— public KV read methods on SpaceDatabaseTest plan
cargo buildsucceedscargo clippy -- -D warningspassesGET /public/{publicSpaceId}/kv/{key}returns data without authIf-None-Matchwith matching ETag returns 304