Skip to content

Commit

Permalink
Fix port mirror rejection in intproxy (#2998)
Browse files Browse the repository at this point in the history
* Fixed handling rejection in intproxy

* Changelog

* fmt
  • Loading branch information
Razz4780 authored Jan 2, 2025
1 parent 9917374 commit 26ab808
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
1 change: 1 addition & 0 deletions changelog.d/+mirrord-policy-rejection.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed a bug where port mirroring block (due to active mirrord policies) would terminate the mirrord session.
26 changes: 17 additions & 9 deletions mirrord/intproxy/src/proxies/incoming/subscriptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ impl SubscriptionsManager {

Ok(subscription.confirm())
}

Err(ResponseError::PortAlreadyStolen(port)) => {
let Some(subscription) = self.subscriptions.remove(&port) else {
return Ok(vec![]);
Expand All @@ -255,23 +256,30 @@ impl SubscriptionsManager {
}
}
}

Err(
ref response_err @ ResponseError::Forbidden {
blocked_action: BlockedAction::Steal(ref steal_type),
..
ref response_error @ ResponseError::Forbidden {
ref blocked_action, ..
},
) => {
tracing::warn!("Port subscribe blocked by policy: {response_err}");
let Some(subscription) = self.subscriptions.remove(&steal_type.get_port()) else {
tracing::warn!(%response_error, "Port subscribe blocked by policy");

let port = match blocked_action {
BlockedAction::Steal(steal_type) => steal_type.get_port(),
BlockedAction::Mirror(port) => *port,
};
let Some(subscription) = self.subscriptions.remove(&port) else {
return Ok(vec![]);
};

subscription
.reject(response_err.clone())
.map_err(|sub|{
tracing::error!("Subscription {sub:?} was confirmed before, then requested again and blocked by a policy.");
IncomingProxyError::SubscriptionFailed(response_err.clone())
.reject(response_error.clone())
.map_err(|subscription|{
tracing::error!(?subscription, "Subscription was confirmed before, then requested again and blocked by a policy.");
IncomingProxyError::SubscriptionFailed(response_error.clone())
})
}

Err(err) => Err(IncomingProxyError::SubscriptionFailed(err)),
}
}
Expand Down

0 comments on commit 26ab808

Please sign in to comment.