Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
2a8d64d
feat(core)!: verify_chain returns the proof chain's root issuer
Vasanthdev2004 Aug 14, 2026
13a2424
fix(node): gate two Unix-only tests so the crate compiles on Windows
Vasanthdev2004 Aug 14, 2026
1b1c972
feat(node): carry the verified UCAN and its root into the request
Vasanthdev2004 Aug 14, 2026
f8b9cf1
feat(node): add ucan_grants_push, anchored at the repo owner
Vasanthdev2004 Aug 14, 2026
d27f0be
feat(node): honour a delegated git/push capability on the push path
Vasanthdev2004 Aug 14, 2026
d141e59
feat(gl): gl ucan import stores a delegation for the push helper
Vasanthdev2004 Aug 14, 2026
3d81f57
feat(git-remote): send a delegated push capability as X-Ucan
Vasanthdev2004 Aug 14, 2026
8843c4f
test(git-remote): cover pack-POST URL splitting
Vasanthdev2004 Aug 14, 2026
a9e9c48
build: sync Cargo.lock for the git-remote-gitlawb dependencies
Vasanthdev2004 Aug 14, 2026
f455726
fix(core,gl,git-remote): close two review findings on delegated push
Vasanthdev2004 Aug 14, 2026
a2502fc
fix(core,node,gl,git-remote): close the second review round on delega…
Vasanthdev2004 Aug 14, 2026
d503655
fix(gl): restrict the delegations directory, and state the contract
Vasanthdev2004 Aug 14, 2026
5071524
fix(gl,git-remote): make a delegation issued the documented way actua…
Vasanthdev2004 Aug 15, 2026
5dfd8c5
fix(gl): refuse a relative or non-UTF-8 GITLAWB_KEY when deriving the…
Vasanthdev2004 Aug 15, 2026
e15fa73
fix(identity): one resolver for GITLAWB_KEY across gl and the helper
Vasanthdev2004 Aug 16, 2026
05fc52d
test(git-remote): cover delegation_header end to end
Vasanthdev2004 Aug 16, 2026
75aa1a0
fix(gl): finish the identity-path sweep on the write side
Vasanthdev2004 Aug 16, 2026
fad75a6
fix(gl,core): close round five — lazy home, envelope reads, honest re…
Vasanthdev2004 Aug 18, 2026
82f2484
fix(node,gl,git-remote): enforce repo narrowing at the node, honour t…
Vasanthdev2004 Aug 22, 2026
a47ea93
fix(gl): align the MCP ucan_show tool with gl ucan show
Vasanthdev2004 Aug 22, 2026
ec4399c
fix(gl): drop a needless borrow in quickstart's unix key write
Vasanthdev2004 Aug 22, 2026
1ab55e5
fix(node,gl,git-remote): fix a delegation's scope at issuance
Vasanthdev2004 Aug 22, 2026
89fa647
Merge origin/main into feat/ucan-push-authorization
Vasanthdev2004 Aug 27, 2026
9cf48f5
fix(gl): drop an unused import in the unix-only refresh tests
Vasanthdev2004 Aug 27, 2026
04e7941
fix(node): pass the UCAN extension at the last two receive-pack call …
Vasanthdev2004 Aug 27, 2026
f79309b
fix(core,node,gl,git-remote): one definition of a usable push capability
Vasanthdev2004 Sep 8, 2026
4dc62b2
fix(node): drop repo_capability_matches, orphaned by the shared push …
Vasanthdev2004 Sep 8, 2026
1da4251
fix(core,gl): bound every proof-chain walk and make verify report the…
Vasanthdev2004 Sep 8, 2026
fb831b1
docs: state the two gates a delegated push crosses, and finish the sweep
Vasanthdev2004 Sep 8, 2026
8b91f28
fix(gl): store one repository per imported delegation; pin the two-ga…
Vasanthdev2004 Sep 8, 2026
e3314c6
fix(gl,core): sanitize token-derived output, prove the publish step, …
Vasanthdev2004 Sep 8, 2026
1b5cb7d
test(gl): count the MCP tool list at 41 with ucan_import
Vasanthdev2004 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
Prev Previous commit
Next Next commit
feat(gl): gl ucan import stores a delegation for the push helper
The git remote helper needs a delegation on disk in a location it can derive
from a gitlawb:// URL alone. Files key on the bare base58 owner key because
did:key contains a colon, which Windows will not accept in a filename, and the
same identity appears in both full and bare form across this codebase — storing
under one and looking up by the other would silently miss.

Import decodes the token so a malformed delegation fails here, where the error
is actionable, rather than surfacing as an unexplained 403 in the middle of a
git push. A delegation naming no repository is rejected with the resources it
did carry, since that is almost always a wrong --cap argument.
  • Loading branch information
Vasanthdev2004 committed Aug 16, 2026
commit d141e59dc2d9104eaf9e4ef473219d66375d8466
4 changes: 3 additions & 1 deletion crates/gl/src/identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ pub async fn run(cmd: IdentityCmd) -> Result<()> {
}
}

