Skip to content
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

Bug 1700037: Check cert issuer directly #44

Merged
merged 1 commit into from
Apr 18, 2019

Conversation

mrogers950
Copy link
Contributor

Since we don't own the annotated service, the signed-by annotation might be overwritten by the owner, leading to continuous cert regeneration. Perform the issuer check by parsing the cert instead of relying on the signed-by annotation.

https://bugzilla.redhat.com/show_bug.cgi?id=1700037

@openshift-ci-robot openshift-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Apr 17, 2019
@openshift-ci-robot openshift-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Apr 17, 2019
@mrogers950
Copy link
Contributor Author

Updated tests.

@mrogers950
Copy link
Contributor Author

/retest

@s-urbaniak
Copy link
Contributor

/test e2e-aws

Copy link
Contributor

@stlaz stlaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor comments

func (sc *serviceServingCertController) issuedByCurrentCA(secret *corev1.Secret) bool {
certs, err := cert.ParseCertsPEM(secret.Data[corev1.TLSCertKey])
if err != nil {
return false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please log the error, if even only to debug

return false
}

if certs[0] == nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ParseCertsPEM() is fairly weirdly written. Could you add a check len() of returned certs as well in case its implementation changes in the future?

I went through the implementation down to x509.parseCertificate() and I think certs[0] can never be nil if err != nil but I might be wrong.

GKM7HG83Wj2hA+DWdy9ZJAdBLISB
-----END CERTIFICATE-----
`
const testCertWrong = `
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe rather call it testCertUnknownIssuer

@stlaz
Copy link
Contributor

stlaz commented Apr 18, 2019

This problem makes me wonder - we are currently still relying on the error annotations in service objects to skip error handling when we've done that enough time already. However, in this case, the annotations could also be removed by a different operator owning the service, which may still possibly cause update looping. Should we handle such cases as well? Maybe not set the annotation at all and just handle the error all of the time?

I'm fine with merging this after the comments are fixed, but the above is something we should probably still bear in mind.

@ericavonb
Copy link
Contributor

This problem makes me wonder - we are currently still relying on the error annotations in service objects to skip error handling when we've done that enough time already. However, in this case, the annotations could also be removed by a different operator owning the service, which may still possibly cause update looping. Should we handle such cases as well? Maybe not set the annotation at all and just handle the error all of the time?

I'd have to look into how the controllers are designed here and in library-go, but usually you use a retry counter on the work queue to deal with retry limits.

This makes me wonder if it would be better to use a custom resource (or the CSR resource?) where we can safely record errors in the status, rather than annotations.

@mrogers950
Copy link
Contributor Author

This makes me wonder if it would be better to use a custom resource (or the CSR resource?) where we can safely record errors in the status, rather than annotations.

This is true about the error annotations that they could also be stomped on. It would probably be better to move this error accounting to a section in the operator status.

@sallyom
Copy link
Contributor

sallyom commented Apr 18, 2019

I'm fine with merging this after the comments are fixed,

+1 and follow-up PR/discussion for the error accounting. this will unblock monitoring team.

Since we don't own the annotated service, the signed-by annotation might be
overwritten by the owner, leading to continuous cert regeneration. Perform the
issuer check by parsing the cert instead of relying on the signed-by
annotation.
@@ -210,6 +211,24 @@ func (sc *serviceServingCertController) requiresCertGeneration(service *corev1.S
return true
}

// Returns true if the secret certificate has the same issuer common name as the current CA, false
// if not or if there is a parsing error.
func (sc *serviceServingCertController) issuedByCurrentCA(secret *corev1.Secret) bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can be a pure function (remove struct receiver)

@ericavonb
Copy link
Contributor

/lgtm
minor comment, can be in follow up though

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Apr 18, 2019
@openshift-merge-robot openshift-merge-robot merged commit 319e883 into openshift:master Apr 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants