Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
54 changes: 52 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ move files in production, read [SECURITY.md](SECURITY.md) first and expect
header protection, 0-RTT resume (`--encrypt`); optional Ed25519 server
authentication (`--server-key`)
- **Authenticated senders** — a daemon can accept only the senders it has
been given the keys for, and refuse anonymous ones (`--allow-peer`,
`--require-peer-auth`); see
been given the keys for, refuse anonymous ones, and take signed expiring
grants scoped to one directory (`--allow-peer`, `--require-peer-auth`,
`--trust-anchor`); see
[Who may send to a daemon](#who-may-send-to-a-daemon)
- **Compressed** — per-chunk zstd with a per-packet flag
(`--compression balanced`)
Expand Down Expand Up @@ -235,6 +236,55 @@ read nothing, so a sender configured with one still transfers to a daemon
that has never heard of client authentication. Verified against a
pre-existing daemon binary, not only in tests.

### Narrower, expiring permissions

`--allow-peer` says *this sender may write here*, and keeps saying it until
somebody edits the configuration. Where permissions are handed out per job,
that is the wrong granularity. A **grant** is the narrower statement — this
sender, into this directory, until this time — signed by a key the daemon
was told to trust:

```bash
# Once: a signing key. Its public half is the anchor daemons are given.
favonius-daemon keygen --output anchor.key
favonius-daemon pubkey --identity anchor.key # prints the anchor

# Per job: issue a grant. Prints hex to hand to the sender.
favonius-daemon grant --anchor anchor.key \
--source <sender pubkey> --destination <daemon pubkey> \
--prefix /srv/in/nightly --run-id job-42 --ttl-secs 300

# The daemon accepts grants from that anchor, and requires one
favonius-daemon --dest-root /srv/in --identity daemon.key \
--trust-anchor <anchor pubkey> --require-grant

# The sender presents it
favonius send big.tar "host:7801:/srv/in/nightly/big.tar" \
--encrypt --identity sender.key --grant <hex or file>
```

A grant names the sender it is for, the **daemon** it is for, a path prefix
and an expiry, and the daemon checks all four offline — no callback, no
directory service. Naming the daemon matters: without it, a permission to
write to one machine would be accepted by every machine trusting the same
anchor. Expiry is the only revocation here; a grant cannot be recalled, it
runs out, which is why the default TTL is minutes.

`--trust-anchor` may be repeated, and that is what makes rotating the
signing key possible without a flag day: publish the new anchor, let daemons
accept both, switch issuance, then drop the retired one.

`--require-grant` implies `--require-peer-auth`, because a grant names its
bearer and demanding one from a sender that proved nothing would be
demanding a document nobody checked the bearer of.

**0-RTT resume is refused while any of this is in force.** A resumed session
carries no identity and no grant, so honouring one would let a sender
authorised for five minutes and one directory keep writing anywhere under
`--dest-root` for as long as its ticket lived. Such daemons do not issue
tickets either, so senders never attempt a reconnection that would be
rejected.

**Two limits worth knowing.** `--require-peer-auth` disables the TCP
fallback, which has no handshake and therefore no way to authenticate
anyone — leaving it listening would publish a door with no lock beside one
Expand Down
35 changes: 31 additions & 4 deletions crates/ahp-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ enum Command {
/// is calling. Requires --encrypt.
#[arg(long)]
identity: Option<std::path::PathBuf>,
/// A signed permission to present to the daemon: hex, or a file
/// containing it. Issued by whatever holds the daemon's trust
/// anchor. Requires --identity, since a grant names the sender it
/// was issued for.
#[arg(long)]
grant: Option<String>,
/// Refuse to transfer unless the daemon confirms it authenticated
/// this client. Without it, a daemon too old to understand the
/// identity accepts the transfer and never says it ignored it.
Expand Down Expand Up @@ -242,7 +248,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
return Ok(());
}

Command::Send { source, destination, compression, congestion, ack_mode, streams, pacing, transport, encrypt, header_protect, resume, server_key, identity, require_peer_auth, adaptive, policy_path, include, exclude, dry_run, bandwidth_limit } => {
Command::Send { source, destination, compression, congestion, ack_mode, streams, pacing, transport, encrypt, header_protect, resume, server_key, identity, grant, require_peer_auth, adaptive, policy_path, include, exclude, dry_run, bandwidth_limit } => {
// No code path reads this. It was destructured away with `..`,
// so `--bandwidth-limit 10` capped nothing and said nothing —
// the user asked for a rate limit and got line rate. Fail
Expand Down Expand Up @@ -364,6 +370,25 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
);
std::process::exit(2);
}
let grant_blob = match grant.as_deref() {
Some(value) => match ahp_crypto::signatures::parse_hex_blob(value) {
Ok(b) => Some(b),
Err(e) => { eprintln!("Error: --grant {e}"); std::process::exit(2); }
},
None => None,
};
// A grant travels appended to the identity that it names, so
// one without an identity would arrive unattached to anyone
// and be ignored — silently, which is the failure worth
// refusing outright.
if grant_blob.is_some() && client_identity.is_none() {
eprintln!(
"Error: --grant needs --identity: a grant names the sender it was \
issued for, and the daemon checks it against the identity that \
authenticated."
);
std::process::exit(2);
}
if client_identity.is_some() && !encrypt {
eprintln!(
"Error: --identity needs --encrypt: the identity is presented inside \
Expand Down Expand Up @@ -446,7 +471,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let failed = run_ahp_sends(
remote_addr, &items, cc_profile, ack, streams, &pacing, encrypt,
compress_profile, resume, adaptive_policy.as_mut(), header_protect,
pinned_key, client_identity.as_ref(), require_peer_auth,
pinned_key, client_identity.as_ref(), grant_blob.as_deref(),
require_peer_auth,
).await;
if failed > 0 {
eprintln!("{failed} of {} transfer(s) failed.", items.len());
Expand Down Expand Up @@ -642,7 +668,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
// unauthenticated rather than half-authenticated. A
// daemon running --require-peer-auth will refuse it.
remote_addr, &items, cc_profile, AckMode::Bitmap, streams, "auto",
encrypt, compress_profile, false, None, false, None, None, false,
encrypt, compress_profile, false, None, false, None, None, None, false,
).await;
}

Expand Down Expand Up @@ -843,6 +869,7 @@ async fn run_ahp_sends(
header_protect: bool,
pinned_key: Option<[u8; 32]>,
client_identity: Option<&ahp_crypto::signatures::SigningIdentity>,
grant: Option<&[u8]>,
require_peer_auth: bool,
) -> usize {
let multi = items.len() > 1;
Expand All @@ -857,7 +884,7 @@ async fn run_ahp_sends(
match net_sender::send_file(
remote_addr, src, dst, cc_profile, ack, streams, pacing, encrypt,
compress_profile, resume, adaptive_policy.as_deref(), header_protect, pinned_key,
client_identity, require_peer_auth,
client_identity, grant, require_peer_auth,
).await {
Ok(stats) => {
sent_bytes += stats.bytes_sent;
Expand Down
16 changes: 16 additions & 0 deletions crates/ahp-cli/src/net_sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1929,6 +1929,9 @@ pub async fn send_file(
// `None` sends an unauthenticated HELLO — what every client did before
// this existed.
client_identity: Option<&ahp_crypto::signatures::SigningIdentity>,
// An opaque signed permission, presented alongside the identity. The
// client does not read it: it was issued for the daemon to check.
grant: Option<&[u8]>,
// Abort unless the daemon says it checked us. Without it, a daemon too
// old to understand the appended material completes the transfer
// happily and the client cannot tell it was never authenticated.
Expand Down Expand Up @@ -2024,6 +2027,7 @@ pub async fn send_file(
&kp.public,
&local_nonce,
offer.as_ref().map(|(pk, sig)| (pk, sig)),
grant,
)
} else {
vec![0x00] // flags: plaintext
Expand Down Expand Up @@ -2535,6 +2539,12 @@ a time; retry when it is free",
match recv_ctrl(&socket, &mut recv_buf, Duration::from_secs(2)).await {
Ok(pkt) => match pkt.header.packet_type {
PacketType::AckBitmap => { manifest_acked = true; break; }
// The daemon refused after reading the manifest — the
// destination is outside what it will accept from this
// sender. Final, like the handshake refusal: retrying sends
// the same manifest to the same answer and then reports a
// timeout, which names the wrong problem.
PacketType::Error => return Err(DEST_REFUSED.into()),
PacketType::ResumeAck => {
if pkt.payload.len() > 1 {
let prefix = pkt.payload[0];
Expand Down Expand Up @@ -4368,6 +4378,11 @@ async fn recv_hello_ack_or_refusal(
}
}

/// The daemon accepted this sender but not this destination.
const DEST_REFUSED: &str = "the daemon refused the destination path: this sender is not \
permitted to write there. If it runs --require-grant, the grant's path prefix does not \
cover the destination; its log says what was asked for and what was permitted.";

/// Marker for a refusal, so the retry loop can tell it from a timeout.
/// Compared by identity of the message, which is why it is a constant.
const PEER_REFUSED: &str = "the daemon refused this transfer before it began: it did not \
Expand Down Expand Up @@ -5391,6 +5406,7 @@ mod tests {
false,
None,
None,
None,
false,
)
.await;
Expand Down
Loading
Loading