Repository navigation
Conversation
NickLarsenNZ
left a comment
There was a problem hiding this comment.
LGTM. I left some comments. Nothing major, just some suggestions.
I do think we should hold off on merging it until after the release, just so it has some time to soak in our regular tests.
| #[snafu(display( | ||
| "the newest CA in {secret}, which can be used until {active_until}, retires too soon to issue usable certificates considering the configured restart buffer of {restart_buffer}, a CA with a later expiry must be added" | ||
| ))] | ||
| CaExpiresTooSoon { | ||
| active_until: OffsetDateTime, | ||
| restart_buffer: Duration, | ||
| secret: ObjectRef<Secret>, | ||
| }, | ||
|
|
There was a problem hiding this comment.
Maybe we should use secret_ref (because of how it reads in other code further below).
| #[snafu(display( | |
| "the newest CA in {secret}, which can be used until {active_until}, retires too soon to issue usable certificates considering the configured restart buffer of {restart_buffer}, a CA with a later expiry must be added" | |
| ))] | |
| CaExpiresTooSoon { | |
| active_until: OffsetDateTime, | |
| restart_buffer: Duration, | |
| secret: ObjectRef<Secret>, | |
| }, | |
| #[snafu(display( | |
| "the newest CA in {secret_ref}, which can be used until {active_until}, retires too soon to issue usable certificates considering the configured restart buffer of {restart_buffer}, a CA with a later expiry must be added" | |
| ))] | |
| CaExpiresTooSoon { | |
| active_until: OffsetDateTime, | |
| restart_buffer: Duration, | |
| secret_ref: ObjectRef<Secret>, | |
| }, | |
| Error::InvalidCertLifetime { .. } => None, | ||
| Error::RetirementDurationNotShorterThanCertificateLifetime { .. } => None, | ||
| Error::TooShortCertLifetimeRequiresTimeTravel { .. } => None, | ||
| Error::CaExpiresTooSoon { secret, .. } => Some(secret.clone().erase()), |
There was a problem hiding this comment.
Relates to my suggestion above.
| Error::CaExpiresTooSoon { secret, .. } => Some(secret.clone().erase()), | |
| Error::CaExpiresTooSoon { secret_ref, .. } => Some(secret_ref.clone().erase()), |
What do we need erase here for? Ahh that's to upcast Secret to DynamicObject.
| active_until = now + remaining_ca_lifetime, | ||
| class = selector.class, | ||
| )), | ||
| action: "ProvisionSecret".to_string(), |
There was a problem hiding this comment.
We convert the static str ref into an owned String. So we should communicate that by using to_owned instead of to_string.
| action: "ProvisionSecret".to_string(), | |
| action: "ProvisionSecret".to_owned(), |
Same with the other to_string() calls.
| Some(remaining_ca_lifetime) => CaExpiresTooSoonSnafu { | ||
| active_until: now + remaining_ca_lifetime, | ||
| restart_buffer: cert_restart_buffer, | ||
| secret: self.ca_manager.source_secret().clone(), |
There was a problem hiding this comment.
Part of an earlier suggestion
| secret: self.ca_manager.source_secret().clone(), | |
| secret_ref: self.ca_manager.source_secret().clone(), |
| now: OffsetDateTime, | ||
| ) -> Option<Duration> { | ||
| let remaining_ca_lifetime = newest_ca_active_until | ||
| .and_then(|active_until| std::time::Duration::try_from(active_until - now).ok()) | ||
| .map(Duration::from)?; | ||
| (cert_lifetime > remaining_ca_lifetime).then_some(remaining_ca_lifetime) |
There was a problem hiding this comment.
I think we should rename this. As it being now is not enforced (it could be any OffsetDateTime).
Note: now in the calling context is fine, because it really is now.
Maybe:
| now: OffsetDateTime, | |
| ) -> Option<Duration> { | |
| let remaining_ca_lifetime = newest_ca_active_until | |
| .and_then(|active_until| std::time::Duration::try_from(active_until - now).ok()) | |
| .map(Duration::from)?; | |
| (cert_lifetime > remaining_ca_lifetime).then_some(remaining_ca_lifetime) | |
| from_when: OffsetDateTime, | |
| ) -> Option<Duration> { | |
| let remaining_ca_lifetime = newest_ca_active_until | |
| .and_then(|active_until| std::time::Duration::try_from(active_until - from_when).ok()) | |
| .map(Duration::from)?; | |
| (cert_lifetime > remaining_ca_lifetime).then_some(remaining_ca_lifetime) |
Or something similar?
| impl std::fmt::Debug for SecretContents { | ||
| fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
| f.debug_struct("SecretContents") | ||
| .field("data", &self.data) |
There was a problem hiding this comment.
I don't think we should leak secret data in a debug impl.
There was a problem hiding this comment.
Or is it needed for the serialization into a Secret?
| self.save_secret_data( | ||
| &target_path, | ||
| data, | ||
| data.data, |
There was a problem hiding this comment.
We maybe want to rename the variable. I assume the second data is the actual Secret.data. What is the first data?
Note to self, it comes from:
let data = backend
.get_secret_data(&selector, pod_info)| const CONTROLLER_NAME: &str = "csi-node-service"; | ||
| pub const FULL_CONTROLLER_NAME: &str = concatcp!(CONTROLLER_NAME, ".", OPERATOR_NAME); | ||
|
|
There was a problem hiding this comment.
I'm surprised we didn't already have this as a const.
| cert_lifetime: Duration, | ||
| newest_ca_active_until: Option<OffsetDateTime>, | ||
| now: OffsetDateTime, | ||
| ) -> Option<Duration> { |
There was a problem hiding this comment.
It's not a major problem, but I think it might be best to always return a Duration, rather than an Option.
Currently, None represents there being no reduction. But the function name says cert_livetime_cap_by_ca.
If None is idea, maybe the function name should change to mention reduction (or similar).
|
|
||
| /// Returns the point in time until which the newest CA may still sign certificates. | ||
| /// Returns [`None`] if there are no CAs. | ||
| pub fn newest_ca_active_until(&self) -> Option<OffsetDateTime> { |
There was a problem hiding this comment.
Might be worth having an explicit test for this one. If only as documentation.
Description
Fixes #753
This PR
autoGenerateisfalse, but it also appeared (according to Claude) when caCertificateLifetime < 5 × caCertificateRetirementDuration, the cap here also fixes that situationTlsGenerate::get_or_create_k8s_certificate. I tried it first but it wasn't necessary and the whole function seems to have grown over time and was tangled with different scenarios, tried refactoring but just confused myself with all the calculations. Can confirm this one though autoTls: calculation for secure maximum certificate lifetimes so that all pods that are deployed trust every other deployed pod is too loose #754 -> according to Claude the fix would be, but I didn't test or include it in the PR:Definition of Done Checklist
Author
Reviewer
Acceptance
type/deprecationlabel & add to the deprecation scheduletype/experimentallabel & add to the experimental features tracker