Skip to content

Commit 49227fe

Browse files
authored
Require identity configuration (#1305)
The proxy currently supports a mode where identity is disabled. This proliferates complexity that isn't really needed: there doesn't appear to be a real use case where disabling identity is necessary. And, if it is really necessary, we should reintroduce it after decoupling TLS and identity. This change causes the proxy to error during startup if identity is disabled by configuration. Furthermore, the `linkerd-proxy-identity` crate now has a `test-util` feature that makes it possible to build a `LocalCrtKey` identity from credentials provided by the `linkerd-identity/test-util` feature. A default set of credentials are used in inbound and outbound tests.
1 parent 3bb7ec4 commit 49227fe

File tree

52 files changed

+344
-438
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+344
-438
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,7 @@ dependencies = [
737737
"linkerd-app-core",
738738
"linkerd-app-test",
739739
"linkerd-io",
740+
"linkerd-proxy-identity",
740741
"linkerd-server-policy",
741742
"linkerd-tonic-watch",
742743
"linkerd-tracing",
@@ -792,6 +793,7 @@ dependencies = [
792793
"linkerd-http-retry",
793794
"linkerd-identity",
794795
"linkerd-io",
796+
"linkerd-proxy-identity",
795797
"linkerd-tracing",
796798
"parking_lot",
797799
"pin-project",

linkerd/app/admin/src/stack.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ struct Permitted {
5858

5959
#[derive(Clone)]
6060
struct TlsParams {
61-
identity: Option<LocalCrtKey>,
61+
identity: LocalCrtKey,
6262
}
6363

6464
const DETECT_TIMEOUT: Duration = Duration::from_secs(1);
@@ -74,7 +74,7 @@ impl Config {
7474
self,
7575
bind: B,
7676
policy: impl inbound::policy::CheckPolicy,
77-
identity: Option<LocalCrtKey>,
77+
identity: LocalCrtKey,
7878
report: R,
7979
metrics: inbound::Metrics,
8080
trace: trace::Handle,
@@ -153,7 +153,7 @@ impl Config {
153153
}
154154
})
155155
.push(svc::ArcNewService::layer())
156-
.push(tls::NewDetectTls::layer(TlsParams {
156+
.push(tls::NewDetectTls::<LocalCrtKey, _, _>::layer(TlsParams {
157157
identity,
158158
}))
159159
.into_inner();
@@ -240,9 +240,9 @@ impl<T> ExtractParam<tls::server::Timeout, T> for TlsParams {
240240
}
241241
}
242242

243-
impl<T> ExtractParam<Option<LocalCrtKey>, T> for TlsParams {
243+
impl<T> ExtractParam<LocalCrtKey, T> for TlsParams {
244244
#[inline]
245-
fn extract_param(&self, _: &T) -> Option<LocalCrtKey> {
245+
fn extract_param(&self, _: &T) -> LocalCrtKey {
246246
self.identity.clone()
247247
}
248248
}

linkerd/app/core/src/control.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl Config {
4343
self,
4444
dns: dns::Resolver,
4545
metrics: metrics::ControlHttp,
46-
identity: Option<L>,
46+
identity: L,
4747
) -> svc::ArcNewService<
4848
(),
4949
impl svc::Service<

linkerd/app/core/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const DEFAULT_PORT: u16 = 80;
5656

5757
#[derive(Clone, Debug)]
5858
pub struct ProxyRuntime {
59-
pub identity: Option<proxy::identity::LocalCrtKey>,
59+
pub identity: proxy::identity::LocalCrtKey,
6060
pub metrics: metrics::Proxy,
6161
pub tap: proxy::tap::Registry,
6262
pub span_sink: http_tracing::OpenCensusSink,

linkerd/app/gateway/src/gateway.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,11 @@ use tracing::{debug, warn};
1818
#[derive(Clone, Debug)]
1919
pub(crate) struct NewGateway<O> {
2020
outbound: O,
21-
local_id: Option<tls::LocalId>,
21+
local_id: tls::LocalId,
2222
}
2323

2424
#[derive(Clone, Debug)]
2525
pub(crate) enum Gateway<O> {
26-
NoIdentity,
2726
BadDomain(dns::Name),
2827
Outbound {
2928
outbound: O,
@@ -37,11 +36,11 @@ pub(crate) type Target = (Option<profiles::Receiver>, HttpTarget);
3736
// === impl NewGateway ===
3837

3938
impl<O> NewGateway<O> {
40-
pub fn new(outbound: O, local_id: Option<tls::LocalId>) -> Self {
39+
pub fn new(outbound: O, local_id: tls::LocalId) -> Self {
4140
Self { outbound, local_id }
4241
}
4342

44-
pub fn layer(local_id: Option<tls::LocalId>) -> impl layer::Layer<O, Service = Self> + Clone {
43+
pub fn layer(local_id: tls::LocalId) -> impl layer::Layer<O, Service = Self> + Clone {
4544
layer::mk(move |outbound| Self::new(outbound, local_id.clone()))
4645
}
4746
}
@@ -56,10 +55,7 @@ where
5655
type Service = Gateway<O::Service>;
5756

5857
fn new_service(&self, (profile, http): Target) -> Self::Service {
59-
let local_id = match self.local_id.clone() {
60-
Some(id) => id,
61-
None => return Gateway::NoIdentity,
62-
};
58+
let local_id = self.local_id.clone();
6359
let profile = match profile {
6460
Some(profile) => profile,
6561
None => return Gateway::BadDomain(http.target.name().clone()),
@@ -198,7 +194,6 @@ where
198194
tracing::debug!("Passing request to outbound");
199195
Box::pin(outbound.call(request).map_err(Into::into))
200196
}
201-
Self::NoIdentity => Box::pin(future::err(GatewayIdentityRequired.into())),
202197
Self::BadDomain(..) => Box::pin(future::err(GatewayDomainInvalid.into())),
203198
}
204199
}

linkerd/app/gateway/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ where
8989
dispatch_timeout,
9090
..
9191
} = inbound.config().proxy.clone();
92-
let local_id = inbound.identity().map(|l| l.id().clone());
92+
let local_id = inbound.identity().id().clone();
9393

9494
// For each gatewayed connection that is *not* HTTP, use the target from the
9595
// transport header to lookup a service profile. If the profile includes a

linkerd/app/gateway/src/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::*;
22
use linkerd_app_core::{
3-
dns, identity as id, profiles, proxy::http, svc::NewService, tls, Error, NameAddr, NameMatch,
3+
dns, profiles, proxy::http, svc::NewService, tls, Error, NameAddr, NameMatch,
44
};
55
use linkerd_app_inbound::{GatewayDomainInvalid, GatewayIdentityRequired, GatewayLoop};
66
use linkerd_app_test as support;
@@ -109,7 +109,7 @@ impl Test {
109109
move |_: svc::Either<outbound::http::Logical, outbound::http::Endpoint>| {
110110
outbound.clone()
111111
},
112-
Some(tls::LocalId(id::Name::from_str("gateway.id.test").unwrap())),
112+
tls::LocalId("gateway.id.test".parse().unwrap()),
113113
);
114114

115115
let t = HttpTarget {

linkerd/app/inbound/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ libfuzzer-sys = { version = "0.4.2", features = ["arbitrary-derive"] }
3434
hyper = { version = "0.14.13", features = ["http1", "http2"] }
3535
linkerd-app-test = { path = "../test" }
3636
linkerd-io = { path = "../../io", features = ["tokio-test"] }
37+
linkerd-proxy-identity = { path = "../../proxy/identity", features = ["test-util"] }
38+
linkerd-tracing = { path = "../../tracing", features = ["ansi"] }
3739
tokio = { version = "1", features = ["full", "macros"] }
3840
tokio-test = "0.4"
39-
linkerd-tracing = { path = "../../tracing", features = ["ansi"] }

linkerd/app/inbound/src/detect.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ struct ConfigureHttpDetect;
5050
#[derive(Clone)]
5151
struct TlsParams {
5252
timeout: tls::server::Timeout,
53-
identity: Option<LocalCrtKey>,
53+
identity: LocalCrtKey,
5454
}
5555

5656
// === impl Inbound ===
@@ -135,7 +135,7 @@ impl<N> Inbound<N> {
135135
.push_on_service(svc::MapTargetLayer::new(io::BoxedIo::new))
136136
.into_inner(),
137137
)
138-
.push(tls::NewDetectTls::layer(TlsParams {
138+
.push(tls::NewDetectTls::<LocalCrtKey, _, _>::layer(TlsParams {
139139
timeout: tls::server::Timeout(detect_timeout),
140140
identity: rt.identity.clone(),
141141
}))
@@ -425,9 +425,9 @@ impl<T> svc::ExtractParam<tls::server::Timeout, T> for TlsParams {
425425
}
426426
}
427427

428-
impl<T> svc::ExtractParam<Option<LocalCrtKey>, T> for TlsParams {
428+
impl<T> svc::ExtractParam<LocalCrtKey, T> for TlsParams {
429429
#[inline]
430-
fn extract_param(&self, _: &T) -> Option<LocalCrtKey> {
430+
fn extract_param(&self, _: &T) -> LocalCrtKey {
431431
self.identity.clone()
432432
}
433433
}

linkerd/app/inbound/src/direct.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub type GatewayIo<I> = io::EitherIo<FwdIo<I>, SensorIo<tls::server::Io<I>>>;
5858
#[derive(Clone)]
5959
struct TlsParams {
6060
timeout: tls::server::Timeout,
61-
identity: Option<WithTransportHeaderAlpn>,
61+
identity: WithTransportHeaderAlpn,
6262
}
6363

6464
impl<N> Inbound<N> {
@@ -186,9 +186,9 @@ impl<N> Inbound<N> {
186186
// connection if it doesn't include an mTLS identity.
187187
.push_request_filter(ClientInfo::try_from)
188188
.push(svc::ArcNewService::layer())
189-
.push(tls::NewDetectTls::layer(TlsParams {
189+
.push(tls::NewDetectTls::<WithTransportHeaderAlpn, _, _>::layer(TlsParams {
190190
timeout: tls::server::Timeout(detect_timeout),
191-
identity: rt.identity.clone().map(WithTransportHeaderAlpn),
191+
identity: WithTransportHeaderAlpn(rt.identity.clone()),
192192
}))
193193
.check_new_service::<T, I>()
194194
.push_on_service(svc::BoxService::layer())
@@ -334,9 +334,9 @@ impl<T> ExtractParam<tls::server::Timeout, T> for TlsParams {
334334
}
335335
}
336336

337-
impl<T> ExtractParam<Option<WithTransportHeaderAlpn>, T> for TlsParams {
337+
impl<T> ExtractParam<WithTransportHeaderAlpn, T> for TlsParams {
338338
#[inline]
339-
fn extract_param(&self, _: &T) -> Option<WithTransportHeaderAlpn> {
339+
fn extract_param(&self, _: &T) -> WithTransportHeaderAlpn {
340340
self.identity.clone()
341341
}
342342
}

0 commit comments

Comments
 (0)