-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Making Pulsar Proxy more secure #1002
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
Merged
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
f956e8d
Made service discovery optional for proxy
878266a
Creating a proto file remains
85206bf
Updated proto file for Pulsar Proxy
d982ec7
Fixed compilation error
cee5751
Merge branch 'Proxy2' of https://github.com/jai1/pulsar into Proxy2
09d5bcf
Added tests and fixed some logic which causes existing test to break
0f77bfe
Fixed tests
069003c
Added certificates
76497c7
Tests
2516038
Tests
578fdb6
Readded Server connection code
9939742
Corrected and fixed some test cases
b716ae3
Removed sending of original auth data
bc95361
Handled merge conflict
25fe708
Fixed some spaces in license header and Commands.java
bc54ffd
Fixed Redirect logic
2071d13
Handled merge conflict
9ee13dd
Added licene headers
f5f7a2e
Resolved Merge Conflict
fd49d55
Corrected some logging and Start up dependencies
252cce3
Fixed test case dependencies
65b9cd5
Resolved merge conflict
b03cc36
Addressed Rajan's Comments
569bc8a
Addressed Matteo's comments
5656d6a
Simplified logic in AuthorizationManager.canLookupAsync as per Andrew…
a5c9b6a
Addressed Rajans changes
d50a8bf
Addressed Matteos comments
75958af
Fixed compilation errors
006e8c6
Changd cluster name to get tests to work
2bbac2f
Merge branch 'master' of https://github.com/yahoo/pulsar into Proxy2
5e5a2a2
Fixed test cases to not create clusters since broker already does
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,9 @@ | |
| import java.util.Map; | ||
| import java.util.Set; | ||
| import java.util.concurrent.CompletableFuture; | ||
| import java.util.concurrent.CountDownLatch; | ||
| import java.util.concurrent.atomic.AtomicBoolean; | ||
|
|
||
| import static java.util.concurrent.TimeUnit.SECONDS; | ||
| import static org.apache.commons.lang3.StringUtils.isNotBlank; | ||
| import static org.apache.pulsar.zookeeper.ZooKeeperCache.cacheTimeOutInSec; | ||
|
|
@@ -66,8 +69,8 @@ public boolean canProduce(DestinationName destination, String role) throws Excep | |
| log.warn("Time-out {} sec while checking authorization on {} ", cacheTimeOutInSec, destination); | ||
| throw e; | ||
| } catch (Exception e) { | ||
| log.warn("Producer-client with Role - {} failed to get permissions for destination - {}", role, | ||
| destination, e); | ||
| log.warn("Producer-client with Role - {} failed to get permissions for destination - {}. {}", role, | ||
| destination, e.getMessage()); | ||
| throw e; | ||
| } | ||
| } | ||
|
|
@@ -96,8 +99,9 @@ public CompletableFuture<Boolean> canConsumeAsync(DestinationName destination, S | |
| switch (policies.get().subscription_auth_mode) { | ||
| case Prefix: | ||
| if (!subscription.startsWith(role)) { | ||
| PulsarServerException ex = new PulsarServerException( | ||
| String.format("Failed to create consumer - The subscription name needs to be prefixed by the authentication role, like %s-xxxx for destination: %s", role, destination)); | ||
| PulsarServerException ex = new PulsarServerException(String.format( | ||
| "Failed to create consumer - The subscription name needs to be prefixed by the authentication role, like %s-xxxx for destination: %s", | ||
| role, destination)); | ||
| permissionFuture.completeExceptionally(ex); | ||
| return; | ||
| } | ||
|
|
@@ -111,13 +115,12 @@ public CompletableFuture<Boolean> canConsumeAsync(DestinationName destination, S | |
| permissionFuture.complete(isAuthorized); | ||
| }); | ||
| }).exceptionally(ex -> { | ||
| log.warn("Client with Role - {} failed to get permissions for destination - {}", role, destination, | ||
| ex); | ||
| log.warn("Client with Role - {} failed to get permissions for destination - {}. {}", role, destination, ex.getMessage()); | ||
| permissionFuture.completeExceptionally(ex); | ||
| return null; | ||
| }); | ||
| } catch (Exception e) { | ||
| log.warn("Client with Role - {} failed to get permissions for destination - {}", role, destination, e); | ||
| log.warn("Client with Role - {} failed to get permissions for destination - {}. {}", role, destination, e.getMessage()); | ||
| permissionFuture.completeExceptionally(e); | ||
| } | ||
| return permissionFuture; | ||
|
|
@@ -130,8 +133,8 @@ public boolean canConsume(DestinationName destination, String role, String subsc | |
| log.warn("Time-out {} sec while checking authorization on {} ", cacheTimeOutInSec, destination); | ||
| throw e; | ||
| } catch (Exception e) { | ||
| log.warn("Consumer-client with Role - {} failed to get permissions for destination - {}", role, | ||
| destination, e); | ||
| log.warn("Consumer-client with Role - {} failed to get permissions for destination - {}. {}", role, | ||
| destination, e.getMessage()); | ||
| throw e; | ||
| } | ||
| } | ||
|
|
@@ -150,8 +153,46 @@ public boolean canLookup(DestinationName destination, String role) throws Except | |
| return canProduce(destination, role) || canConsume(destination, role, null); | ||
| } | ||
|
|
||
| private CompletableFuture<Boolean> checkAuthorization(DestinationName destination, String role, | ||
| AuthAction action) { | ||
| /** | ||
| * Check whether the specified role can perform a lookup for the specified destination. | ||
| * | ||
| * For that the caller needs to have producer or consumer permission. | ||
| * | ||
| * @param destination | ||
| * @param role | ||
| * @return | ||
| * @throws Exception | ||
| */ | ||
| public CompletableFuture<Boolean> canLookupAsync(DestinationName destination, String role) { | ||
| CompletableFuture<Boolean> finalResult = new CompletableFuture<Boolean>(); | ||
| canProduceAsync(destination, role).whenComplete((produceAuthorized, ex) -> { | ||
| if (ex == null) { | ||
| if (produceAuthorized) { | ||
| finalResult.complete(produceAuthorized); | ||
| return; | ||
| } | ||
| } else if (log.isDebugEnabled()) { | ||
| log.debug("Destination [{}] Role [{}] exception occured while trying to check Produce permissions. {}", | ||
| destination.toString(), role, ex.getMessage()); | ||
| } | ||
| canConsumeAsync(destination, role, null).whenComplete((consumeAuthorized, e) -> { | ||
| if (e == null) { | ||
| if (consumeAuthorized) { | ||
| finalResult.complete(consumeAuthorized); | ||
| return; | ||
| } | ||
| } else if (log.isDebugEnabled()) { | ||
| log.debug( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| "Destination [{}] Role [{}] exception occured while trying to check Consume permissions. {}", | ||
| destination.toString(), role, e.getMessage()); | ||
| } | ||
| finalResult.complete(false); | ||
| }); | ||
| }); | ||
| return finalResult; | ||
| } | ||
|
|
||
| private CompletableFuture<Boolean> checkAuthorization(DestinationName destination, String role, AuthAction action) { | ||
| if (isSuperUser(role)) { | ||
| return CompletableFuture.completedFuture(true); | ||
| } else { | ||
|
|
@@ -218,13 +259,13 @@ public CompletableFuture<Boolean> checkPermission(DestinationName destination, S | |
| } | ||
| permissionFuture.complete(false); | ||
| }).exceptionally(ex -> { | ||
| log.warn("Client with Role - {} failed to get permissions for destination - {}", role, destination, | ||
| ex); | ||
| log.warn("Client with Role - {} failed to get permissions for destination - {}. {}", role, destination, | ||
| ex.getMessage()); | ||
| permissionFuture.completeExceptionally(ex); | ||
| return null; | ||
| }); | ||
| } catch (Exception e) { | ||
| log.warn("Client with Role - {} failed to get permissions for destination - {}", role, destination, e); | ||
| log.warn("Client with Role - {} failed to get permissions for destination - {}. {}", role, destination, e.getMessage()); | ||
| permissionFuture.completeExceptionally(e); | ||
| } | ||
| return permissionFuture; | ||
|
|
@@ -244,8 +285,7 @@ private boolean checkWildcardPermission(String checkedRole, AuthAction checkedAc | |
| } | ||
|
|
||
| // Suffix match | ||
| if (permittedRole.charAt(0) == '*' | ||
| && checkedRole.endsWith(permittedRole.substring(1)) | ||
| if (permittedRole.charAt(0) == '*' && checkedRole.endsWith(permittedRole.substring(1)) | ||
| && permittedActions.contains(checkedAction)) { | ||
| return true; | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.