Skip to content

Commit 5ffc10b

Browse files
committed
Introduce meshtls facade to hide rustls crate
In #1351, we add an alternate identity/mtls implementation that uses `boring`. To setup for that, this change introduces a new `meshtls` crate that serves as a facade for application crates to depend on, independently of the actual crypto implementation. This change does not change any runtime logic and sets up for #1351 to enable an alternate TLS implementation as a build-time configuration.
1 parent 6e51c64 commit 5ffc10b

File tree

27 files changed

+652
-69
lines changed

27 files changed

+652
-69
lines changed

Cargo.lock

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -674,8 +674,9 @@ dependencies = [
674674
"linkerd-http-classify",
675675
"linkerd-http-metrics",
676676
"linkerd-http-retry",
677-
"linkerd-identity-default",
677+
"linkerd-identity",
678678
"linkerd-io",
679+
"linkerd-meshtls",
679680
"linkerd-metrics",
680681
"linkerd-opencensus",
681682
"linkerd-proxy-api-resolve",
@@ -743,8 +744,8 @@ dependencies = [
743744
"libfuzzer-sys",
744745
"linkerd-app-core",
745746
"linkerd-app-test",
746-
"linkerd-identity-default",
747747
"linkerd-io",
748+
"linkerd-meshtls-rustls",
748749
"linkerd-server-policy",
749750
"linkerd-tonic-watch",
750751
"linkerd-tracing",
@@ -799,8 +800,8 @@ dependencies = [
799800
"linkerd-app-test",
800801
"linkerd-http-retry",
801802
"linkerd-identity",
802-
"linkerd-identity-default",
803803
"linkerd-io",
804+
"linkerd-meshtls-rustls",
804805
"linkerd-tracing",
805806
"parking_lot",
806807
"pin-project",
@@ -1000,7 +1001,35 @@ dependencies = [
10001001
]
10011002

10021003
[[package]]
1003-
name = "linkerd-identity-default"
1004+
name = "linkerd-io"
1005+
version = "0.1.0"
1006+
dependencies = [
1007+
"async-trait",
1008+
"bytes",
1009+
"futures",
1010+
"linkerd-errno",
1011+
"pin-project",
1012+
"tokio",
1013+
"tokio-test",
1014+
"tokio-util",
1015+
]
1016+
1017+
[[package]]
1018+
name = "linkerd-meshtls"
1019+
version = "0.1.0"
1020+
dependencies = [
1021+
"futures",
1022+
"linkerd-error",
1023+
"linkerd-identity",
1024+
"linkerd-io",
1025+
"linkerd-meshtls-rustls",
1026+
"linkerd-stack",
1027+
"linkerd-tls",
1028+
"pin-project",
1029+
]
1030+
1031+
[[package]]
1032+
name = "linkerd-meshtls-rustls"
10041033
version = "0.1.0"
10051034
dependencies = [
10061035
"futures",
@@ -1022,20 +1051,6 @@ dependencies = [
10221051
"webpki",
10231052
]
10241053

1025-
[[package]]
1026-
name = "linkerd-io"
1027-
version = "0.1.0"
1028-
dependencies = [
1029-
"async-trait",
1030-
"bytes",
1031-
"futures",
1032-
"linkerd-errno",
1033-
"pin-project",
1034-
"tokio",
1035-
"tokio-test",
1036-
"tokio-util",
1037-
]
1038-
10391054
[[package]]
10401055
name = "linkerd-metrics"
10411056
version = "0.1.0"
@@ -1202,8 +1217,8 @@ dependencies = [
12021217
"ipnet",
12031218
"linkerd-conditional",
12041219
"linkerd-error",
1205-
"linkerd-identity-default",
12061220
"linkerd-io",
1221+
"linkerd-meshtls",
12071222
"linkerd-proxy-http",
12081223
"linkerd-stack",
12091224
"linkerd-tls",

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ members = [
2929
"linkerd/http-metrics",
3030
"linkerd/http-retry",
3131
"linkerd/identity",
32-
"linkerd/identity/default",
3332
"linkerd/io",
33+
"linkerd/meshtls",
34+
"linkerd/meshtls/rustls",
3435
"linkerd/metrics",
3536
"linkerd/opencensus",
3637
"linkerd/proxy/api-resolve",

linkerd/app/core/Cargo.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ This crate conglomerates proxy configuration, runtime administration, etc,
1212
independently of the inbound and outbound proxy logic.
1313
"""
1414

15+
[features]
16+
default = ["meshtls-rustls"]
17+
meshtls-rustls = ["linkerd-meshtls/rustls"]
18+
1519
[dependencies]
1620
bytes = "1"
1721
drain = { version = "0.1.0", features = ["retain"] }
@@ -33,8 +37,9 @@ linkerd-exp-backoff = { path = "../../exp-backoff" }
3337
linkerd-http-classify = { path = "../../http-classify" }
3438
linkerd-http-metrics = { path = "../../http-metrics" }
3539
linkerd-http-retry = { path = "../../http-retry" }
36-
linkerd-identity-default = { path = "../../identity/default" }
40+
linkerd-identity = { path = "../../identity" }
3741
linkerd-io = { path = "../../io" }
42+
linkerd-meshtls = { path = "../../meshtls", default-features = false }
3843
linkerd-metrics = { path = "../../metrics", features = ["linkerd-stack"] }
3944
linkerd-opencensus = { path = "../../opencensus" }
4045
linkerd-proxy-core = { path = "../../proxy/core" }

linkerd/app/core/src/lib.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,8 @@ pub use linkerd_dns;
2020
pub use linkerd_error::{is_error, Error, Infallible, Recover, Result};
2121
pub use linkerd_exp_backoff as exp_backoff;
2222
pub use linkerd_http_metrics as http_metrics;
23-
pub use linkerd_identity_default as identity;
2423
pub use linkerd_io as io;
2524
pub use linkerd_opencensus as opencensus;
26-
pub use linkerd_proxy_identity_client as identity_client;
2725
pub use linkerd_service_profiles as profiles;
2826
pub use linkerd_stack_metrics as stack_metrics;
2927
pub use linkerd_stack_tracing as stack_tracing;
@@ -51,6 +49,12 @@ pub mod transport;
5149

5250
pub use self::addr_match::{AddrMatch, IpMatch, NameMatch};
5351

52+
pub mod identity {
53+
pub use linkerd_identity::*;
54+
pub use linkerd_meshtls::*;
55+
pub use linkerd_proxy_identity_client as client;
56+
}
57+
5458
pub const CANONICAL_DST_HEADER: &str = "l5d-dst-canonical";
5559

5660
const DEFAULT_PORT: u16 = 80;

linkerd/app/inbound/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ libfuzzer-sys = { version = "0.4.2", features = ["arbitrary-derive"] }
3434
hyper = { version = "0.14.14", features = ["http1", "http2"] }
3535
linkerd-app-test = { path = "../test" }
3636
linkerd-io = { path = "../../io", features = ["tokio-test"] }
37-
linkerd-identity-default = { path = "../../identity/default", features = ["test-util"] }
37+
linkerd-meshtls-rustls = { path = "../../meshtls/rustls", features = ["test-util"] }
3838
linkerd-tracing = { path = "../../tracing", features = ["ansi"] }
3939
tokio = { version = "1", features = ["full", "macros"] }
4040
tokio-test = "0.4"

linkerd/app/inbound/fuzz/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ libfuzzer-sys = { version = "0.4.2", features = ["arbitrary-derive"] }
1717
linkerd-app-core = { path = "../../core" }
1818
linkerd-app-inbound = { path = ".." }
1919
linkerd-app-test = { path = "../../test" }
20-
linkerd-identity-default = { path = "../../../identity/default", features = ["test-util"] }
20+
linkerd-meshtls-rustls = { path = "../../../meshtls/rustls", features = ["test-util"] }
2121
linkerd-tracing = { path = "../../../tracing", features = ["ansi"] }
2222
tokio = { version = "1", features = ["full"] }
2323
tracing = "0.1"

linkerd/app/inbound/src/test_util.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ pub use futures::prelude::*;
33
use linkerd_app_core::{
44
config,
55
dns::Suffix,
6-
drain, exp_backoff, identity, metrics,
6+
drain, exp_backoff,
7+
identity::rustls,
8+
metrics,
79
proxy::{
810
http::{h1, h2},
911
tap,
@@ -73,7 +75,7 @@ pub fn runtime() -> (ProxyRuntime, drain::Signal) {
7375
let (tap, _) = tap::new();
7476
let (metrics, _) = metrics::Metrics::new(std::time::Duration::from_secs(10));
7577
let runtime = ProxyRuntime {
76-
identity: identity::creds::default_for_test().1,
78+
identity: rustls::creds::default_for_test().1.into(),
7779
metrics: metrics.proxy,
7880
tap,
7981
span_sink: None,

linkerd/app/outbound/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pin-project = "1"
3232
hyper = { version = "0.14.14", features = ["http1", "http2"] }
3333
linkerd-app-test = { path = "../test" }
3434
linkerd-io = { path = "../../io", features = ["tokio-test"] }
35-
linkerd-identity-default = { path = "../../identity/default", features = ["test-util"] }
35+
linkerd-meshtls-rustls = { path = "../../meshtls/rustls", features = ["test-util"] }
3636
linkerd-tracing = { path = "../../tracing", features = ["ansi"] }
3737
parking_lot = "0.11"
3838
tokio = { version = "1", features = ["time", "macros"] }

linkerd/app/outbound/src/test_util.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::Config;
22
pub use futures::prelude::*;
33
use linkerd_app_core::{
4-
config, drain, exp_backoff, identity, metrics,
4+
config, drain, exp_backoff, metrics,
55
proxy::{
66
http::{h1, h2},
77
tap,
@@ -53,7 +53,7 @@ pub(crate) fn runtime() -> (ProxyRuntime, drain::Signal) {
5353
let (tap, _) = tap::new();
5454
let (metrics, _) = metrics::Metrics::new(std::time::Duration::from_secs(10));
5555
let runtime = ProxyRuntime {
56-
identity: identity::creds::default_for_test().1,
56+
identity: linkerd_meshtls_rustls::creds::default_for_test().1.into(),
5757
metrics: metrics.proxy,
5858
tap,
5959
span_sink: None,

linkerd/app/src/env.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use crate::core::{
22
addr,
33
config::*,
44
control::{Config as ControlConfig, ControlAddr},
5-
identity_client,
65
proxy::http::{h1, h2},
76
tls,
87
transport::{Keepalive, ListenAddr},
@@ -1102,14 +1101,7 @@ pub fn parse_control_addr<S: Strings>(
11021101

11031102
pub fn parse_identity_config<S: Strings>(
11041103
strings: &S,
1105-
) -> Result<
1106-
(
1107-
ControlAddr,
1108-
identity_client::certify::Config,
1109-
identity::Documents,
1110-
),
1111-
EnvError,
1112-
> {
1104+
) -> Result<(ControlAddr, identity::certify::Config, identity::Documents), EnvError> {
11131105
let control = parse_control_addr(strings, ENV_IDENTITY_SVC_BASE);
11141106
let ta = parse(strings, ENV_IDENTITY_TRUST_ANCHORS, |s| {
11151107
if s.is_empty() {

linkerd/app/src/identity.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1+
pub use linkerd_app_core::identity::{
2+
client::{certify, TokenSource},
3+
InvalidName, LocalId, Name,
4+
};
15
use linkerd_app_core::{
26
control, dns,
37
exp_backoff::{ExponentialBackoff, ExponentialBackoffStream},
4-
identity::{creds, Credentials, DerX509},
5-
identity_client::{Certify, Metrics as IdentityMetrics},
8+
identity::{
9+
client::{Certify, Metrics as IdentityMetrics},
10+
creds, Credentials, DerX509, Mode,
11+
},
612
metrics::ControlHttp as ClientMetrics,
713
Error, Result,
814
};
9-
pub use linkerd_app_core::{
10-
identity::{InvalidName, LocalId, Name},
11-
identity_client::{certify, TokenSource},
12-
};
1315
use std::{future::Future, pin::Pin};
1416
use tokio::sync::watch;
1517
use tracing::Instrument;
@@ -53,7 +55,7 @@ struct NotifyReady {
5355

5456
impl Config {
5557
pub fn build(self, dns: dns::Resolver, client_metrics: ClientMetrics) -> Result<Identity> {
56-
let (store, receiver) = creds::watch(
58+
let (store, receiver) = Mode::default().watch(
5759
(*self.documents.id).clone(),
5860
&self.documents.trust_anchors_pem,
5961
&self.documents.key_pkcs8,

linkerd/meshtls/Cargo.toml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[package]
2+
name = "linkerd-meshtls"
3+
version = "0.1.0"
4+
authors = ["Linkerd Developers <[email protected]>"]
5+
license = "Apache-2.0"
6+
edition = "2018"
7+
publish = false
8+
9+
[features]
10+
default = ["rustls"]
11+
rustls = ["linkerd-meshtls-rustls"]
12+
13+
14+
[dependencies]
15+
futures = { version = "0.3", default-features = false }
16+
linkerd-error = { path = "../error" }
17+
linkerd-identity = { path = "../identity" }
18+
linkerd-io = { path = "../io" }
19+
linkerd-meshtls-rustls = { path = "rustls", optional = true }
20+
linkerd-stack = { path = "../stack" }
21+
linkerd-tls = { path = "../tls" }
22+
pin-project = "1"

linkerd/identity/default/Cargo.toml renamed to linkerd/meshtls/rustls/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "linkerd-identity-default"
2+
name = "linkerd-meshtls-rustls"
33
version = "0.1.0"
44
authors = ["Linkerd Developers <[email protected]>"]
55
license = "Apache-2.0"
@@ -19,7 +19,7 @@ linkerd-tls = { path = "../../tls" }
1919
linkerd-tls-test-util = { path = "../../tls/test-util", optional = true }
2020
ring = { version = "0.16.19", features = ["std"] }
2121
thiserror = "1"
22-
tokio = { version = "1", features = ["macros", "sync"] }
22+
tokio = { version = "1", features = ["macros", "rt", "sync"] }
2323
tokio-rustls = "0.22"
2424
tracing = "0.1"
2525
webpki = "0.21"

linkerd/identity/default/src/lib.rs renamed to linkerd/meshtls/rustls/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,3 @@ pub use self::{
99
client::{ClientIo, Connect, ConnectFuture, NewClient},
1010
server::{Server, ServerIo, TerminateFuture},
1111
};
12-
pub use linkerd_identity::*;

linkerd/identity/default/tests/tls_accept.rs renamed to linkerd/meshtls/rustls/tests/tls_accept.rs

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
use futures::prelude::*;
99
use linkerd_conditional::Conditional;
1010
use linkerd_error::Infallible;
11-
use linkerd_identity_default::{self as identity, Credentials, DerX509, Name};
11+
use linkerd_identity::{Credentials, DerX509, Name};
1212
use linkerd_io::{self as io, AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt};
13+
use linkerd_meshtls_rustls as meshtls;
1314
use linkerd_proxy_transport::{
1415
addrs::*,
1516
listen::{Addrs, Bind, BindTcp},
@@ -28,18 +29,12 @@ use tracing::instrument::Instrument;
2829

2930
type ServerConn<T, I> = (
3031
(tls::ConditionalServerTls, T),
31-
io::EitherIo<identity::ServerIo<tls::server::DetectIo<I>>, tls::server::DetectIo<I>>,
32+
io::EitherIo<meshtls::ServerIo<tls::server::DetectIo<I>>, tls::server::DetectIo<I>>,
3233
);
3334

34-
fn load(
35-
ent: &test_util::Entity,
36-
) -> (
37-
identity::creds::Store,
38-
identity::NewClient,
39-
identity::Server,
40-
) {
35+
fn load(ent: &test_util::Entity) -> (meshtls::creds::Store, meshtls::NewClient, meshtls::Server) {
4136
let roots_pem = std::str::from_utf8(ent.trust_anchors).expect("valid PEM");
42-
let (mut store, rx) = identity::creds::watch(
37+
let (mut store, rx) = meshtls::creds::watch(
4338
ent.name.parse().unwrap(),
4439
roots_pem,
4540
ent.key,
@@ -152,19 +147,19 @@ struct Transported<I, R> {
152147

153148
#[derive(Clone)]
154149
struct ServerParams {
155-
identity: identity::Server,
150+
identity: meshtls::Server,
156151
}
157152

158-
type ClientIo = io::EitherIo<io::ScopedIo<TcpStream>, identity::ClientIo<io::ScopedIo<TcpStream>>>;
153+
type ClientIo = io::EitherIo<io::ScopedIo<TcpStream>, meshtls::ClientIo<io::ScopedIo<TcpStream>>>;
159154

160155
/// Runs a test for a single TCP connection. `client` processes the connection
161156
/// on the client side and `server` processes the connection on the server
162157
/// side.
163158
async fn run_test<C, CF, CR, S, SF, SR>(
164-
client_tls: identity::NewClient,
159+
client_tls: meshtls::NewClient,
165160
client_server_id: Conditional<tls::ServerId, tls::NoClientTls>,
166161
client: C,
167-
server_id: identity::Server,
162+
server_id: meshtls::Server,
168163
server: S,
169164
) -> (
170165
Transported<tls::ConditionalClientTls, CR>,
@@ -187,7 +182,7 @@ where
187182
// Saves the result of every connection.
188183
let (sender, receiver) = mpsc::channel::<Transported<tls::ConditionalServerTls, SR>>();
189184

190-
let detect = tls::NewDetectTls::<identity::Server, _, _>::new(
185+
let detect = tls::NewDetectTls::<meshtls::Server, _, _>::new(
191186
ServerParams {
192187
identity: server_id,
193188
},
@@ -375,8 +370,8 @@ impl<T> ExtractParam<tls::server::Timeout, T> for ServerParams {
375370
}
376371
}
377372

378-
impl<T> ExtractParam<identity::Server, T> for ServerParams {
379-
fn extract_param(&self, _: &T) -> identity::Server {
373+
impl<T> ExtractParam<meshtls::Server, T> for ServerParams {
374+
fn extract_param(&self, _: &T) -> meshtls::Server {
380375
self.identity.clone()
381376
}
382377
}

0 commit comments

Comments
 (0)