Repository navigation
feat: path-scoped repository visibility (Phase 1) for #18 #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kevincodex1
merged 2 commits into
Twigpine:main
from
beardthelion:feat/path-scoped-visibility
Jun 5, 2026
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
feat: path-scoped repository visibility (Phase 1)
Implements per-path read visibility for repositories, addressing #18. A repo's private status becomes a property of a path subtree rather than a whole-repo boolean, enforced on the git read path via the node's existing DID identity and RFC 9421 HTTP signatures. Phase 1 scope (whole-repo enforcement, data model for the rest): - visibility_rules data model (path_glob, mode, reader_dids) + DB access - visibility_check pure decision function (owner-always-allow, most- specific rule wins, reader-DID allow-list, is_public fallback) - enforcement on git_info_refs and git_upload_pack: unauthorized reads return 404 byte-identical to a missing repo (no existence leak) - owner-only management API: PUT/DELETE/GET /api/v1/repos/{o}/{r}/visibility - gl visibility set/remove/list CLI mode A (hide) is whole-repo ("/") only by construction: hiding a subtree's existence would rewrite ancestor tree hashes and diverge history. Subtrees use mode B (content withheld, SHAs intact); B-subtree clone filtering is deferred to a later phase and the CLI/API say so. 260 tests (69 node + 191 gl); fmt + clippy clean.
- Loading branch information
commit b5fc7dd5bc04d01fb19a55e15eb5de3e769a538e
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,4 +17,5 @@ pub mod repos; | |
| pub mod resolve; | ||
| pub mod stars; | ||
| pub mod tasks; | ||
| pub mod visibility; | ||
| pub mod webhooks; | ||
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,159 @@ | ||
| //! Path-scoped visibility management API. Owner-only, mirrors `api/protect.rs`. | ||
|
|
||
| use axum::extract::{Extension, Path, State}; | ||
| use axum::http::StatusCode; | ||
| use axum::Json; | ||
| use serde::Deserialize; | ||
|
|
||
| use crate::auth::AuthenticatedDid; | ||
| use crate::db::VisibilityMode; | ||
| use crate::error::{AppError, Result}; | ||
| use crate::state::AppState; | ||
|
|
||
| #[derive(Deserialize)] | ||
| pub struct SetVisibilityRequest { | ||
| pub path_glob: String, | ||
| /// "a" or "b"; defaults to "b" if absent or unrecognized. | ||
| #[serde(default)] | ||
| pub mode: Option<String>, | ||
| #[serde(default)] | ||
| pub reader_dids: Vec<String>, | ||
| } | ||
|
|
||
| #[derive(Deserialize)] | ||
| pub struct RemoveVisibilityRequest { | ||
| pub path_glob: String, | ||
| } | ||
|
|
||
| fn require_owner(record: &crate::db::RepoRecord, caller: &str) -> Result<()> { | ||
| let owner_short = record | ||
| .owner_did | ||
| .split(':') | ||
| .next_back() | ||
| .unwrap_or(&record.owner_did); | ||
| if caller != record.owner_did && caller != owner_short { | ||
| return Err(AppError::BadRequest( | ||
| "only the repo owner can manage visibility".into(), | ||
| )); | ||
| } | ||
| Ok(()) | ||
| } | ||
|
|
||
| /// PUT /api/v1/repos/{owner}/{repo}/visibility | ||
| pub async fn set_visibility( | ||
| State(state): State<AppState>, | ||
| Extension(auth): Extension<AuthenticatedDid>, | ||
| Path((owner, repo)): Path<(String, String)>, | ||
| Json(req): Json<SetVisibilityRequest>, | ||
| ) -> Result<(StatusCode, Json<serde_json::Value>)> { | ||
| let record = state | ||
| .db | ||
| .get_repo(&owner, &repo) | ||
| .await? | ||
| .ok_or_else(|| AppError::RepoNotFound(format!("{owner}/{repo}")))?; | ||
| require_owner(&record, &auth.0)?; | ||
|
|
||
| let mode = match req.mode.as_deref() { | ||
| Some("a") => VisibilityMode::A, | ||
| _ => VisibilityMode::B, | ||
| }; | ||
|
|
||
| // Mode A hides existence and is only coherent for the whole repo; a subtree | ||
| // cannot hide its existence without rewriting git history (see spec). | ||
| if mode == VisibilityMode::A && req.path_glob != "/" { | ||
| return Err(AppError::BadRequest( | ||
| "mode 'a' (hide) is only allowed for the whole repo (path_glob '/'); use mode 'b' for subtrees".into(), | ||
| )); | ||
| } | ||
|
|
||
| // An empty reader_dids list is valid and intentional: the owner is always | ||
| // allowed by visibility_check, so a "/" rule with no readers is exactly the | ||
| // whole-repo "private to owner only" case. | ||
| state | ||
| .db | ||
| .set_visibility_rule(&record.id, &req.path_glob, mode, &req.reader_dids, &auth.0) | ||
| .await?; | ||
|
|
||
| let subtree_warning = req.path_glob != "/"; | ||
| tracing::info!( | ||
| repo = %repo, caller = %auth.0, path_glob = %req.path_glob, mode = %mode.as_str(), | ||
| subtree_pending = subtree_warning, | ||
| "visibility rule set" | ||
| ); | ||
|
|
||
| Ok(( | ||
| StatusCode::CREATED, | ||
| Json(serde_json::json!({ | ||
| "status": "set", | ||
| "repo": format!("{owner}/{repo}"), | ||
| "path_glob": req.path_glob, | ||
| "mode": mode.as_str(), | ||
| "reader_dids": req.reader_dids, | ||
| "subtree_clone_enforcement_pending": subtree_warning, | ||
| })), | ||
| )) | ||
| } | ||
|
|
||
| /// DELETE /api/v1/repos/{owner}/{repo}/visibility | ||
| pub async fn remove_visibility( | ||
| State(state): State<AppState>, | ||
| Extension(auth): Extension<AuthenticatedDid>, | ||
| Path((owner, repo)): Path<(String, String)>, | ||
| Json(req): Json<RemoveVisibilityRequest>, | ||
| ) -> Result<Json<serde_json::Value>> { | ||
| let record = state | ||
| .db | ||
| .get_repo(&owner, &repo) | ||
| .await? | ||
| .ok_or_else(|| AppError::RepoNotFound(format!("{owner}/{repo}")))?; | ||
| require_owner(&record, &auth.0)?; | ||
|
|
||
| state | ||
| .db | ||
| .remove_visibility_rule(&record.id, &req.path_glob) | ||
| .await?; | ||
|
|
||
| tracing::info!( | ||
| repo = %repo, caller = %auth.0, path_glob = %req.path_glob, | ||
| "visibility rule removed" | ||
| ); | ||
|
|
||
| Ok(Json(serde_json::json!({ | ||
| "status": "removed", | ||
| "repo": format!("{owner}/{repo}"), | ||
| "path_glob": req.path_glob, | ||
| }))) | ||
| } | ||
|
|
||
| /// GET /api/v1/repos/{owner}/{repo}/visibility | ||
| pub async fn list_visibility( | ||
| State(state): State<AppState>, | ||
| Extension(auth): Extension<AuthenticatedDid>, | ||
| Path((owner, repo)): Path<(String, String)>, | ||
| ) -> Result<Json<serde_json::Value>> { | ||
| let record = state | ||
| .db | ||
| .get_repo(&owner, &repo) | ||
| .await? | ||
| .ok_or_else(|| AppError::RepoNotFound(format!("{owner}/{repo}")))?; | ||
| require_owner(&record, &auth.0)?; | ||
|
|
||
| let rules = state.db.list_visibility_rules(&record.id).await?; | ||
| let rules_json: Vec<_> = rules | ||
| .into_iter() | ||
| .map(|r| { | ||
| serde_json::json!({ | ||
| "path_glob": r.path_glob, | ||
| "mode": r.mode.as_str(), | ||
| "reader_dids": r.reader_dids, | ||
| "created_by": r.created_by, | ||
| }) | ||
| }) | ||
| .collect(); | ||
|
|
||
| Ok(Json(serde_json::json!({ | ||
| "repo": format!("{owner}/{repo}"), | ||
| "count": rules_json.len(), | ||
| "rules": rules_json, | ||
| }))) | ||
| } | ||
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.