Skip to content

Commit 730c626

Browse files
authored
refactor(identity): move equality check into app (#4430)
* refactor(app/identity): TlsIdAndServerNameNotMatching is Clone Signed-off-by: katelyn martin <kate@buoyant.io> * refactor(app/identity): EnvError: From<TlsIdAndServerNameNotMatching> Signed-off-by: katelyn martin <kate@buoyant.io> * refactor(identity): move equality check into app this addresses a long-standing todo comment in the linkerd-identity library. this moves a bit of validation logic that confirms, when running in the regular "Linkerd" mode, that the `id` field contains a DNS name, and that `server_name` matches it. Signed-off-by: katelyn martin <kate@buoyant.io> * refactor(identity): EnvError::TlsIdAndServerNameNotMatching Signed-off-by: katelyn martin <kate@buoyant.io> * nit(app): address clippy `useless_conversion` lint Signed-off-by: katelyn martin <kate@buoyant.io> --------- Signed-off-by: katelyn martin <kate@buoyant.io>
1 parent 64101a2 commit 730c626

2 files changed

Lines changed: 10 additions & 12 deletions

File tree

linkerd/app/src/env.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ pub enum EnvError {
3939
NoDestinationAddress,
4040
#[error("no policy service configured")]
4141
NoPolicyAddress,
42+
#[error("linkerd identity requires a TLS Id and server name to be the same")]
43+
TlsIdAndServerNameNotMatching,
4244
}
4345

4446
#[derive(Debug, Error, Eq, PartialEq)]
@@ -906,6 +908,13 @@ pub fn parse_config<S: Strings>(strings: &S) -> Result<super::Config, EnvError>
906908
}
907909
},
908910
None => {
911+
match (&tls.id, &tls.server_name) {
912+
(linkerd_app_core::identity::Id::Dns(id), sni) if id == sni => {}
913+
(_id, _sni) => {
914+
return Err(EnvError::TlsIdAndServerNameNotMatching);
915+
}
916+
};
917+
909918
let (addr, certify) = parse_linkerd_identity_config(strings)?;
910919

911920
// If the address doesn't have a server identity, then we're on localhost.

linkerd/app/src/identity.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ use std::{future::Future, pin::Pin, time::SystemTime};
1414
use tokio::sync::watch;
1515
use tracing::Instrument;
1616

17-
#[derive(Debug, thiserror::Error)]
18-
#[error("linkerd identity requires a TLS Id and server name to be the same")]
19-
pub struct TlsIdAndServerNameNotMatching(());
20-
2117
#[derive(Clone, Debug)]
2218
#[allow(clippy::large_enum_variant)]
2319
pub enum Config {
@@ -83,14 +79,7 @@ impl Config {
8379
certify,
8480
tls,
8581
} => {
86-
// TODO: move this validation into env.rs
87-
let name = match (&tls.id, &tls.server_name) {
88-
(Id::Dns(id), sni) if id == sni => id.clone(),
89-
(_id, _sni) => {
90-
return Err(TlsIdAndServerNameNotMatching(()).into());
91-
}
92-
};
93-
82+
let name = tls.server_name.clone();
9483
let certify = Certify::from(certify);
9584
let (store, receiver, ready) = watch(tls, metrics.cert)?;
9685

0 commit comments

Comments
 (0)