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

secrets: Allow adding additional middlewares #70

Merged
merged 2 commits into from
Feb 4, 2020

Conversation

fishy
Copy link
Member

@fishy fishy commented Feb 2, 2020

Also:

  1. Remove the type check after filewatcher.Get, which would never fail.
  2. Add Store.Stop()

@fishy
Copy link
Member Author

fishy commented Feb 2, 2020

cc @andizzle

@fishy fishy force-pushed the secrets-additional-middleware branch from e39e93e to 834efa6 Compare February 2, 2020 20:23
// AddMiddlewares call is not thread-safe, it should not be called concurrently.
func (s *Store) AddMiddlewares(middlewares ...SecretMiddleware) {
s.secretHandler(middlewares...)
s.secretHandlerFunc(s.getSecrets())
Copy link
Contributor

Choose a reason for hiding this comment

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

As commented this would also trigger existing middlewares. What do you think have this function accepts SecretHandlerFunc, call them and wrap them as SecretMiddleware?

https://github.com/reddit/baseplate.go/pull/71/files#diff-1a3fa2e612f9f352390e03634cc256d0R82

Copy link
Member Author

Choose a reason for hiding this comment

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

triggering existing middlewares shouldn't be a problem, because we are triggering them with the same secret data.

If we want to accept SecretHandlerFunc instead of SecretMiddleware as the arg, we should make it consistent and also SecretMiddleware in NewStore as well (and not export SecretMiddleware at all).

}

// GetCredentialSecret loads secrets from watcher, and fetches a credential secret from secrets
func (s *Store) GetCredentialSecret(path string) (CredentialSecret, error) {
secrets, ok := s.watcher.Get().(*Secrets)
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we should remove the type check. I don't like making assumptions based on upstream code that may or may not change in the future. If the type would be set in stone just a few lines above I'd be okay with it but this is a different package.

Copy link
Member Author

Choose a reason for hiding this comment

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

  1. This is the behavior of stdlib's atomic.Value, I'm pretty sure that's part of the the go 1 backward compatibility guarantee
  2. We control the parser implementation, and there's no reason we would return a different type in the parser.

Copy link
Member

Choose a reason for hiding this comment

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

But on these lines I don't see that it's using atomic.Value, it's referencing a different package. It's just defensive programming, doesn't really hurt to keep the practice of checking the type when you type assert. The opposite, does.

Copy link
Member Author

Choose a reason for hiding this comment

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

Even though, the second point still stands, that we control what are the values stored in the same package (parser implementation).

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Okay, sounds good!

}

// TODO 1: Patch upstream to support key rotation natively:
// TODO: Patch upstream to support key rotation natively:
Copy link
Member

Choose a reason for hiding this comment

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

Nice, can we add an issue in our repository to keep track of this?

Copy link
Member Author

Choose a reason for hiding this comment

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

#73

secrets/store.go Outdated
// but can still access the secrets as they were before Stop is called.
//
// It's OK to call Stop multiple times. Calls after the first one are no-ops.
func (s *Store) Stop() {
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we can find a method name that fits the semantic more. I was a bit confused about stopping the store. It doesn't really stop the store but just the updating of the underlying file I guess?

Copy link
Member Author

Choose a reason for hiding this comment

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

StopUpdating? Release? Do you have any suggestions?

Copy link
Contributor

Choose a reason for hiding this comment

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

Release sounds good or maybe Close?

Copy link
Member

Choose a reason for hiding this comment

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

In which scenario would this usually be called?

Copy link
Member Author

Choose a reason for hiding this comment

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

defer this right after a store is initialized to have an clean exit.

Copy link
Member

Choose a reason for hiding this comment

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

I mean for instance in production code. I saw the usage in test, I was just wondering it's purpose on the public interface of store :)

Copy link
Member Author

@fishy fishy Feb 3, 2020

Choose a reason for hiding this comment

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

You can (and should) still defer this in the main function in prod code.

Copy link
Member

Choose a reason for hiding this comment

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

Now where I understand this better I think both Close() or Stop() are fine.

Copy link
Member Author

Choose a reason for hiding this comment

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

Renamed to Close.

@fishy fishy force-pushed the secrets-additional-middleware branch from 324b0bd to 47d28ae Compare February 4, 2020 17:28
@fishy fishy force-pushed the secrets-additional-middleware branch 2 times, most recently from 7c7dc07 to 81f6180 Compare February 4, 2020 17:40
}

// GetCredentialSecret loads secrets from watcher, and fetches a credential secret from secrets
func (s *Store) GetCredentialSecret(path string) (CredentialSecret, error) {
secrets, ok := s.watcher.Get().(*Secrets)
Copy link
Member

Choose a reason for hiding this comment

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

Okay, sounds good!

Also:

1. Remove the type check after filewatcher.Get, which would never fail.
2. Add Store.Close()
@fishy fishy force-pushed the secrets-additional-middleware branch from 81f6180 to 76c32df Compare February 4, 2020 18:51
@fishy fishy merged commit 3514da1 into reddit:master Feb 4, 2020
@fishy fishy deleted the secrets-additional-middleware branch February 4, 2020 18:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants