-
Notifications
You must be signed in to change notification settings - Fork 103
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
Fix cleaning up identities #1021
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ mod namespaced { | |
use std::collections::HashMap; | ||
use std::fs; | ||
use std::fs::File; | ||
|
||
use std::net::{IpAddr, SocketAddr}; | ||
|
||
use std::path::PathBuf; | ||
|
@@ -713,6 +714,78 @@ mod namespaced { | |
Ok(()) | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_prefetch_forget_certs() -> anyhow::Result<()> { | ||
// TODO: this test doesn't really need namespacing, but the direct test doesn't allow dynamic config changes. | ||
let mut manager = setup_netns_test!(InPod); | ||
let id1 = identity::Identity::Spiffe { | ||
trust_domain: "cluster.local".into(), | ||
service_account: "sa1".into(), | ||
namespace: "default".into(), | ||
}; | ||
let id1s = id1.to_string(); | ||
|
||
let ta = manager.deploy_ztunnel(DEFAULT_NODE).await?; | ||
|
||
let check = |want: Vec<String>, help: &str| { | ||
let cm = ta.cert_manager.clone(); | ||
let help = help.to_string(); | ||
async move { | ||
// Cert manager is async, so we need to wait | ||
let res = check_eventually( | ||
Duration::from_secs(2), | ||
|| cm.collect_certs(|a, _b| a.to_string()), | ||
want, | ||
) | ||
.await; | ||
assert!(res.is_ok(), "{}: got {:?}", help, res.err().unwrap()); | ||
} | ||
}; | ||
check(vec![], "initially empty").await; | ||
manager | ||
.workload_builder("id1-a-remote-node", REMOTE_NODE) | ||
.identity(id1.clone()) | ||
.register() | ||
.await?; | ||
check(vec![], "we should not prefetch remote nodes").await; | ||
manager | ||
.workload_builder("id1-a-same-node", DEFAULT_NODE) | ||
.identity(id1.clone()) | ||
.register() | ||
.await?; | ||
check(vec![id1s.clone()], "we should prefetch our nodes").await; | ||
manager | ||
.workload_builder("id1-b-same-node", DEFAULT_NODE) | ||
.identity(id1.clone()) | ||
.register() | ||
.await?; | ||
check( | ||
vec![id1s.clone()], | ||
"multiple of same identity shouldn't do anything", | ||
) | ||
.await; | ||
manager.delete_workload("id1-a-remote-node").await?; | ||
check( | ||
vec![id1s.clone()], | ||
"removing remote node shouldn't impact anything", | ||
) | ||
.await; | ||
manager.delete_workload("id1-b-same-node").await?; | ||
check( | ||
vec![id1s.clone()], | ||
"removing local node shouldn't impact anything if I still have some running", | ||
) | ||
.await; | ||
manager.delete_workload("id1-a-same-node").await?; | ||
// TODO: this should be vec![], but our testing setup doesn't exercise the real codepath | ||
check( | ||
vec![id1s.clone()], | ||
"removing final workload should clear things out", | ||
) | ||
.await; | ||
Comment on lines
+780
to
+785
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. Is this something we're looking to address before merging? Is it something covered elsewhere so we're not that worried? Kind of odd to assert a final state that isn't actually the state it should be 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. I would love to before merging though it will take a lot of work I may not have time to in the timelines this would be good to merge in (1.22.0). I think asserting the final state in the meantime is better than no assertion so if/when we fix it, it is remembered 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. yeah, odd but probably the least bad option I suppose |
||
Ok(()) | ||
} | ||
|
||
/// initialize_namespace_tests sets up the namespace tests. | ||
/// These utilize the `unshare` syscall to setup an environment where we: | ||
/// * Are "root" | ||
|
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 think this comment describes the intended use for track_identity rather than what this code does. Should we consider adding this comment to the insert method itself and/or changing
track_identity
to beis_node_local
perhaps?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.
should_track_certificates_for_removal()
probably belongs inworkload
and should be checked as part ofinsert
, and not incert_mgr
- it's being called beforeworkload.insert
pretty much everywhere.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.
The reason I did it this way is workload doesn't have access to the proxy mode, local node, etc at all, so it cannot make the call itself. We could plumb it down, but then its inconsistent with the
should_prefetch_certificate
and requires even more plumbing aroundThere 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.
Figured.
should_prefetch
andshould_track
are almost the same check and it feels like both should probably go inworkload
but yeah that's getting OOS for this.