-
Notifications
You must be signed in to change notification settings - Fork 271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
linkerd_identity: split linkerd_identity::Id
into DNS and URI variants
#2538
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ca41400
split tls id into DNS and URI variants
zaharidichev d2242f6
feedback
zaharidichev 3e31ee8
make authz fns private again
zaharidichev 0359465
feedback
zaharidichev a187e19
allow two versions of idna
zaharidichev 2defa19
feedback
zaharidichev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ pub use self::{ | |
|
||
pub use linkerd_app_core::metrics::ServerLabel; | ||
use linkerd_app_core::{ | ||
identity as id, | ||
metrics::{RouteAuthzLabels, ServerAuthzLabels}, | ||
tls, | ||
transport::{ClientAddr, OrigDstAddr, Remote}, | ||
|
@@ -150,15 +151,7 @@ impl AllowPolicy { | |
} | ||
} | ||
|
||
fn is_authorized( | ||
authz: &Authorization, | ||
client_addr: Remote<ClientAddr>, | ||
tls: &tls::ConditionalServerTls, | ||
) -> bool { | ||
if !authz.networks.iter().any(|n| n.contains(&client_addr.ip())) { | ||
return false; | ||
} | ||
|
||
fn is_tls_authorized(tls: &tls::ConditionalServerTls, authz: &Authorization) -> bool { | ||
match authz.authentication { | ||
Authentication::Unauthenticated => true, | ||
|
||
|
@@ -176,15 +169,30 @@ fn is_authorized( | |
tls::ConditionalServerTls::Some(tls::ServerTls::Established { | ||
client_id: Some(tls::server::ClientId(ref id)), | ||
.. | ||
}) => { | ||
identities.contains(&*id.to_str()) | ||
|| suffixes.iter().any(|s| s.contains(&id.to_str())) | ||
} | ||
}) => match id { | ||
id::Id::Uri(_) => identities.contains(&*id.to_str()), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does that make sense for now ? |
||
id::Id::Dns(_) => { | ||
identities.contains(&*id.to_str()) | ||
|| suffixes.iter().any(|s| s.contains(&id.to_str())) | ||
} | ||
}, | ||
_ => false, | ||
}, | ||
} | ||
} | ||
|
||
fn is_authorized( | ||
authz: &Authorization, | ||
client_addr: Remote<ClientAddr>, | ||
tls: &tls::ConditionalServerTls, | ||
) -> bool { | ||
if !authz.networks.iter().any(|n| n.contains(&client_addr.ip())) { | ||
return false; | ||
} | ||
|
||
is_tls_authorized(tls, authz) | ||
} | ||
|
||
// === impl Permit === | ||
|
||
impl ServerPermit { | ||
|
@@ -199,3 +207,119 @@ impl ServerPermit { | |
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::is_tls_authorized; | ||
use super::Meta; | ||
use super::Suffix; | ||
use super::{Authentication, Authorization}; | ||
use linkerd_app_core::tls; | ||
use std::collections::BTreeSet; | ||
use std::str::FromStr; | ||
use std::sync::Arc; | ||
|
||
fn authorization(identities: BTreeSet<String>, suffixes: Vec<Suffix>) -> Authorization { | ||
Authorization { | ||
networks: vec![], | ||
meta: Arc::new(Meta::Default { | ||
name: "name".into(), | ||
}), | ||
authentication: Authentication::TlsAuthenticated { | ||
identities, | ||
suffixes, | ||
}, | ||
} | ||
} | ||
|
||
fn server_tls(identity: &str) -> tls::ConditionalServerTls { | ||
let client_id = tls::ClientId::from_str(identity).expect("should parse id"); | ||
tls::ConditionalServerTls::Some(tls::ServerTls::Established { | ||
client_id: Some(client_id), | ||
negotiated_protocol: None, | ||
}) | ||
} | ||
|
||
#[test] | ||
fn is_authorized_for_matching_spiffe_ids() { | ||
let tls = server_tls("spiffe://some-root/some-workload"); | ||
let authz = authorization( | ||
BTreeSet::from(["spiffe://some-root/some-workload".into()]), | ||
vec![], | ||
); | ||
assert!(is_tls_authorized(&tls, &authz)) | ||
} | ||
|
||
#[test] | ||
fn is_not_authorized_for_non_matching_spiffe_ids() { | ||
let tls = server_tls("spiffe://some-root/some-workload-1"); | ||
let authz = authorization( | ||
BTreeSet::from(["spiffe://some-root/some-workload-2".into()]), | ||
vec![], | ||
); | ||
assert!(!is_tls_authorized(&tls, &authz)) | ||
} | ||
|
||
#[test] | ||
fn is_authorized_for_matching_dns_ids() { | ||
let tls = server_tls("some.id.local"); | ||
let authz = authorization(BTreeSet::from(["some.id.local".into()]), vec![]); | ||
assert!(is_tls_authorized(&tls, &authz)) | ||
} | ||
|
||
#[test] | ||
fn is_not_authorized_for_non_matching_dns_ids() { | ||
let tls = server_tls("some.id.local.one"); | ||
let authz = authorization(BTreeSet::from(["some.id.local.two".into()]), vec![]); | ||
assert!(!is_tls_authorized(&tls, &authz)) | ||
} | ||
|
||
#[test] | ||
fn is_authorized_for_matching_dns_suffixes_ids() { | ||
let tls = server_tls("some.id.local"); | ||
let authz = authorization(BTreeSet::new(), vec![Suffix::new("id.local")]); | ||
assert!(is_tls_authorized(&tls, &authz)) | ||
} | ||
|
||
#[test] | ||
fn is_not_authorized_for_non_matching_suffixes_ids() { | ||
let tls = server_tls("some.id.local"); | ||
let authz = authorization(BTreeSet::new(), vec![Suffix::new("another-id.local")]); | ||
assert!(!is_tls_authorized(&tls, &authz)) | ||
} | ||
|
||
#[test] | ||
fn is_not_authorized_for_suffixes_and_spiffe_id() { | ||
let tls = server_tls("spiffe://some-root/some-workload-1"); | ||
let authz = authorization(BTreeSet::new(), vec![Suffix::new("some-workload-1")]); | ||
assert!(!is_tls_authorized(&tls, &authz)) | ||
} | ||
|
||
#[test] | ||
fn is_authorized_for_one_matching_spiffe_id() { | ||
let tls = server_tls("spiffe://some-root/some-workload-1"); | ||
let authz = authorization( | ||
BTreeSet::from([ | ||
"spiffe://some-root/some-workload-1".into(), | ||
"some.workload.one".into(), | ||
"some.workload.two".into(), | ||
]), | ||
vec![], | ||
); | ||
assert!(is_tls_authorized(&tls, &authz)) | ||
} | ||
|
||
#[test] | ||
fn is_authorized_for_one_matching_dns_id() { | ||
let tls = server_tls("some.workload.one"); | ||
let authz = authorization( | ||
BTreeSet::from([ | ||
"spiffe://some-root/some-workload-1".into(), | ||
"some.workload.one".into(), | ||
"some.workload.two".into(), | ||
]), | ||
vec![], | ||
); | ||
assert!(is_tls_authorized(&tls, &authz)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked into this and (1) it appears that trust-dns has rebranded as hickory-dns, so we're going to have to be aware of that when we upgrade trust-dns; (2) and the latest version is on idna v0.4.
Normally, we'd follow up this PR with an upstream PR to update hickory-dns to idna 0.5 so that we can be sure to resolve this when we take the next hickory udpate.
These exceptions are fine temporarily, but each skip here means we're double-building dependencies. We try to keep this overhead manageable over time.