Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Prev Previous commit
Merge remote-tracking branch 'origin/main' into feat/enforce-owner-push
# Conflicts:
#	crates/gitlawb-node/src/api/protect.rs
#	crates/gitlawb-node/src/api/visibility.rs
  • Loading branch information
FrozenRaspberry committed Jun 24, 2026
commit 8ab7e50a0a64677ec8078f32155a260fb6182918
6 changes: 3 additions & 3 deletions crates/gitlawb-node/src/api/protect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use axum::extract::{Extension, Path, State};
use axum::http::StatusCode;
use axum::Json;

use crate::auth::{is_repo_owner, AuthenticatedDid};
use crate::auth::AuthenticatedDid;
use crate::error::{AppError, Result};
use crate::state::AppState;

Expand All @@ -25,7 +25,7 @@ pub async fn protect_branch(

// Only the repo owner can protect branches (DID-safe match, shared idiom).
let caller = &auth.0;
if !is_repo_owner(&record, caller) {
if !crate::api::did_matches(caller, &record.owner_did) {
return Err(AppError::Forbidden(
"only the repo owner can protect branches".into(),
));
Expand Down Expand Up @@ -58,7 +58,7 @@ pub async fn unprotect_branch(
.ok_or_else(|| AppError::RepoNotFound(format!("{owner}/{repo}")))?;

let caller = &auth.0;
if !is_repo_owner(&record, caller) {
if !crate::api::did_matches(caller, &record.owner_did) {
return Err(AppError::Forbidden(
"only the repo owner can unprotect branches".into(),
));
Expand Down
16 changes: 4 additions & 12 deletions crates/gitlawb-node/src/api/repos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use axum::Json;
use bytes::Bytes;
use std::sync::Arc;

use crate::auth::{caller_authorized_to_push, is_repo_owner, AuthenticatedDid};
use crate::auth::{caller_authorized_to_push, AuthenticatedDid};
use chrono::Utc;
use serde::{Deserialize, Serialize};
use uuid::Uuid;
Expand Down Expand Up @@ -162,7 +162,7 @@ pub async fn list_repos(
.iter()
.filter(|(r, _)| {
if let Some(owner) = &query.owner {
is_repo_owner(r, owner.as_str())
crate::api::did_matches(owner.as_str(), &r.owner_did)
} else {
true
}
Expand Down Expand Up @@ -557,7 +557,7 @@ pub async fn git_receive_pack(
.is_branch_protected(&record.id, branch)
.await
.unwrap_or(false)
&& !is_repo_owner(&record, &auth.0)
&& !crate::api::did_matches(&auth.0, &record.owner_did)
{
tracing::warn!(
branch = %branch,
Expand Down Expand Up @@ -1319,7 +1319,7 @@ fn to_response(record: &crate::db::RepoRecord, state: &AppState, star_count: i64
#[cfg(test)]
mod tests {
use super::owner_push_rejection;
use crate::auth::{caller_authorized_to_push, is_repo_owner};
use crate::auth::caller_authorized_to_push;
use crate::error::AppError;

const OWNER_DID: &str = "did:key:z6MkpTHR8VNsBxYAAWHut2Geadd9jSwuBV8xRoAnwWsdvktH";
Expand Down Expand Up @@ -1387,14 +1387,6 @@ mod tests {
assert!(owner_push_rejection(false, &repo, None).is_none());
}

#[test]
fn is_repo_owner_matches_full_and_short_did_only() {
let repo = repo_owned_by(OWNER_DID);
assert!(is_repo_owner(&repo, OWNER_DID));
assert!(is_repo_owner(&repo, OWNER_SHORT));
assert!(!is_repo_owner(&repo, STRANGER_DID));
}

#[test]
fn caller_authorized_to_push_is_owner_only_in_phase_1() {
let repo = repo_owned_by(OWNER_DID);
Expand Down
11 changes: 8 additions & 3 deletions crates/gitlawb-node/src/api/visibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use axum::http::StatusCode;
use axum::Json;
use serde::Deserialize;

use crate::auth::{is_repo_owner, AuthenticatedDid};
use crate::auth::AuthenticatedDid;
use crate::db::VisibilityMode;
use crate::error::{AppError, Result};
use crate::state::AppState;
Expand All @@ -26,8 +26,13 @@ pub struct RemoveVisibilityRequest {
}

fn require_owner(record: &crate::db::RepoRecord, caller: &str) -> Result<()> {
if !is_repo_owner(record, caller) {
return Err(AppError::Forbidden(
// DID-safe owner match (collapses did:key full vs bare on both sides, never
// across methods), shared with require_repo_owner — not a trailing-segment
// compare that only normalized the owner side.
if crate::api::did_matches(caller, &record.owner_did) {
Ok(())
} else {
Err(AppError::Forbidden(
"only the repo owner can manage visibility".into(),
))
}
Expand Down
27 changes: 7 additions & 20 deletions crates/gitlawb-node/src/auth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,16 @@ use crate::state::AppState;
#[derive(Clone, Debug)]
pub struct AuthenticatedDid(pub String);

/// Whether `caller` is the owner of `record`.
///
/// Owners are compared in both forms the rest of the codebase accepts: the full
/// `did:key:z6Mk…` string and its bare multibase suffix (`z6Mk…`). This is the
/// single source of truth for the owner-match logic that previously lived inline
/// in the receive-pack, branch-protection, and visibility paths.
pub fn is_repo_owner(record: &crate::db::RepoRecord, caller: &str) -> bool {
let owner_short = record
.owner_did
.split(':')
.next_back()
.unwrap_or(&record.owner_did);
caller == record.owner_did || caller == owner_short
}

/// Whether `caller` is authorized to push to `record`.
///
/// Phase 1 (`GITLAWB_ENFORCE_OWNER_PUSH`): owner-only. This is intentionally a
/// distinct, intent-named gate rather than a bare owner check so that Phase 2 can
/// extend it to honor a verified UCAN `git/push` capability as a pure addition
/// (`is_repo_owner(..) || ucan_grants_push(..)`) without rewriting call sites.
/// Phase 1 (`GITLAWB_ENFORCE_OWNER_PUSH`): owner-only, via the canonical
/// [`crate::api::did_matches`] owner comparison (DID-safe on both sides). This is
/// intentionally a distinct, intent-named gate rather than a bare owner check so
/// that Phase 2 can extend it to honor a verified UCAN `git/push` capability as a
/// pure addition (`did_matches(..) || ucan_grants_push(..)`) without rewriting
/// call sites.
pub fn caller_authorized_to_push(record: &crate::db::RepoRecord, caller: &str) -> bool {
is_repo_owner(record, caller)
crate::api::did_matches(caller, &record.owner_did)
}

use gitlawb_core::http_sig::{
Expand Down
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.