fn gitlawb_dir(override_dir: Option<PathBuf>) -> Result<PathBuf> {
/// Resolve the identity directory, honouring an explicit override.
/// Public so sibling commands (`gl ucan import`) store alongside the identity.
pub fn gitlawb_dir(override_dir: Option<PathBuf>) -> Result<PathBuf> {
if let Some(d) = override_dir {
return Ok(d);
}
Expand Down
107 changes: 107 additions & 0 deletions crates/gl/src/ucan_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,38 @@ pub enum UcanCmd {
/// UCAN JSON token (or path to file containing it)
token: String,
},
/// Store a delegation received from a repo owner, so `git push` can present it
Import {
/// UCAN JSON token (or path to a file containing it)
token: String,
/// Identity directory
#[arg(long)]
dir: Option<PathBuf>,
},
}

/// Where a delegation for `owner_did`/`repo` is stored.
///
/// Keyed on the bare base58 key rather than the full DID: `did:key:` contains a
/// colon, which is not a legal filename character on Windows, and the same
/// identity appears in both forms across this codebase — storing under one form
/// and looking up by the other would silently miss.
///
/// `git-remote-gitlawb` derives the same path from a `gitlawb://` URL alone; the
/// two must agree, and the helper carries a pointer back to this function.
pub fn delegation_path(dir: &std::path::Path, owner_did: &str, repo: &str) -> PathBuf {
let bare = owner_did.strip_prefix("did:key:").unwrap_or(owner_did);
dir.join("delegations").join(format!("{bare}__{repo}.ucan"))
}

/// Pull the repo this capability names out of `gitlawb://repos/<owner>/<repo>`.
fn repo_from_resource(with: &str) -> Option<(String, String)> {
let rest = with.strip_prefix("gitlawb://repos/")?;
let (owner, name) = rest.rsplit_once('/')?;
if owner.is_empty() || name.is_empty() {
return None;
}
Some((owner.to_string(), name.to_string()))
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}

pub async fn run(args: UcanArgs) -> Result<()> {
Expand All @@ -68,7 +100,57 @@ pub async fn run(args: UcanArgs) -> Result<()> {
} => cmd_delegate(to, cap, can, expiry, out, dir, json_out).await,
UcanCmd::Show { dir } => cmd_show(dir).await,
UcanCmd::Verify { token } => cmd_verify(token).await,
UcanCmd::Import { token, dir } => cmd_import(token, dir).await,
}
}

/// Store a delegation where `git-remote-gitlawb` will look for it on push.
///
/// The token is decoded here rather than at push time so a malformed delegation
/// fails where the error is actionable, instead of surfacing as an unexplained
/// 403 in the middle of a `git push`.
async fn cmd_import(token: String, dir: Option<PathBuf>) -> Result<()> {
let raw = match std::fs::read_to_string(&token) {
Ok(contents) => contents.trim().to_string(),
Err(_) => token.clone(),
};

let ucan = Ucan::decode(&raw).context(
"not a valid UCAN token — pass the JSON emitted by `gl ucan delegate`, or a path to it",
)?;

let push_caps: Vec<(String, String)> = ucan
.payload
.att
.iter()
.filter_map(|cap| repo_from_resource(&cap.with))
.collect();

if push_caps.is_empty() {
anyhow::bail!(
"this delegation names no repository — expected a capability on \
gitlawb://repos/<owner>/<repo>, found: {}",
ucan.payload
.att
.iter()
.map(|c| c.with.as_str())
.collect::<Vec<_>>()
.join(", ")
);
}

let base = crate::identity::gitlawb_dir(dir)?;
std::fs::create_dir_all(base.join("delegations"))
.with_context(|| format!("could not create {}", base.join("delegations").display()))?;

for (owner, repo) in &push_caps {
let path = delegation_path(&base, owner, repo);
std::fs::write(&path, &raw)
.with_context(|| format!("could not write {}", path.display()))?;
println!("Stored delegation for {owner}/{repo} at {}", path.display());
}

Ok(())
}

async fn cmd_delegate(
Expand Down Expand Up @@ -348,3 +430,28 @@ mod tests {
.unwrap();
}
}

#[cfg(test)]
mod delegation_store_tests {
use super::*;

#[test]
fn delegation_path_strips_the_did_prefix_and_separates_owner_from_repo() {
let base = std::path::Path::new("/tmp/id");
let expected = base.join("delegations").join("z6MkAbc__myrepo.ucan");

assert_eq!(
delegation_path(base, "did:key:z6MkAbc", "myrepo"),
expected,
"the bare key keys the file: `did:key:` contains ':', which is not a \
legal filename character on Windows"
);
// A bare owner and a full DID must resolve to the same file, or a
// delegation stored under one form is invisible to a lookup by the other.
assert_eq!(
delegation_path(base, "z6MkAbc", "myrepo"),
expected,
"bare and full owner forms must address the same delegation"
);
}
}