Add possibility to configure mTLS validityDays and renewalDays for each KafkaUser#12658
Add possibility to configure mTLS validityDays and renewalDays for each KafkaUser#12658im-konge wants to merge 3 commits intostrimzi:mainfrom
validityDays and renewalDays for each KafkaUser#12658Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #12658 +/- ##
============================================
- Coverage 75.07% 75.01% -0.06%
- Complexity 6513 6517 +4
============================================
Files 377 377
Lines 25092 25124 +32
Branches 3268 3276 +8
============================================
+ Hits 18838 18848 +10
- Misses 4914 4934 +20
- Partials 1340 1342 +2
🚀 New features to boost your workflow:
|
|
/gha run pipeline=regression,upgrade |
|
⏳ System test verification started: link The following 10 job(s) will be executed:
Tests will start after successful build completion. |
|
🎉 System test verification passed: link |
16e3c12 to
ae7ec92
Compare
Signed-off-by: Lukas Kral <lukywill16@gmail.com> finish implementation Signed-off-by: Lukas Kral <lukywill16@gmail.com> fix tests Signed-off-by: Lukas Kral <lukywill16@gmail.com> add changelog Signed-off-by: Lukas Kral <lukywill16@gmail.com> same value of validityDays and renewalDays in KafkaUserModelCertificateHandlingTest Signed-off-by: Lukas Kral <lukywill16@gmail.com> crds 🤦 Signed-off-by: Lukas Kral <lukywill16@gmail.com> update API docs and add ST for this change Signed-off-by: Lukas Kral <lukywill16@gmail.com>
ae7ec92 to
8d6cfed
Compare
Signed-off-by: Lukas Kral <lukywill16@gmail.com>
4b32af4 to
7d3f1cd
Compare
Signed-off-by: Lukas Kral <lukywill16@gmail.com>
|
/gha run pipeline=regression,upgrade |
|
⏳ System test verification started: link The following 10 job(s) will be executed:
Tests will start after successful build completion. |
|
🎉 System test verification passed: link |
| @CelValidation.CelValidationRule( | ||
| rule = "self > 0", | ||
| message = "'validityDays' has to be higher than 0." | ||
| ) |
There was a problem hiding this comment.
Does this work when it is not set?
There was a problem hiding this comment.
There is no validation if it is not set. I tried that. Or better - I didn't hit any issue when I was testing the feature.
| }) | ||
| @Description( | ||
| "Number of days for which the user certificate should be valid. " + | ||
| "If not configured, default User Operator value is used. " + |
There was a problem hiding this comment.
Given majority of uses are from Kafka CR, should we say that by default it uses Clients CA cofiguration? (here as well as below)
There was a problem hiding this comment.
Yeah I can change that, good point, thanks.
| * | ||
| * @return True if the certificate should be renewed due to new validity period. False otherwise. | ||
| */ | ||
| public boolean requiresImmediateRenewalDueToValidityChange(Secret secret, String certKey) { |
There was a problem hiding this comment.
Why is this needed? Why not have it behave as with other certificates?
There was a problem hiding this comment.
Why is this needed? Why not have it behave as with other certificates?
I added this because of the approved proposal:
If validityDays is set or reduced on an existing KafkaUser whose current certificate would already be expired or would exceed the new validity period, the User Operator must renew the certificate immediately on the next reconciliation rather than waiting for the natural renewal window.
Or am I misunderstanding this sentence in some way?
There was a problem hiding this comment.
Also, why does it belong here?
I added it there, because there are also other methods checking if the certificate is expiring etc.
But maybe better place would be ClientsCa.
There was a problem hiding this comment.
I do not follow this sentence. In all our other cases, the validity is used for new certificates. The renewal period (or manual annotation) is used to decide when to renew it.
There was a problem hiding this comment.
Also, why does it belong here?
I added it there, because there are also other methods checking if the certificate is expiring etc. But maybe better place would be
ClientsCa.
I do not think any other certificate is using it because it is a completely unique thing in this PR. So it probably should not mix into the Ca at all.
There was a problem hiding this comment.
I do not follow this sentence. In all our other cases, the validity is used for new certificates. The renewal period (or manual annotation) is used to decide when to renew it.
Well I just implemented what was approved and written in the proposal. Without that, it would have much less changes in the tests and everywhere else.
Maybe I completely misunderstood the sentence. But that's how I understand it - in case that the current certificate's validity would exceed the new one or the current certificate would be already expired under new validity, renew the certificate immediately.
But if it doesn't make sense, I think I should update the proposal and remove this block of code.
@sebastiangaiser did I understand the sentence incorrectly?
| if (renewalDays >= validityDays) { | ||
| throw new InvalidResourceException("spec.authentication.renewalDays is higher or equal to spec.authentication.validityDays. It should be configured to be lower than spec.authentication.validityDays."); | ||
| } |
There was a problem hiding this comment.
Should you validate this also in CEL? And while a validation in code might be useful, it should probably happen somewhere in some constructor?
There was a problem hiding this comment.
I didn't use CEL for this one in case of some weird combination of default validity/renewal days will be used from operator config and also one of those two will be configured in the KafkaUser.
So let's say that in KafkaUser you will have validityDays set to 30, without renewalDays being set in the KafkaUser's spec -> then it would use default for renewalDays, which can be 30 as well.
But that is not something you can check using CEL.
And I can have a look for a better place to put this one, maybe it will be then less confusing where is it being configured (I mean those two variables).
There was a problem hiding this comment.
That is kinds wierd. Should that be allowed? 🤔
In any case, I think you definitely need to decidde if this is a class thing and then do it in cosntructor or a method thing and then do it in the method. Given certifcates are used only by some users, method might be fine. But don't mix it.
There was a problem hiding this comment.
That is kinds wierd. Should that be allowed? 🤔
Maybe it would be better to validate that in case that one field is set, the second field has to be set as well. In that case we can move all of this to the CEL validation.
Given certifcates are used only by some users, method might be fine. But don't mix it.
I will update it, yes. Maybe it will be even simpler in case that we will forbid to set just one field and leave some default. That makes sense to me, thanks.
| private int validityDays; | ||
| private int renewalDays; |
There was a problem hiding this comment.
This is pretty confusing. How and where is it set? What it is?
There was a problem hiding this comment.
It is configured in validateValidityAndRenewalDays. I'm not sure why it is confusing - they were used there even before. But they were passed as the method arguments, I renamed them to be "defaults" coming from the User Operator config and in case that KafkaUser has different configuration, it is used like that.
| validityDays, | ||
| renewalDays, | ||
| this.validityDays, | ||
| this.renewalDays, |
There was a problem hiding this comment.
In what is it confusing?
There was a problem hiding this comment.
The whole way how you handle it is confusing. Why do you need the class level fields? Why do you set them from some method called from another method much later? Why don't you handle all of it right here in the code or in the place where it is called from?
There was a problem hiding this comment.
From other comments I get why it is confusing 😀 I just didn't get it from this comment. I will anyway rewrite the whole thing based on other comments, so this will be removed as well. Thanks.
Type of change
Description
This PR implements proposal about Configurable validityDays and renewalDays per KafkaUser. As described in the proposal, it adds
validityDaysandrenewalDaysto theKafkaUserCRD, when thetypeof authn istls- which is covered by CEL validation, together with values of both fields to be higher than 0.Because of handling of the validity period inside the code (so checking if the current certificate would be expired or if current certificate's validity period exceeds the new one), I had to add generating of clients cert and key inside the
MockCertManagerclass, because current certificate was valid for more like 100 years, which would every time trigger the immediate renewal of certificate. With the generated cert it will pass the validation period check and it will continue doing the checks as before. Also, I removed some of the unused methods.Also, the values inside
KafkaUserModelCertificateHandlingTestare lowered from 1000 and 500 to 365 and 182, to match the validity of the current certificate - stored inUSER_CRT_FOR_EXPIRATION_TEST.Fixes #12336
Checklist