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
6 changes: 5 additions & 1 deletion src/bin/varlink-httpd/auth_ssh.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: LGPL-2.1-or-later

use anyhow::{Context, bail};
use log::{info, warn};
use log::{debug, info, warn};
use ssh_key::{HashAlg, PublicKey};
use std::collections::HashMap;
use std::sync::Mutex;
Expand Down Expand Up @@ -122,6 +122,10 @@ impl SshKeyAuthenticator {
continue;
}
let fp = key.fingerprint(HashAlg::Sha256).to_string();
debug!(
" authorized key: {fp} ({comment})",
comment = key.comment()
);
keys.insert(fp, key);
}

Expand Down
17 changes: 15 additions & 2 deletions src/bin/varlink-httpd/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,13 +476,15 @@ async fn auth_middleware(
next: Next,
) -> Response {
if state.authenticators.is_empty() {
debug!("auth: no authenticators configured, allowing request");
return next.run(request).await;
}

let auth_header = match request.headers().get("authorization") {
Some(val) => match val.to_str() {
Ok(s) => s.to_string(),
Err(_) => {
debug!("auth: invalid Authorization header encoding");
return (
StatusCode::BAD_REQUEST,
axum::Json(json!({"error": "invalid Authorization header encoding"})),
Expand All @@ -491,6 +493,10 @@ async fn auth_middleware(
}
},
None => {
debug!(
"auth: no Authorization header in request to {}",
request.uri()
);
return (
StatusCode::UNAUTHORIZED,
axum::Json(json!({"error": "missing Authorization header"})),
Expand All @@ -513,6 +519,8 @@ async fn auth_middleware(
.map_or(request.uri().path(), axum::http::uri::PathAndQuery::as_str)
.to_string();

debug!("auth: checking {method} {path} (nonce={nonce:?}, tls_cb={tls_channel_binding:?})");

let mut errors = Vec::new();
for authenticator in state.authenticators.iter() {
match authenticator.check_request(
Expand All @@ -522,14 +530,19 @@ async fn auth_middleware(
nonce.as_deref(),
tls_channel_binding.as_deref(),
) {
Ok(()) => return next.run(request).await,
Ok(()) => {
debug!("auth: accepted {method} {path}");
return next.run(request).await;
}
Err(e) => errors.push(e.to_string()),
}
}

let joined = errors.join("; ");
debug!("auth: rejected {method} {path}: {joined}");
(
StatusCode::UNAUTHORIZED,
axum::Json(json!({"error": errors.join("; ")})),
axum::Json(json!({"error": joined})),
)
.into_response()
}
Expand Down
Loading