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
fix(gl,core): close round five — lazy home, envelope reads, honest re…
…gister

Five findings from the round-five review, four of them introduced by round four's
own centralisation.

resolve_key_path and resolve_identity_dir opened with `home_dir()?`, but
identity_key_path only needs a home when the key is unset, empty, or `~/`-prefixed.
On a host where `dirs::home_dir()` returns None — no HOME and no passwd entry, an
ordinary container shape — a perfectly valid absolute GITLAWB_KEY was discarded and
the push went out unsigned, blaming the home directory for a setting the operator
had got right. The pre-round code resolved an absolute key without consulting home
at all, so this was a regression, not an inherited gap. The core resolvers now take
`Option<&Path>` and demand a home only where the value being resolved needs one.

`gl ucan show` called Ucan::decode on the whole of ucan.json, but register, init,
and quickstart all write an envelope — {"ucan", "node", "did", "saved_at"} — and
doctor and quickstart already read it as one. Ucan is {payload, s}, so show failed
with "missing field `payload`" immediately after a successful `gl register`. It now
reads the envelope like every other reader, and still accepts a bare token so files
written by an older gl stay readable. The predating mismatch belongs to this round
because this round rerouted cmd_show and claimed to unify the identity flow.

`gl register` printed "You are now a verified agent" even when the node returned no
bootstrap UCAN — the exact shape the previous commit message said it existed to
remove, one line below the fix. The closing line is now inside the branch that
actually stored a token.

The MCP `ucan_show` tool called gitlawb_dir(None) while every sibling tool in
call_tool honours the server's --dir, so one session read two identity directories.
The parameter was already in scope.

Six `--dir` help texts still promised "default: ~/.gitlawb" after the resolver
stopped having that default.

Both behavioural fixes were verified by mutation: demanding a home unconditionally
turns an_absolute_key_resolves_without_a_home_directory red, and dropping the
envelope branch turns the_register_envelope_decodes red.
  • Loading branch information
