Skip to content

Commit

Permalink
Explicitly check and forbid knocking on the control port
Browse files Browse the repository at this point in the history
The resource configuration is incorrect.
Check for this scenario to avoid accidental modification of the firewall rules
and to give the user an error message.
  • Loading branch information
mbuesch committed Sep 21, 2024
1 parent 5d0d582 commit b15c62a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
12 changes: 11 additions & 1 deletion letmeind/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,23 @@ impl<'a, C: ConnectionOps> Protocol<'a, C> {

// Check if the authenticating user is allowed to access this resource.
match resource {
Resource::Port { .. } => {
Resource::Port { port, users: _ } => {
// Check the mapped user on the resource.
if !resource.contains_user(user_id) {
let _ = self.send_go_away().await;
return Err(err!(
"Resource {resource_id} not allowed for user {user_id}"
));
}
// The control port is never allowed.
let control_port = self.conf.port();
if *port == control_port {
let _ = self.send_go_away().await;
return Err(err!(
"Incorrect configuration: The resource {resource_id} uses the \
letmein control port {control_port}. That is not allowed."
));
}
}
}

Expand Down
8 changes: 8 additions & 0 deletions letmeinfwd/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ impl FirewallConnection {
return Err(err!("The port {port} is not configured in letmeind.conf."));
}

// Don't allow letmein to manage its own control port.
if port == conf.port() {
// Whoops, letmeind should never send us a request for the
// control port. Did some other process write to the unix socket?
self.send_msg(&FirewallMessage::new_nack()).await?;
return Err(err!("The knocked port {port} is the letmein control port."));
}

// Open the firewall.
let ok = {
let mut fw = fw.lock().await;
Expand Down

0 comments on commit b15c62a

Please sign in to comment.