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

Proxy forward auth data #1169

Merged
merged 20 commits into from Feb 8, 2018
Merged

Proxy forward auth data #1169

merged 20 commits into from Feb 8, 2018

Conversation

jai1
Copy link
Contributor

@jai1 jai1 commented Feb 2, 2018

======

Currently the proxy extracts and forwards the client Principal to the broker. Client Principal is a modifiable string i.e can be changed or manufactured by the Proxy.

What we want to do instead is to send the clientAuthData to the broker - which is in most cases digitally signed. The broker will extract the client principal from the clientAuthData and reauthenticate the client.

In order to enforce this behavior we have introduced two new flags:-

  • authenticateOriginalAuthData on the broker
  • forwardClientAuthData on the Proxy

======

@msb-at-yahoo

@jai1 jai1 added the type/enhancement The enhancements for the existing features or docs. e.g. reduce memory usage of the delayed messages label Feb 2, 2018
@jai1 jai1 self-assigned this Feb 2, 2018
Copy link
Contributor

@saandrews saandrews left a comment

Choose a reason for hiding this comment

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

Overall looks ok, few comments.

@@ -101,7 +105,9 @@
private int nonPersistentPendingMessages = 0;
private final int MaxNonPersistentPendingMessages;
private String originalPrincipal = null;

private Set<String> proxyRoles = Sets.newHashSet();
Copy link
Contributor

Choose a reason for hiding this comment

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

If it's initialized in constructor, why create a new set here?

@@ -180,6 +188,19 @@ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws E
ctx.close();
}

private boolean validateOriginalPrincipal(String originalPrincipal, ByteBuf errorResponse, String topicName,
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add comment explaining the logic?

connect.hasOriginalAuthData() ? connect.getOriginalAuthData() : null,
connect.hasOriginalAuthMethod() ? connect.getOriginalAuthMethod() : null,
connect.hasOriginalPrincipal() ? connect.getOriginalPrincipal() : null,
sslSession);
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if sslSession is null ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

is sslSession is null AuthDataCommand.hasDataFromTls will return false


// Original auth role and auth Method that was passed
// to the proxy. In this case the auth info above
// will the the auth of the proxy itself
Copy link
Contributor

Choose a reason for hiding this comment

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

"will be the"?

Same for the remaining comments as well.

@jai1
Copy link
Contributor Author

jai1 commented Feb 6, 2018

@saandrews - have addressed your comments
@rdhabalia @merlimat - Please review this PR when you find time

@jai1
Copy link
Contributor Author

jai1 commented Feb 6, 2018

retest this please

@merlimat merlimat mentioned this pull request Feb 6, 2018
@@ -197,6 +197,10 @@
// role as proxyRoles - it will demand to see the original client role or certificate.
private Set<String> proxyRoles = Sets.newTreeSet();

// If this flag is set then the broker authenticates the original Auth data
// else it just accepts the originalPrincipal and authorizes it (if required).
private boolean authenticateOriginalAuthData = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

Config options need to be also added into conf/broker.conf and conf/standalone.conf, also check if there is a suitable name prefix this can be aggregated into.

@@ -213,8 +221,19 @@ protected void handleLookup(CommandLookupTopic lookup) {

final Semaphore lookupSemaphore = service.getLookupRequestSemaphore();
if (lookupSemaphore.tryAcquire()) {
final String originalPrincipal = lookup.hasOriginalPrincipal() ? lookup.getOriginalPrincipal()
: this.originalPrincipal;
String originalPrincipal;
Copy link
Contributor

Choose a reason for hiding this comment

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

This check can be done before acquiring the semaphore

Copy link
Contributor

Choose a reason for hiding this comment

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

As with similar changes, try to put common logic in a single method


// Forward client authData to Broker for re authorization
// make sure authentication is enabled for this to take effect
private boolean forwardAuthData = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be added to proxy.conf

Copy link
Contributor

Choose a reason for hiding this comment

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

Rename to something like authorizationForwardCredentials or similar

@jai1
Copy link
Contributor Author

jai1 commented Feb 7, 2018

As with similar changes, try to put common logic in a single method

@merlimat - Have addressed your comments

I feel the last commit (f986185) addresses your comment but makes the logic more difficult to understand

@jai1
Copy link
Contributor Author

jai1 commented Feb 7, 2018

@merlimat @rdhabalia @saandrews - can I merge this or do you want to take one last look.

Copy link
Contributor

@rdhabalia rdhabalia left a comment

Choose a reason for hiding this comment

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

overall LGTM..

lookup);

if (authenticateOriginalAuthData && lookup.hasOriginalAuthData() && originalPrincipal == null) {
return;
Copy link
Contributor

Choose a reason for hiding this comment

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

this condition seems little tricky. if we fail to validate original principal then validateOriginalPrincipal() will send failure response to the client and then thread should not process anything further. but then with this condition there is a possibility to move forward and thread will do further processing if authenticateOriginalAuthData && lookup.hasOriginalAuthData() =is false.??

@jai1
Copy link
Contributor Author

jai1 commented Feb 8, 2018

@rdhabalia - handled your comments - hope to get a +1 from you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/enhancement The enhancements for the existing features or docs. e.g. reduce memory usage of the delayed messages
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants