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

fix: Ensure verifyKvStoreConnection takes into account rootPrefix #5

Merged
merged 1 commit into from
Aug 9, 2022

Conversation

njhill
Copy link
Member

@njhill njhill commented Aug 8, 2022

Motivation

Instances of KVUtilsFactory are initialized for a particular connection configuration, which for etcd includes a "chroot" rootPrefix. All the utility methods honor this prefix, except the verifyKvConnection method.

This can cause problems when role-based access controls are configured in etcd and the client-configured userid doesn't have access outside of the rootPrefix key range. In this case the verifyKvConnection call will fail unexpectedly with a permission denied error.

Modifications

  • Adjust the verifyKvConnection to perform a get on a dummy (likely nonexistent) key within the rootPrefix range
  • Add auth-based unit test

Result

KVUtilsFactory#verifyKvConnection will work as expected in key-specific auth cases.

Motivation

Instances of KVUtilsFactory are initialized for a particular connection configuration, which for etcd includes a "chroot" rootPrefix. All the utility methods honor this prefix, except the verifyKvConnection method.

This can cause problems when role-based access controls are configured in etcd and the client-configured userid doesn't have access outside of the rootPrefix key range. In this case the verifyKvConnection call will fail unexpectedly with a permission denied error.

Modifications

- Adjust the verifyKvConnection to perform a get on a dummy (likely nonexistent) key within the rootPrefix range
- Add auth-based unit test

Result

KVUtilsFactory#verifyKvConnection will work as expected in key-specific auth cases.

Signed-off-by: Nick Hill <[email protected]>
@njhill njhill marked this pull request as ready for review August 9, 2022 15:12

@Override
public ListenableFuture<Boolean> verifyKvStoreConnection() {
return Futures.catching(Futures.transform(client.getKvClient().get(TEST_KEY).countOnly()
return Futures.catching(Futures.transform(client.getKvClient().get(pathToKey(TEST_PATH, false)).countOnly()
Copy link

Choose a reason for hiding this comment

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

is the .countOnly() what makes it cool to .get() a key that doesn't exist without throwing an error?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think even without that it's cool, it will just return an empty result (the "get" operation is actually generic and takes either a range or single key, as well as other filtering criteria, so it can return zero or more results).

Copy link

Choose a reason for hiding this comment

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

that's tight

Copy link

@joerunde joerunde left a comment

Choose a reason for hiding this comment

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

seems chill 😎

@njhill njhill merged commit 62d8d95 into main Aug 9, 2022
@njhill njhill deleted the fix-conn-verify branch August 9, 2022 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants