Skip to content

Commit 311a38f

Browse files
committed
Revert inbound policy discovery changes
The changes--specifically those in 93b06e6--prevent control plane boot-strapping: the identity controller is unable to serve requests because its proxy can't contact the destination pod for policy because the destination pod doesn't have identity yet. Ultimately, we probably want to change Linkerd's control plane deployment topology to avoid these bootstrapping issues. In the meantime, we'll need to revisit our approach to these changes. * Revert 89ee318 inbound: Introduce a `policy::LookupAddr` type (#2264) * Revert 93b06e6 inbound: Remove default policies (#2204) * Revert c186d88 inbound: connections wait for ServerPolicy discovery (#2186)
1 parent 7948f13 commit 311a38f

32 files changed

+709
-1023
lines changed

Cargo.lock

-4
Original file line numberDiff line numberDiff line change
@@ -891,13 +891,11 @@ dependencies = [
891891
"linkerd2-proxy-api",
892892
"once_cell",
893893
"parking_lot",
894-
"pin-project",
895894
"thiserror",
896895
"tokio",
897896
"tokio-test",
898897
"tonic",
899898
"tower",
900-
"tower-test",
901899
"tracing",
902900
]
903901

@@ -912,7 +910,6 @@ dependencies = [
912910
"http",
913911
"http-body",
914912
"hyper",
915-
"ipnet",
916913
"linkerd-app",
917914
"linkerd-app-admin",
918915
"linkerd-app-core",
@@ -921,7 +918,6 @@ dependencies = [
921918
"linkerd-metrics",
922919
"linkerd-tracing",
923920
"linkerd2-proxy-api",
924-
"maplit",
925921
"parking_lot",
926922
"regex",
927923
"rustls-pemfile",

linkerd/app/admin/src/stack.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,11 @@ struct Rescue;
6969
// === impl Config ===
7070

7171
impl Config {
72-
/// Builds the admin endpoint server.
73-
///
74-
/// This method is asynchronous, as it must discover a `ServerPolicy` for
75-
/// the admin port.
7672
#[allow(clippy::too_many_arguments)]
77-
pub async fn build<B, R>(
73+
pub fn build<B, R>(
7874
self,
7975
bind: B,
80-
policy: &impl inbound::policy::GetPolicy,
76+
policy: impl inbound::policy::GetPolicy,
8177
identity: identity::Server,
8278
report: R,
8379
metrics: inbound::Metrics,
@@ -93,9 +89,7 @@ impl Config {
9389
let (listen_addr, listen) = bind.bind(&self.server)?;
9490

9591
// Get the policy for the admin server.
96-
let policy = policy
97-
.get_policy(inbound::policy::LookupAddr(listen_addr.into()))
98-
.await?;
92+
let policy = policy.get_policy(OrigDstAddr(listen_addr.into()));
9993

10094
let (ready, latch) = crate::server::Readiness::new();
10195
let admin = crate::server::Admin::new(report, ready, shutdown, trace);

linkerd/app/gateway/src/http/tests.rs

+2-10
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use linkerd_app_core::{
44
svc::{NewService, ServiceExt},
55
tls,
66
trace::test::trace_init,
7-
transport::ServerAddr,
87
Error, NameAddr,
98
};
109
use linkerd_app_inbound::GatewayLoop;
@@ -53,7 +52,7 @@ async fn upgraded_request_remains_relative_form() {
5352

5453
impl svc::Param<OrigDstAddr> for Target {
5554
fn param(&self) -> OrigDstAddr {
56-
OrigDstAddr(Self::dst_addr())
55+
OrigDstAddr(([10, 10, 10, 10], 4143).into())
5756
}
5857
}
5958

@@ -133,21 +132,14 @@ async fn upgraded_request_remains_relative_form() {
133132
}]))]),
134133
},
135134
};
136-
let (policy, tx) =
137-
inbound::policy::AllowPolicy::for_test(ServerAddr(Self::dst_addr()), policy);
135+
let (policy, tx) = inbound::policy::AllowPolicy::for_test(self.param(), policy);
138136
tokio::spawn(async move {
139137
tx.closed().await;
140138
});
141139
policy
142140
}
143141
}
144142

