Navigation Menu

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

ceph: fix kms auto-detection when full TLS #8867

Merged
merged 1 commit into from Oct 14, 2021

Conversation

leseb
Copy link
Member

@leseb leseb commented Sep 29, 2021

Description of your changes:

When TLS is used and includes a caert, client key/cert, we need to copy
the content of the secret to a file in the operator's container
filesystem so that we can build the TLS config and thus the HTTP Client,
which reads those files.
Also, removing the files after each API call so they don't persist on
the filesystem forever.

Signed-off-by: Sébastien Han seb@redhat.com

Which issue is resolved by this Pull Request:
Resolves #

Checklist:

  • Commit Message Formatting: Commit titles and messages follow guidelines in the developer guide.
  • Skip Tests for Docs: Add the flag for skipping the build if this is only a documentation change. See here for the flag.
  • Skip Unrelated Tests: Add a flag to run tests for a specific storage provider. See test options.
  • Reviewed the developer guide on Submitting a Pull Request
  • Documentation has been updated, if necessary.
  • Unit tests have been added, if necessary.
  • Integration tests have been added, if necessary.
  • Pending release notes updated with breaking and/or notable changes, if necessary.
  • Upgrade from previous release is tested and upgrade user guide is updated, if necessary.
  • Code generation (make codegen) has been run to update object specifications, if necessary.

@mergify mergify bot added the ceph main ceph tag label Sep 29, 2021
@leseb leseb force-pushed the kv-auto-detect-with-certs branch 4 times, most recently from e3ca518 to 4c5d090 Compare September 30, 2021 12:33
@leseb leseb added this to In progress in v1.7 via automation Sep 30, 2021
pkg/daemon/ceph/osd/kms/kms.go Outdated Show resolved Hide resolved
pkg/daemon/ceph/osd/kms/vault.go Show resolved Hide resolved
@mergify
Copy link

mergify bot commented Oct 1, 2021

This pull request has merge conflicts that must be resolved before it can be merged. @leseb please rebase it. https://rook.io/docs/rook/latest/development-flow.html#updating-your-fork

@leseb leseb force-pushed the kv-auto-detect-with-certs branch 4 times, most recently from 1691be9 to 4ef2ff3 Compare October 1, 2021 08:48
@leseb leseb requested a review from BlaineEXE October 1, 2021 09:16
Copy link
Member

@BlaineEXE BlaineEXE left a comment

Choose a reason for hiding this comment

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

I wonder if the Sleep() calls in the tests are still needed.

If they are, I have generally seen the advice that unit tests that test timeouts should change the timeout value itself so that the test doesn't actually take many seconds to run unnecessarily. I think I've changed them to be on the order of milliseconds (10ms or so) with success on local runs as well as in CI.

pkg/daemon/ceph/osd/kms/vault_test.go Outdated Show resolved Hide resolved
pkg/daemon/ceph/osd/kms/vault_test.go Outdated Show resolved Hide resolved
// Populate TLS config
newConfigWithTLS, removeCertFiles, err := configTLS(clusterdContext, namespace, localSecretConfig)
if err != nil {
return nil, errors.Wrap(err, "failed to initialize vault tls configuration")
Copy link
Member

Choose a reason for hiding this comment

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

Would it be simpler to remove cert files here in the error condition, instead of inside configTLS()?

Suggested change
return nil, errors.Wrap(err, "failed to initialize vault tls configuration")
removeCertFiles()
return nil, errors.Wrap(err, "failed to initialize vault tls configuration")

Copy link
Member

Choose a reason for hiding this comment

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

I think removing the files from this function is the better design so that the calling function doesn't have to worry about handling special behavior. It seems like it's normal practice to me for go functions to clean up after themselves.

But I think what you're seeing is that modifying the function in the future, we could forget to keep removeCertFiles() before returning an error in configTLS()...

Copy link
Member

Choose a reason for hiding this comment

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

The caller already owns calling removeCertFiles() on success, so it seems reasonable to cleanup here on failure as well. Like you said, cleaning up could be missed in an individual error condition inside the method.

Copy link
Member Author

Choose a reason for hiding this comment

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

The cleanup is not missed anymore since we use defer in configTLS() now.

pkg/daemon/ceph/osd/kms/vault.go Outdated Show resolved Hide resolved
pkg/daemon/ceph/osd/kms/vault_test.go Outdated Show resolved Hide resolved
pkg/daemon/ceph/osd/kms/vault_test.go Outdated Show resolved Hide resolved
pkg/daemon/ceph/osd/kms/vault_test.go Show resolved Hide resolved
// Populate TLS config
newConfigWithTLS, removeCertFiles, err := configTLS(clusterdContext, namespace, localSecretConfig)
if err != nil {
return nil, errors.Wrap(err, "failed to initialize vault tls configuration")
Copy link
Member

Choose a reason for hiding this comment

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

I think removing the files from this function is the better design so that the calling function doesn't have to worry about handling special behavior. It seems like it's normal practice to me for go functions to clean up after themselves.

But I think what you're seeing is that modifying the function in the future, we could forget to keep removeCertFiles() before returning an error in configTLS()...

pkg/daemon/ceph/osd/kms/vault.go Outdated Show resolved Hide resolved
// The signature has named result parameters to help building 'defer' statements especially for the
// content of removeCertFiles which needs to be populated by the files to remove if no errors and be
// nil on errors
func configTLS(clusterdContext *clusterd.Context, namespace string, config map[string]string) (newCconfig map[string]string, removeCertFiles removeCertFilesFunction, retErr error) {
Copy link
Member

Choose a reason for hiding this comment

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

Nit: typo?

Suggested change
func configTLS(clusterdContext *clusterd.Context, namespace string, config map[string]string) (newCconfig map[string]string, removeCertFiles removeCertFilesFunction, retErr error) {
func configTLS(clusterdContext *clusterd.Context, namespace string, config map[string]string) (newConfig map[string]string, removeCertFiles removeCertFilesFunction, retErr error) {

Comment on lines +176 to +179
err := file.Close()
if err != nil {
logger.Errorf("failed to close file %q. %v", file.Name(), err)
}
Copy link
Member

Choose a reason for hiding this comment

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

All the files are definitely still open when this is called, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, we don't close them anywhere else.

assert.NoFileExists(t, config["VAULT_CLIENT_KEY"])
})

t.Run("advanced TLS config with temp file creation error", func(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

I'm having some trouble following what this test is checking for. Let's discuss in huddle.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok but essentially it's testing that previously created files are removed if any invocation in conifgTLS fails. It's testing the cleanup.

When TLS is used and includes a caert, client key/cert, we need to copy
the content of the secret to a file in the operator's container
filesystem so that we can build the TLS config and thus the HTTP Client,
which reads those files.
Also, removing the files after each API call so they don't persist on
the filesystem forever.

Signed-off-by: Sébastien Han <seb@redhat.com>
Copy link
Member

@travisn travisn left a comment

Choose a reason for hiding this comment

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

Is there an upstream need to backport to 1.6? If not, let's just backport to 1.7.

@leseb leseb merged commit 07986bc into rook:master Oct 14, 2021
v1.7 automation moved this from In progress to Done Oct 14, 2021
@leseb leseb deleted the kv-auto-detect-with-certs branch October 14, 2021 09:30
mergify bot added a commit that referenced this pull request Oct 14, 2021
ceph: fix kms auto-detection when full TLS (backport #8867)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ceph main ceph tag
Projects
No open projects
v1.7
Done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants