-
Notifications
You must be signed in to change notification settings - Fork 48
Handle invalid ValidityDuration user input #253
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
base: main
Are you sure you want to change the base?
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: ArkaSaha30 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
685ced1 to
119b232
Compare
|
cc @neolit123 |
783c3dc to
e6346e5
Compare
|
/test pull-etcd-operator-test-e2e |
internal/controller/utils.go
Outdated
| // Set default duration to 365 days for auto provider if not provided | ||
| var duration time.Duration | ||
| if autoConfig.ValidityDuration == "" { | ||
| duration = certInterface.DefaultAutoValidity | ||
| } else { | ||
| var err error | ||
| duration, err = time.ParseDuration(autoConfig.ValidityDuration) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to parse ValidityDuration: %w", err) | ||
| } |
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.
Please add a function something like below, and reuse it for both createCMCertificateConfig and createAutoCertificateConfig
func parseValidityDuration(customizedDuration string, defaultDuration time.Duration) (time.Duration, error)
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.
Sure, updated the PR.
ivanvc
left a comment
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.
Thanks for the pull request, Arka. Other than Benjamin's comment and one observation I left, this looks great :)
pkg/certificate/auto/provider.go
Outdated
| log.Printf("calling SelfCert with hosts: %v", hosts) | ||
|
|
||
| tlsInfo, selfCertErr := transport.SelfCert(zap.NewNop(), tmpDir, hosts, uint(validity/DefaultValidity)) | ||
| tlsInfo, selfCertErr := transport.SelfCert(zap.NewNop(), tmpDir, hosts, uint(validity/interfaces.DefaultAutoValidity)) |
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 that dividing by interfaces.DefaultAutoValidity may be error-prone in the future (i.e., if someone changes the DefaultAutoValidity to anything other than one year). I think this division needs to be fixed to be by 365 * 24 * time.Hour, as transport.SelfCert(...) expects this to be years.
It could be another constant defined in this function.
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.
Sure, updated the PR
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'll debug and fix the failing test as well
This commit will handle a scenario of invalid cert-manager ValidityDuration user input and throw an error. In case, ValidityDuration is not defined by user it will default to 90days for cert-manager Signed-off-by: ArkaSaha30 <[email protected]>
e6346e5 to
4adafe5
Compare
This commit will handle a scenario of invalid auto cert provider ValidityDuration user input and throw an error. In case, ValidityDuration is not defined by user it will default to 365days for auto cert provider Signed-off-by: ArkaSaha30 <[email protected]>
4adafe5 to
4d9d86c
Compare
Signed-off-by: ArkaSaha30 <[email protected]>
|
@ArkaSaha30: The following test failed, say
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
This PR will handle a scenario of invalid
ValidityDurationuser input for the following certificate providers and throw an error.In case
ValidityDurationis not defined by the user, it will default to the corresponding default values:Fixes: #251