145-
impl Target {
146-
fn dst_addr() -> std::net::SocketAddr {
147-
([10, 10, 10, 10], 4143).into()
148-
}
149-
}
150-
151143
let (inner, mut handle) =
152144
mock::pair::<http::Request<http::BoxBody>, http::Response<http::BoxBody>>();
153145
handle.allow(1);

linkerd/app/inbound/Cargo.toml

-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ linkerd-tonic-watch = { path = "../../tonic-watch" }
3131
linkerd2-proxy-api = { version = "0.8", features = ["inbound"] }
3232
once_cell = "1"
3333
parking_lot = "0.12"
34-
pin-project = "1"
3534
thiserror = "1"
3635
tokio = { version = "1", features = ["sync"] }
3736
tonic = { version = "0.8", default-features = false }
@@ -60,4 +59,3 @@ linkerd-meshtls-rustls = { path = "../../meshtls/rustls", features = [
6059
linkerd-tracing = { path = "../../tracing", features = ["ansi"] }
6160
tokio = { version = "1", features = ["full", "macros"] }
6261
tokio-test = "0.4"
63-
tower-test = "0.4"

linkerd/app/inbound/src/accept.rs

+115-24
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::{
2-
policy::{self, AllowPolicy, GetPolicy},
2+
policy::{AllowPolicy, GetPolicy},
33
Inbound,
44
};
55
use linkerd_app_core::{
@@ -10,9 +10,6 @@ use linkerd_app_core::{
1010
use std::fmt::Debug;
1111
use tracing::info_span;
1212

13-
#[cfg(test)]
14-
mod tests;
15-
1613
#[derive(Clone, Debug)]
1714
pub(crate) struct Accept {
1815
client_addr: Remote<ClientAddr>,
@@ -29,7 +26,7 @@ impl<N> Inbound<N> {
2926
pub(crate) fn push_accept<T, I, NSvc, D, DSvc>(
3027
self,
3128
proxy_port: u16,
32-
policies: impl GetPolicy,
29+
policies: impl GetPolicy + Clone + Send + Sync + 'static,
3330
direct: D,
3431
) -> Inbound<svc::ArcNewTcp<T, I>>
3532
where
@@ -49,24 +46,6 @@ impl<N> Inbound<N> {
4946
{
5047
self.map_stack(|cfg, rt, accept| {
5148
accept
52-
.push_on_service(svc::MapErr::layer_boxed())
53-
.push_map_target(|(policy, t): (AllowPolicy, T)| {
54-
tracing::debug!(policy = ?&*policy.borrow(), "Accepted");
55-
Accept {
56-
client_addr: t.param(),
57-
orig_dst_addr: t.param(),
58-
policy,
59-
}
60-
})
61-
.lift_new_with_target()
62-
.push(policy::Discover::layer_via(policies, |t: &T| {
63-
// For non-direct inbound connections, policies are always
64-
// looked up for the original destination address.
65-
let OrigDstAddr(addr) = t.param();
66-
policy::LookupAddr(addr)
67-
}))
68-
.into_new_service()
69-
.check_new_service::<T, I>()
7049
.push_switch(
7150
// Switch to the `direct` stack when a connection's original destination is the
7251
// proxy's inbound port. Otherwise, check that connections are allowed on the
@@ -77,7 +56,13 @@ impl<N> Inbound<N> {
7756
return Ok(svc::Either::B(t));
7857
}
7958

80-
Ok(svc::Either::A(t))
59+
let policy = policies.get_policy(addr);
60+
tracing::debug!(policy = ?&*policy.borrow(), "Accepted");
61+
Ok(svc::Either::A(Accept {
62+
client_addr: t.param(),
63+
orig_dst_addr: addr,
64+
policy,
65+
}))
8166
},
8267
direct,
8368
)
@@ -120,3 +105,109 @@ impl svc::Param<AllowPolicy> for Accept {
120105
self.policy.clone()
121106
}
122107
}
108+
109+
#[cfg(test)]
110+
mod tests {
111+
use super::*;
112+
use crate::{
113+
policy::{DefaultPolicy, Store},
114+
test_util,
115+
};
116+
use futures::future;
117+
use linkerd_app_core::{
118+
svc::{NewService, ServiceExt},
119+
Error,
120+
};
121+
use linkerd_proxy_server_policy::{Authentication, Authorization, Meta, ServerPolicy};
122+
use std::sync::Arc;
123+
124+
#[tokio::test(flavor = "current_thread")]
125+
async fn default_allow() {
126+
let (io, _) = io::duplex(1);
127+
let policies = Store::for_test(
128+
ServerPolicy {
129+
protocol: linkerd_proxy_server_policy::Protocol::Opaque(Arc::new([
130+
Authorization {
131+
authentication: Authentication::Unauthenticated,
132+
networks: vec![Default::default()],
133+
meta: Arc::new(Meta::Resource {
134+
group: "policy.linkerd.io".into(),
135+
kind: "serverauthorization".into(),
136+
name: "testsaz".into(),
137+
}),
138+
},
139+
])),
140+
meta: Arc::new(Meta::Resource {
141+
group: "policy.linkerd.io".into(),
142+
kind: "server".into(),
143+
name: "testsrv".into(),
144+
}),
145+
},
146+
None,
147+
);
148+
inbound()
149+
.with_stack(new_ok())
150+
.push_accept(999, policies, new_panic("direct stack must not be built"))
151+
.into_inner()
152+
.new_service(Target(1000))
153+
.oneshot(io)
154+
.await
155+
.expect("should succeed");
156+
}
157+
158+
/// Default-deny authorizations are checked by an internal stack.
159+
#[tokio::test(flavor = "current_thread")]
160+
async fn default_deny() {
161+
let policies = Store::for_test(DefaultPolicy::Deny, None);
162+
let (io, _) = io::duplex(1);
163+
inbound()
164+
.with_stack(new_ok())
165+
.push_accept(999, policies, new_panic("direct stack must not be built"))
166+
.into_inner()
167+
.new_service(Target(1000))
168+
.oneshot(io)
169+
.await
170+
.expect("should succeed");
171+
}
172+
173+
#[tokio::test(flavor = "current_thread")]
174+
async fn direct() {
175+
let policies = Store::for_test(DefaultPolicy::Deny, None);
176+
let (io, _) = io::duplex(1);
177+
inbound()
178+
.with_stack(new_panic("detect stack must not be built"))
179+
.push_accept(999, policies, new_ok())
180+
.into_inner()
181+
.new_service(Target(999))
182+
.oneshot(io)
183+
.await
184+
.expect("should succeed");
185+
}
186+
187+
fn inbound() -> Inbound<()> {
188+
Inbound::new(test_util::default_config(), test_util::runtime().0)
189+
}
190+
191+
fn new_panic<T>(msg: &'static str) -> svc::ArcNewTcp<T, io::DuplexStream> {
192+
svc::ArcNewService::new(move |_| panic!("{msg}"))
193+
}
194+
195+
fn new_ok<T>() -> svc::ArcNewTcp<T, io::DuplexStream> {
196+
svc::ArcNewService::new(|_| svc::BoxService::new(svc::mk(|_| future::ok::<(), Error>(()))))
197+
}
198+
199+
#[derive(Clone, Debug)]
200+
struct Target(u16);
201+
202+
impl svc::Param<OrigDstAddr> for Target {
203+
fn param(&self) -> OrigDstAddr {
204+
OrigDstAddr(([192, 0, 2, 2], self.0).into())
205+
}
206+
}
207+
208+
impl svc::Param<Remote<ClientAddr>> for Target {
209+
fn param(&self) -> Remote<ClientAddr> {
210+
Remote(ClientAddr(([192, 0, 2, 3], 54321).into()))
211+
}
212+
}
213+
}

0 commit comments

Comments
 (0)