Vasanthdev2004 committed Aug 18, 2026
commit fad75a65797bfadfe549ca2596ae13eac2d3013d
14 changes: 6 additions & 8 deletions crates/git-remote-gitlawb/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1006,28 +1006,26 @@ fn load_keypair() -> Option<Keypair> {
/// helper mid-push, so a misconfiguration is logged and the push continues
/// unsigned rather than aborting the transfer.
fn resolve_key_path() -> Option<std::path::PathBuf> {
let home = home_dir()?;
gitlawb_core::identity_path::identity_key_path(&home)
gitlawb_core::identity_path::identity_key_path(home_dir().as_deref())
.inspect_err(|e| tracing::warn!("cannot resolve the identity key path: {e}"))
.ok()
}

/// The directory holding `identity.pem` and `delegations/`.
fn resolve_identity_dir() -> Option<std::path::PathBuf> {
let home = home_dir()?;
gitlawb_core::identity_path::identity_dir(&home)
gitlawb_core::identity_path::identity_dir(home_dir().as_deref())
.inspect_err(|e| tracing::warn!("cannot resolve the identity directory: {e}"))
.ok()
}

/// `dirs`, not `$HOME`: the old code fell back to `"."` when `HOME` was unset,
/// which on Windows is always, so the default key resolved against whatever
/// directory git happened to invoke the helper from.
///
/// `None` is not fatal — an absolute `GITLAWB_KEY` resolves without it, and only
/// the default and `~/`-prefixed forms need a home at all.
fn home_dir() -> Option<std::path::PathBuf> {
dirs::home_dir().or_else(|| {
tracing::warn!("could not determine the home directory; pushing without a delegation");
None
})
dirs::home_dir()
}

// ── Tests ─────────────────────────────────────────────────────────────────────
Expand Down
91 changes: 75 additions & 16 deletions crates/gitlawb-core/src/identity_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,22 @@ pub const DEFAULT_DIR_NAME: &str = ".gitlawb";
/// An empty `GITLAWB_KEY` counts as unset. That is what a shell leaves behind for
/// `FOO=` and for an unset variable expanded into a wrapper script, and reading it
/// as a path would resolve against the process working directory instead.
pub fn identity_key_path(home: &Path) -> Result<PathBuf> {
pub fn identity_key_path(home: Option<&Path>) -> Result<PathBuf> {
// `var_os`, not `var`: `var` folds a non-UTF-8 value into the same `Err` as
// unset, so an operator whose key path is not valid UTF-8 would silently get
// the default directory rather than theirs — or an error naming the real
// problem.
match std::env::var_os(KEY_ENV) {
Some(raw) if !raw.is_empty() => resolve_key_value(Path::new(&raw), home),
_ => Ok(home.join(DEFAULT_DIR_NAME).join(KEY_FILE_NAME)),
_ => Ok(require_home(home)?
.join(DEFAULT_DIR_NAME)
.join(KEY_FILE_NAME)),
}
}

/// The directory holding `identity.pem` and `delegations/` — the parent of
/// [`identity_key_path`].
pub fn identity_dir(home: &Path) -> Result<PathBuf> {
pub fn identity_dir(home: Option<&Path>) -> Result<PathBuf> {
let key = identity_key_path(home)?;
key.parent().map(Path::to_path_buf).ok_or_else(|| {
Error::Key(format!(
Expand All @@ -57,11 +59,27 @@ pub fn identity_dir(home: &Path) -> Result<PathBuf> {
})
}

/// The home directory, demanded only where the value being resolved needs it.
///
/// An absolute `GITLAWB_KEY` never needs home, so requiring it up front would
/// discard a perfectly good key on a host where `dirs::home_dir()` returns `None`
/// — no `HOME` and no passwd entry, which is an ordinary container shape. The
/// helper would then push unsigned, blaming the home directory for a setting the
/// operator had configured correctly.
fn require_home(home: Option<&Path>) -> Result<&Path> {
home.ok_or_else(|| {
Error::Key(format!(
"could not determine the home directory, which is needed to resolve this \
{KEY_ENV} value. Set {KEY_ENV} to an absolute path to avoid needing it."
))
})
}

/// Apply the `GITLAWB_KEY` rules to a raw value.
///
/// Split out from [`identity_key_path`] so the rules can be tested without setting
/// a process-global environment variable, which would make the tests race.
fn resolve_key_value(raw: &Path, home: &Path) -> Result<PathBuf> {
fn resolve_key_value(raw: &Path, home: Option<&Path>) -> Result<PathBuf> {
let path = expand_tilde(raw, home)?;

if !path.is_absolute() {
Expand Down Expand Up @@ -95,7 +113,7 @@ fn resolve_key_value(raw: &Path, home: &Path) -> Result<PathBuf> {
/// what lets the value stay an `OsStr` end to end: the helper's old
/// `str::strip_prefix("~/")` needed a `String` first, which is why it reached for
/// `env::var` and folded every non-UTF-8 path into "unset".
fn expand_tilde(path: &Path, home: &Path) -> Result<PathBuf> {
fn expand_tilde(path: &Path, home: Option<&Path>) -> Result<PathBuf> {
let mut components = path.components();
match components.next() {
Some(Component::Normal(first)) if first == OsStr::new("~") => {
Expand All @@ -107,7 +125,7 @@ fn expand_tilde(path: &Path, home: &Path) -> Result<PathBuf> {
path.display()
)));
}
Ok(home.join(rest))
Ok(require_home(home)?.join(rest))
}
_ => Ok(path.to_path_buf()),
}
Expand All @@ -131,12 +149,12 @@ mod tests {
#[test]
fn absolute_value_is_taken_verbatim() {
let raw = home().join("data").join("keys").join(KEY_FILE_NAME);
assert_eq!(resolve_key_value(&raw, &home()).unwrap(), raw);
assert_eq!(resolve_key_value(&raw, Some(&home())).unwrap(), raw);
}

#[test]
fn tilde_slash_expands_to_the_home_directory() {
let resolved = resolve_key_value(Path::new("~/keys/identity.pem"), &home()).unwrap();
let resolved = resolve_key_value(Path::new("~/keys/identity.pem"), Some(&home())).unwrap();
assert_eq!(resolved, home().join("keys").join(KEY_FILE_NAME));
}

Expand All @@ -145,7 +163,8 @@ mod tests {
/// shell, and the two binaries used to reach it by different routes.
#[test]
fn the_tilde_spelling_of_the_default_resolves_to_the_default() {
let resolved = resolve_key_value(Path::new("~/.gitlawb/identity.pem"), &home()).unwrap();
let resolved =
resolve_key_value(Path::new("~/.gitlawb/identity.pem"), Some(&home())).unwrap();
assert_eq!(resolved, home().join(DEFAULT_DIR_NAME).join(KEY_FILE_NAME));
}

Expand All @@ -156,7 +175,7 @@ mod tests {
fn relative_values_are_refused() {
for raw in ["identity.pem", "keys/identity.pem", "./keys/identity.pem"] {
assert!(
resolve_key_value(Path::new(raw), &home()).is_err(),
resolve_key_value(Path::new(raw), Some(&home())).is_err(),
"{raw} is relative and must be refused"
);
}
Expand All @@ -168,7 +187,7 @@ mod tests {
fn unsupported_tilde_forms_are_refused() {
for raw in ["~", "~/", "~someone/keys/identity.pem"] {
assert!(
resolve_key_value(Path::new(raw), &home()).is_err(),
resolve_key_value(Path::new(raw), Some(&home())).is_err(),
"{raw} must be refused rather than resolved"
);
}
Expand All @@ -177,7 +196,7 @@ mod tests {
/// The root has no parent, so the delegation store would have nowhere to go.
#[test]
fn the_filesystem_root_is_refused() {
assert!(resolve_key_value(Path::new("/"), &home()).is_err());
assert!(resolve_key_value(Path::new("/"), Some(&home())).is_err());
}

/// The whole point of `var_os`: a non-UTF-8 value must reach the rules rather
Expand All @@ -191,14 +210,14 @@ mod tests {

let relative = OsString::from_vec(b"keys/\xFF/identity.pem".to_vec());
assert!(
resolve_key_value(Path::new(&relative), &home()).is_err(),
resolve_key_value(Path::new(&relative), Some(&home())).is_err(),
"a non-UTF-8 relative path must be refused, not silently defaulted"
);

let mut absolute = OsString::from("/data/");
absolute.push(OsString::from_vec(vec![0xFF]));
absolute.push("/identity.pem");
let resolved = resolve_key_value(Path::new(&absolute), &home()).unwrap();
let resolved = resolve_key_value(Path::new(&absolute), Some(&home())).unwrap();
assert_eq!(resolved.as_os_str(), absolute.as_os_str());
}

Expand All @@ -215,9 +234,15 @@ mod tests {
let restore = std::env::var_os(KEY_ENV);

std::env::remove_var(KEY_ENV);
let unset = (identity_key_path(&home()), identity_dir(&home()));
let unset = (
identity_key_path(Some(&home())),
identity_dir(Some(&home())),
);
std::env::set_var(KEY_ENV, "");
let empty = (identity_key_path(&home()), identity_dir(&home()));
let empty = (
identity_key_path(Some(&home())),
identity_dir(Some(&home())),
);

match restore {
Some(v) => std::env::set_var(KEY_ENV, v),
Expand All @@ -238,3 +263,37 @@ mod tests {
}
}
}

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

/// An absolute key needs no home directory. Demanding one up front discarded a
/// correctly-configured `GITLAWB_KEY` on any host where `dirs::home_dir()`
/// returns `None` — no `HOME` and no passwd entry, an ordinary container shape —
/// and the helper then pushed unsigned while blaming the home directory.
#[test]
fn an_absolute_key_resolves_without_a_home_directory() {
let raw = if cfg!(windows) {
r"C:\data\keys\identity.pem"
} else {
"/data/keys/identity.pem"
};
let resolved = resolve_key_value(Path::new(raw), None)
.expect("an absolute key must not need a home directory");
assert_eq!(resolved, PathBuf::from(raw));
assert_eq!(resolved.parent().unwrap(), Path::new(raw).parent().unwrap());
}

/// The forms that genuinely need a home still say so, rather than resolving
/// somewhere arbitrary.
#[test]
fn the_forms_that_need_a_home_report_its_absence() {
let err = resolve_key_value(Path::new("~/keys/identity.pem"), None)
.expect_err("a ~/ path cannot resolve without a home directory");
assert!(
err.to_string().contains("home directory"),
"the error must name the missing home directory, got: {err}"
);
}
}
2 changes: 1 addition & 1 deletion crates/gl/src/doctor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub struct DoctorArgs {
#[arg(long, default_value = PUBLIC_NODE, env = "GITLAWB_NODE")]
pub node: String,

/// Identity directory (default: ~/.gitlawb)
/// Identity directory (default: the parent of $GITLAWB_KEY, else ~/.gitlawb)
#[arg(long)]
pub dir: Option<PathBuf>,
}
Expand Down
7 changes: 5 additions & 2 deletions crates/gl/src/identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,11 @@ pub fn gitlawb_dir(override_dir: Option<PathBuf>) -> Result<PathBuf> {
if let Some(d) = override_dir {
return Ok(d);
}
let home = dirs::home_dir().context("could not determine the home directory")?;
gitlawb_core::identity_path::identity_dir(&home).map_err(|e| anyhow::anyhow!("{e}"))
// `home_dir()` is passed as an Option rather than demanded here: an absolute
// GITLAWB_KEY resolves without a home directory, and a host that has none is a
// normal container shape, not a reason to refuse a correctly-configured key.
let home = dirs::home_dir();
gitlawb_core::identity_path::identity_dir(home.as_deref()).map_err(|e| anyhow::anyhow!("{e}"))
}

fn key_path(dir: &Path) -> PathBuf {
Expand Down
2 changes: 1 addition & 1 deletion crates/gl/src/ipfs_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub enum IpfsCmd {
List {
#[arg(long, default_value = "https://node.gitlawb.com", env = "GITLAWB_NODE")]
node: String,
/// Identity directory (default: ~/.gitlawb)
/// Identity directory (default: the parent of $GITLAWB_KEY, else ~/.gitlawb)
#[arg(long)]
dir: Option<PathBuf>,
},
Expand Down
6 changes: 5 additions & 1 deletion crates/gl/src/mcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,11 @@ async fn call_tool(
]))?),

"ucan_show" => {
let ucan_path = crate::identity::gitlawb_dir(None)?.join("ucan.json");
// The directory the server was started with, like every sibling tool.
// Reading the default here while the rest honour `--dir` splits one MCP
// session across two identity directories.
let ucan_path = crate::identity::gitlawb_dir(dir.map(std::path::Path::to_path_buf))?
.join("ucan.json");
if ucan_path.exists() {
let content = std::fs::read_to_string(ucan_path)?;
Ok(content)
Expand Down
2 changes: 1 addition & 1 deletion crates/gl/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub enum NodeCmd {
Status {
#[arg(long, default_value = "https://node.gitlawb.com", env = "GITLAWB_NODE")]
node: String,
/// Identity directory (default: ~/.gitlawb)
/// Identity directory (default: the parent of $GITLAWB_KEY, else ~/.gitlawb)
#[arg(long)]
dir: Option<PathBuf>,
},
Expand Down
2 changes: 1 addition & 1 deletion crates/gl/src/quickstart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub struct QuickstartArgs {
#[arg(long, default_value = PUBLIC_NODE, env = "GITLAWB_NODE")]
pub node: String,

/// Identity directory (default: ~/.gitlawb)
/// Identity directory (default: the parent of $GITLAWB_KEY, else ~/.gitlawb)
#[arg(long)]
pub dir: Option<PathBuf>,

Expand Down
15 changes: 11 additions & 4 deletions crates/gl/src/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub struct RegisterArgs {
#[arg(long)]
pub model: Option<String>,

/// Identity directory (default: ~/.gitlawb)
/// Identity directory (default: the parent of $GITLAWB_KEY, else ~/.gitlawb)
#[arg(long)]
pub dir: Option<PathBuf>,
}
Expand Down Expand Up @@ -105,11 +105,18 @@ pub async fn run(args: RegisterArgs) -> Result<()> {
println!();
// The real path, not the default one: `GITLAWB_KEY` moves it, and an operator
// told to look in `~/.gitlawb` would find nothing there.
// Registration without a stored token means the registration-gated
// capabilities never arrived, so the closing line must not claim they did.
match &saved_to {
Some(path) => println!(" Bootstrap UCAN saved to {}", path.display()),
None => println!(" The node returned no bootstrap UCAN."),
Some(path) => {
println!(" Bootstrap UCAN saved to {}", path.display());
println!(" You are now a verified agent on the gitlawb network.");
}
None => {
println!(" The node returned no bootstrap UCAN, so this identity is not");
println!(" a verified agent yet. Re-run `gl register` once the node issues one.");
}
}
println!(" You are now a verified agent on the gitlawb network.");

Ok(())
}
Expand Down
Loading
Loading