You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2020/01/17 05:06:35 UTC
[GitHub] [pulsar] merlimat opened a new pull request #6074: PIP-55: Refresh
Authentication Credentials
merlimat opened a new pull request #6074: PIP-55: Refresh Authentication Credentials
URL: https://github.com/apache/pulsar/pull/6074
### Motivation
Implemented the authentication refreshing functionality.
Notes:
* Works with mutual auth providers
* Works through Pulsar proxy (when client credentials are forwarded to broker)
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [pulsar] ivankelly commented on a change in pull request #6074:
PIP-55: Refresh Authentication Credentials
Posted by GitBox <gi...@apache.org>.
ivankelly commented on a change in pull request #6074: PIP-55: Refresh Authentication Credentials
URL: https://github.com/apache/pulsar/pull/6074#discussion_r369983759
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java
##########
@@ -551,29 +624,46 @@ protected void handleConnect(CommandConnect connect) {
if (sslHandler != null) {
sslSession = ((SslHandler) sslHandler).engine().getSession();
}
- originalPrincipal = getOriginalPrincipal(
- connect.hasOriginalAuthData() ? connect.getOriginalAuthData() : null,
- connect.hasOriginalAuthMethod() ? connect.getOriginalAuthMethod() : null,
- connect.hasOriginalPrincipal() ? connect.getOriginalPrincipal() : null,
- sslSession);
authState = authenticationProvider.newAuthState(clientData, remoteAddress, sslSession);
authenticationData = authState.getAuthDataSource();
- doAuthentication(clientData, clientProtocolVersion, clientVersion);
+ state = doAuthentication(clientData, clientProtocolVersion, clientVersion);
Review comment:
not for this patch, but it seems strange that this is a synchronous call, given that authentication could be calling out to a remote system.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [pulsar] merlimat commented on a change in pull request #6074:
PIP-55: Refresh Authentication Credentials
Posted by GitBox <gi...@apache.org>.
merlimat commented on a change in pull request #6074: PIP-55: Refresh Authentication Credentials
URL: https://github.com/apache/pulsar/pull/6074#discussion_r370845882
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/PulsarChannelInitializer.java
##########
@@ -38,6 +48,11 @@
private final NettySslContextBuilder sslCtxRefresher;
private final ServiceConfiguration brokerConf;
+ private final Cache<SocketAddress, ServerCnx> connections = Caffeine.newBuilder()
Review comment:
The socket address is already kept in the `ServerCnx` itself, so it will not be a new allocation here.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [pulsar] ivankelly commented on a change in pull request #6074:
PIP-55: Refresh Authentication Credentials
Posted by GitBox <gi...@apache.org>.
ivankelly commented on a change in pull request #6074: PIP-55: Refresh Authentication Credentials
URL: https://github.com/apache/pulsar/pull/6074#discussion_r369976838
##########
File path: pulsar-broker-common/src/main/java/org/apache/pulsar/broker/authentication/AuthenticationProviderToken.java
##########
@@ -166,4 +179,61 @@ private SignatureAlgorithm getPublicKeyAlgType(ServiceConfiguration conf) throws
return SignatureAlgorithm.RS256;
}
}
+
+ private static final class TokenAuthenticationState implements AuthenticationState {
+ private final AuthenticationProviderToken provider;
+ private AuthenticationDataSource authenticationDataSource;
+ private Jwt<?, Claims> jwt;
+ private final SocketAddress remoteAddress;
+ private final SSLSession sslSession;
+ private long expiration;
+
+ TokenAuthenticationState(
+ AuthenticationProviderToken provider,
+ AuthData authData,
+ SocketAddress remoteAddress,
+ SSLSession sslSession) throws AuthenticationException {
+ this.provider = provider;
+ this.remoteAddress = remoteAddress;
+ this.sslSession = sslSession;
+ this.authenticate(authData);
+ }
+
+ @Override
+ public String getAuthRole() throws AuthenticationException {
+ return provider.getPrincipal(jwt);
+ }
+
+ @Override
+ public AuthData authenticate(AuthData authData) throws AuthenticationException {
+ String token = new String(authData.getBytes(), UTF_8);
+
+ this.jwt = provider.authenticateToken(token);
+ this.authenticationDataSource = new AuthenticationDataCommand(token, remoteAddress, sslSession);
+ if (jwt.getBody().getExpiration() != null) {
+ this.expiration = jwt.getBody().getExpiration().getTime();
+ } else {
+ this.expiration = 0;
Review comment:
nit: Why not set to Long.MAX_VALUE and make the check simpler?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [pulsar] merlimat commented on a change in pull request #6074:
PIP-55: Refresh Authentication Credentials
Posted by GitBox <gi...@apache.org>.
merlimat commented on a change in pull request #6074: PIP-55: Refresh Authentication Credentials
URL: https://github.com/apache/pulsar/pull/6074#discussion_r370842831
##########
File path: pulsar-common/src/main/proto/PulsarApi.proto
##########
@@ -235,6 +235,12 @@ message CommandConnect {
optional string original_auth_data = 8;
optional string original_auth_method = 9;
+ // Feature flags
+ optional FeatureFlags feature_flags = 10;
+}
+
+message FeatureFlags {
Review comment:
Bumping the version is a very primitive way of checking the supported features. It worked well when the client implementation was only Java and started to be problematic after that.
The reality is that all the clients out there will have a different set of supported features. Also, if someone just updates the`PulsarApi.proto` it looks like that client is now at the latest version, while in reality it might not be able to understand a specific command.
Exchanging the list of supported features will allow client to selectively implement features.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [pulsar] rdhabalia commented on a change in pull request #6074:
PIP-55: Refresh Authentication Credentials
Posted by GitBox <gi...@apache.org>.
rdhabalia commented on a change in pull request #6074: PIP-55: Refresh Authentication Credentials
URL: https://github.com/apache/pulsar/pull/6074#discussion_r370864152
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java
##########
@@ -497,8 +523,60 @@ private void doAuthentication(AuthData clientData,
log.debug("[{}] Authentication in progress client by method {}.",
remoteAddress, authMethod);
}
- state = State.Connecting;
- return;
+ return State.Connecting;
+ }
+
+ public void refreshAuthenticationCredentials() {
+ if (getState() != State.Connected || !isActive) {
+ // Connection is either still being established or already closed.
+ return;
+ }
+
+ AuthenticationState authState = this.originalAuthState != null ? originalAuthState : this.authState;
+ if (authState != null && !authState.isExpired()) {
+ // Credentials are still valid. Nothing to do at this point
+ return;
+ }
+
+ if (originalPrincipal != null && originalAuthState == null) {
+ log.info(
+ "[{}] Cannot revalidate user credential when using proxy and not forwarding the credentials. Closing connection",
+ remoteAddress);
+ return;
+ }
+
+ ctx.executor().execute(SafeRun.safeRun(() -> {
+ log.info("[{}] Refreshing authentication credentials", remoteAddress);
+
+ if (!supportsAuthenticationRefresh()) {
+ log.warn("[{}] Closing connection because client doesn't support auth credentials refresh", remoteAddress);
+ ctx.close();
Review comment:
if client doesn't support then let's not change the behavior and don't close the connection, because closing connection will interrupt the client side processing and it requires them to upgrade client lib immediately if client wants to fix auto disconnect. So, we don't want our client to complain for such changed behavior which requires them to upgrade client lib.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [pulsar] merlimat commented on a change in pull request #6074:
PIP-55: Refresh Authentication Credentials
Posted by GitBox <gi...@apache.org>.
merlimat commented on a change in pull request #6074: PIP-55: Refresh Authentication Credentials
URL: https://github.com/apache/pulsar/pull/6074#discussion_r370843340
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java
##########
@@ -551,29 +624,46 @@ protected void handleConnect(CommandConnect connect) {
if (sslHandler != null) {
sslSession = ((SslHandler) sslHandler).engine().getSession();
}
- originalPrincipal = getOriginalPrincipal(
- connect.hasOriginalAuthData() ? connect.getOriginalAuthData() : null,
- connect.hasOriginalAuthMethod() ? connect.getOriginalAuthMethod() : null,
- connect.hasOriginalPrincipal() ? connect.getOriginalPrincipal() : null,
- sslSession);
authState = authenticationProvider.newAuthState(clientData, remoteAddress, sslSession);
authenticationData = authState.getAuthDataSource();
- doAuthentication(clientData, clientProtocolVersion, clientVersion);
+ state = doAuthentication(clientData, clientProtocolVersion, clientVersion);
Review comment:
Yes, initially all auth methods were completely stateless and therefore didn't require any asynchronousness in the provider API. This is not true now in general and we'll have to make a bit of a refactor to achieve that.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [pulsar] jerrypeng commented on issue #6074: PIP-55: Refresh
Authentication Credentials
Posted by GitBox <gi...@apache.org>.
jerrypeng commented on issue #6074: PIP-55: Refresh Authentication Credentials
URL: https://github.com/apache/pulsar/pull/6074#issuecomment-575468826
@merlimat awesome feature! Overall LGTM. One small comment.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [pulsar] merlimat merged pull request #6074: PIP-55: Refresh
Authentication Credentials
Posted by GitBox <gi...@apache.org>.
merlimat merged pull request #6074: PIP-55: Refresh Authentication Credentials
URL: https://github.com/apache/pulsar/pull/6074
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [pulsar] ivankelly commented on a change in pull request #6074:
PIP-55: Refresh Authentication Credentials
Posted by GitBox <gi...@apache.org>.
ivankelly commented on a change in pull request #6074: PIP-55: Refresh Authentication Credentials
URL: https://github.com/apache/pulsar/pull/6074#discussion_r369985978
##########
File path: pulsar-common/src/main/proto/PulsarApi.proto
##########
@@ -235,6 +235,12 @@ message CommandConnect {
optional string original_auth_data = 8;
optional string original_auth_method = 9;
+ // Feature flags
+ optional FeatureFlags feature_flags = 10;
+}
+
+message FeatureFlags {
Review comment:
why a feature flag rather than bumping the version? Because some auth will not support reauth?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [pulsar] merlimat commented on a change in pull request #6074:
PIP-55: Refresh Authentication Credentials
Posted by GitBox <gi...@apache.org>.
merlimat commented on a change in pull request #6074: PIP-55: Refresh Authentication Credentials
URL: https://github.com/apache/pulsar/pull/6074#discussion_r370845931
##########
File path: pulsar-broker-common/src/main/java/org/apache/pulsar/broker/authentication/AuthenticationProviderToken.java
##########
@@ -166,4 +179,61 @@ private SignatureAlgorithm getPublicKeyAlgType(ServiceConfiguration conf) throws
return SignatureAlgorithm.RS256;
}
}
+
+ private static final class TokenAuthenticationState implements AuthenticationState {
+ private final AuthenticationProviderToken provider;
+ private AuthenticationDataSource authenticationDataSource;
+ private Jwt<?, Claims> jwt;
+ private final SocketAddress remoteAddress;
+ private final SSLSession sslSession;
+ private long expiration;
+
+ TokenAuthenticationState(
+ AuthenticationProviderToken provider,
+ AuthData authData,
+ SocketAddress remoteAddress,
+ SSLSession sslSession) throws AuthenticationException {
+ this.provider = provider;
+ this.remoteAddress = remoteAddress;
+ this.sslSession = sslSession;
+ this.authenticate(authData);
+ }
+
+ @Override
+ public String getAuthRole() throws AuthenticationException {
+ return provider.getPrincipal(jwt);
+ }
+
+ @Override
+ public AuthData authenticate(AuthData authData) throws AuthenticationException {
+ String token = new String(authData.getBytes(), UTF_8);
+
+ this.jwt = provider.authenticateToken(token);
+ this.authenticationDataSource = new AuthenticationDataCommand(token, remoteAddress, sslSession);
+ if (jwt.getBody().getExpiration() != null) {
+ this.expiration = jwt.getBody().getExpiration().getTime();
+ } else {
+ this.expiration = 0;
Review comment:
Fixed
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [pulsar] sijie commented on issue #6074: PIP-55: Refresh
Authentication Credentials
Posted by GitBox <gi...@apache.org>.
sijie commented on issue #6074: PIP-55: Refresh Authentication Credentials
URL: https://github.com/apache/pulsar/pull/6074#issuecomment-583997866
@rdhabalia any thoughts on Matteo's last comment?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [pulsar] sijie commented on issue #6074: PIP-55: Refresh
Authentication Credentials
Posted by GitBox <gi...@apache.org>.
sijie commented on issue #6074: PIP-55: Refresh Authentication Credentials
URL: https://github.com/apache/pulsar/pull/6074#issuecomment-581704581
@jerrypeng @rdhabalia can you review this pull request again? Matteo has addressed your comments.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [pulsar] rdhabalia commented on a change in pull request #6074:
PIP-55: Refresh Authentication Credentials
Posted by GitBox <gi...@apache.org>.
rdhabalia commented on a change in pull request #6074: PIP-55: Refresh Authentication Credentials
URL: https://github.com/apache/pulsar/pull/6074#discussion_r370861764
##########
File path: pulsar-common/src/main/proto/PulsarApi.proto
##########
@@ -235,6 +235,12 @@ message CommandConnect {
optional string original_auth_data = 8;
optional string original_auth_method = 9;
+ // Feature flags
+ optional FeatureFlags feature_flags = 10;
+}
+
+message FeatureFlags {
Review comment:
adding `FeatureFlags` makes sense. 👍
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [pulsar] rdhabalia commented on a change in pull request #6074:
PIP-55: Refresh Authentication Credentials
Posted by GitBox <gi...@apache.org>.
rdhabalia commented on a change in pull request #6074: PIP-55: Refresh Authentication Credentials
URL: https://github.com/apache/pulsar/pull/6074#discussion_r370856720
##########
File path: pulsar-broker-common/src/main/java/org/apache/pulsar/broker/ServiceConfiguration.java
##########
@@ -660,6 +660,12 @@
)
private Set<String> authenticationProviders = Sets.newTreeSet();
+ @FieldContext(
+ category = CATEGORY_AUTHENTICATION,
+ doc = "Interval of time for checking for expired authentication credentials"
+ )
+ private int authenticationRefreshCheckSeconds = 60;
Review comment:
we should disable it by default.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [pulsar] merlimat commented on a change in pull request #6074:
PIP-55: Refresh Authentication Credentials
Posted by GitBox <gi...@apache.org>.
merlimat commented on a change in pull request #6074: PIP-55: Refresh Authentication Credentials
URL: https://github.com/apache/pulsar/pull/6074#discussion_r370870784
##########
File path: pulsar-broker-common/src/main/java/org/apache/pulsar/broker/ServiceConfiguration.java
##########
@@ -660,6 +660,12 @@
)
private Set<String> authenticationProviders = Sets.newTreeSet();
+ @FieldContext(
+ category = CATEGORY_AUTHENTICATION,
+ doc = "Interval of time for checking for expired authentication credentials"
+ )
+ private int authenticationRefreshCheckSeconds = 60;
Review comment:
It will "disabled by default" in the sense that the current credentials are not expiring as of now.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [pulsar] ivankelly commented on a change in pull request #6074:
PIP-55: Refresh Authentication Credentials
Posted by GitBox <gi...@apache.org>.
ivankelly commented on a change in pull request #6074: PIP-55: Refresh Authentication Credentials
URL: https://github.com/apache/pulsar/pull/6074#discussion_r369978802
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/PulsarChannelInitializer.java
##########
@@ -38,6 +48,11 @@
private final NettySslContextBuilder sslCtxRefresher;
private final ServiceConfiguration brokerConf;
+ private final Cache<SocketAddress, ServerCnx> connections = Caffeine.newBuilder()
Review comment:
nit: Why not Cache<ServerCnx, ServerCnx> and avoid possibly allocating the SocketAddress? We don't care about the keys in any case. Maybe add a comment that the you're using Cache to avoid having to clean stuff up.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [pulsar] rdhabalia commented on a change in pull request #6074:
PIP-55: Refresh Authentication Credentials
Posted by GitBox <gi...@apache.org>.
rdhabalia commented on a change in pull request #6074: PIP-55: Refresh Authentication Credentials
URL: https://github.com/apache/pulsar/pull/6074#discussion_r374859328
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java
##########
@@ -497,8 +523,60 @@ private void doAuthentication(AuthData clientData,
log.debug("[{}] Authentication in progress client by method {}.",
remoteAddress, authMethod);
}
- state = State.Connecting;
- return;
+ return State.Connecting;
+ }
+
+ public void refreshAuthenticationCredentials() {
+ if (getState() != State.Connected || !isActive) {
+ // Connection is either still being established or already closed.
+ return;
+ }
+
+ AuthenticationState authState = this.originalAuthState != null ? originalAuthState : this.authState;
+ if (authState != null && !authState.isExpired()) {
+ // Credentials are still valid. Nothing to do at this point
+ return;
+ }
+
+ if (originalPrincipal != null && originalAuthState == null) {
+ log.info(
+ "[{}] Cannot revalidate user credential when using proxy and not forwarding the credentials. Closing connection",
+ remoteAddress);
+ return;
+ }
+
+ ctx.executor().execute(SafeRun.safeRun(() -> {
+ log.info("[{}] Refreshing authentication credentials", remoteAddress);
+
+ if (!supportsAuthenticationRefresh()) {
+ log.warn("[{}] Closing connection because client doesn't support auth credentials refresh", remoteAddress);
+ ctx.close();
Review comment:
this change will not work for us because we have usecase where application creates large number of producers on one connection and if the client library is not upgraded then it closes the connection and disrupts all producers connection. this application is latency sensitive and we would like to avoid reconnection.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [pulsar] merlimat commented on a change in pull request #6074:
PIP-55: Refresh Authentication Credentials
Posted by GitBox <gi...@apache.org>.
merlimat commented on a change in pull request #6074: PIP-55: Refresh Authentication Credentials
URL: https://github.com/apache/pulsar/pull/6074#discussion_r368105348
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java
##########
@@ -127,6 +127,10 @@
AuthenticationDataSource authenticationData;
AuthenticationProvider authenticationProvider;
AuthenticationState authState;
+ // In case of proxy, if the authentication credentials are forwardable,
+ // it will hold the credentials of the original client
+ AuthenticationState originalAuthState;
+ private boolean pendingAuthChallengeResponse = false;
Review comment:
This variable will be always accessed only the connection IO thread so there won't be any race condition.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [pulsar] ivankelly commented on a change in pull request #6074:
PIP-55: Refresh Authentication Credentials
Posted by GitBox <gi...@apache.org>.
ivankelly commented on a change in pull request #6074: PIP-55: Refresh Authentication Credentials
URL: https://github.com/apache/pulsar/pull/6074#discussion_r369982426
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java
##########
@@ -476,19 +473,42 @@ private void completeConnect(int clientProtoVersion, String clientVersion) {
}
// According to auth result, send newConnected or newAuthChallenge command.
- private void doAuthentication(AuthData clientData,
- int clientProtocolVersion,
- String clientVersion) throws Exception {
+ private State doAuthentication(AuthData clientData,
+ int clientProtocolVersion,
+ String clientVersion) throws Exception {
+
+ // The original auth state can only be set on subsequent auth attempts (and only
+ // in presence of a proxy and if the proxy is forwarding the credentials).
+ // In this case, the re-validation needs to be done against the original client
+ // credentials.
+ boolean useOriginalAuthState = (originalAuthState != null);
+ AuthenticationState authState = useOriginalAuthState ? originalAuthState : this.authState;
+ String authRole = useOriginalAuthState ? originalPrincipal : this.authRole;
AuthData brokerData = authState.authenticate(clientData);
+
// authentication has completed, will send newConnected command.
Review comment:
This comment is now wrong. I think the flow should change a little here, to only call completeConnect if it's the initial auth. There seems to be enough difference in the flows to have them completely separate.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [pulsar] merlimat commented on issue #6074: PIP-55: Refresh
Authentication Credentials
Posted by GitBox <gi...@apache.org>.
merlimat commented on issue #6074: PIP-55: Refresh Authentication Credentials
URL: https://github.com/apache/pulsar/pull/6074#issuecomment-584223523
> @rdhabalia any thoughts on Matteo's last comment?
@sijie I think he's on vacation now. I'll sync-up with him once he's back.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [pulsar] jerrypeng commented on a change in pull request #6074:
PIP-55: Refresh Authentication Credentials
Posted by GitBox <gi...@apache.org>.
jerrypeng commented on a change in pull request #6074: PIP-55: Refresh Authentication Credentials
URL: https://github.com/apache/pulsar/pull/6074#discussion_r367772350
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java
##########
@@ -127,6 +127,10 @@
AuthenticationDataSource authenticationData;
AuthenticationProvider authenticationProvider;
AuthenticationState authState;
+ // In case of proxy, if the authentication credentials are forwardable,
+ // it will hold the credentials of the original client
+ AuthenticationState originalAuthState;
+ private boolean pendingAuthChallengeResponse = false;
Review comment:
I think this needs to be marked volatile?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [pulsar] merlimat commented on a change in pull request #6074:
PIP-55: Refresh Authentication Credentials
Posted by GitBox <gi...@apache.org>.
merlimat commented on a change in pull request #6074: PIP-55: Refresh Authentication Credentials
URL: https://github.com/apache/pulsar/pull/6074#discussion_r370875273
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java
##########
@@ -497,8 +523,60 @@ private void doAuthentication(AuthData clientData,
log.debug("[{}] Authentication in progress client by method {}.",
remoteAddress, authMethod);
}
- state = State.Connecting;
- return;
+ return State.Connecting;
+ }
+
+ public void refreshAuthenticationCredentials() {
+ if (getState() != State.Connected || !isActive) {
+ // Connection is either still being established or already closed.
+ return;
+ }
+
+ AuthenticationState authState = this.originalAuthState != null ? originalAuthState : this.authState;
+ if (authState != null && !authState.isExpired()) {
+ // Credentials are still valid. Nothing to do at this point
+ return;
+ }
+
+ if (originalPrincipal != null && originalAuthState == null) {
+ log.info(
+ "[{}] Cannot revalidate user credential when using proxy and not forwarding the credentials. Closing connection",
+ remoteAddress);
+ return;
+ }
+
+ ctx.executor().execute(SafeRun.safeRun(() -> {
+ log.info("[{}] Refreshing authentication credentials", remoteAddress);
+
+ if (!supportsAuthenticationRefresh()) {
+ log.warn("[{}] Closing connection because client doesn't support auth credentials refresh", remoteAddress);
+ ctx.close();
Review comment:
If we don't close the connection for older clients, it becomes a security loophole.
Also, keep in mind that this is only apply if the credentials are expiring. In that case, a client will typically be reading the credentials each time are needed (eg: from a file or through a supplier function).
If that was not the case, it would have trouble even without this change. (eg: when a broker gets restarted it will not be able to reconnect anymore).
After the connection gets closed, an older client will be anyway able to immediately reconnect and refresh the authentication.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [pulsar] merlimat commented on a change in pull request #6074:
PIP-55: Refresh Authentication Credentials
Posted by GitBox <gi...@apache.org>.
merlimat commented on a change in pull request #6074: PIP-55: Refresh Authentication Credentials
URL: https://github.com/apache/pulsar/pull/6074#discussion_r370850532
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java
##########
@@ -476,19 +473,42 @@ private void completeConnect(int clientProtoVersion, String clientVersion) {
}
// According to auth result, send newConnected or newAuthChallenge command.
- private void doAuthentication(AuthData clientData,
- int clientProtocolVersion,
- String clientVersion) throws Exception {
+ private State doAuthentication(AuthData clientData,
+ int clientProtocolVersion,
+ String clientVersion) throws Exception {
+
+ // The original auth state can only be set on subsequent auth attempts (and only
+ // in presence of a proxy and if the proxy is forwarding the credentials).
+ // In this case, the re-validation needs to be done against the original client
+ // credentials.
+ boolean useOriginalAuthState = (originalAuthState != null);
+ AuthenticationState authState = useOriginalAuthState ? originalAuthState : this.authState;
+ String authRole = useOriginalAuthState ? originalPrincipal : this.authRole;
AuthData brokerData = authState.authenticate(clientData);
+
// authentication has completed, will send newConnected command.
Review comment:
Fixed the comment and tried to make the flow a bit clearer
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [pulsar] merlimat commented on a change in pull request #6074:
PIP-55: Refresh Authentication Credentials
Posted by GitBox <gi...@apache.org>.
merlimat commented on a change in pull request #6074: PIP-55: Refresh Authentication Credentials
URL: https://github.com/apache/pulsar/pull/6074#discussion_r370846331
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/PulsarChannelInitializer.java
##########
@@ -38,6 +48,11 @@
private final NettySslContextBuilder sslCtxRefresher;
private final ServiceConfiguration brokerConf;
+ private final Cache<SocketAddress, ServerCnx> connections = Caffeine.newBuilder()
Review comment:
Added comment
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [pulsar] tuteng commented on issue #6074: PIP-55: Refresh
Authentication Credentials
Posted by GitBox <gi...@apache.org>.
tuteng commented on issue #6074: PIP-55: Refresh Authentication Credentials
URL: https://github.com/apache/pulsar/pull/6074#issuecomment-601993018
Add label release-2.5.1, due to #6178 dependency
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [pulsar] merlimat commented on a change in pull request #6074:
PIP-55: Refresh Authentication Credentials
Posted by GitBox <gi...@apache.org>.
merlimat commented on a change in pull request #6074: PIP-55: Refresh Authentication Credentials
URL: https://github.com/apache/pulsar/pull/6074#discussion_r375081645
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java
##########
@@ -497,8 +523,60 @@ private void doAuthentication(AuthData clientData,
log.debug("[{}] Authentication in progress client by method {}.",
remoteAddress, authMethod);
}
- state = State.Connecting;
- return;
+ return State.Connecting;
+ }
+
+ public void refreshAuthenticationCredentials() {
+ if (getState() != State.Connected || !isActive) {
+ // Connection is either still being established or already closed.
+ return;
+ }
+
+ AuthenticationState authState = this.originalAuthState != null ? originalAuthState : this.authState;
+ if (authState != null && !authState.isExpired()) {
+ // Credentials are still valid. Nothing to do at this point
+ return;
+ }
+
+ if (originalPrincipal != null && originalAuthState == null) {
+ log.info(
+ "[{}] Cannot revalidate user credential when using proxy and not forwarding the credentials. Closing connection",
+ remoteAddress);
+ return;
+ }
+
+ ctx.executor().execute(SafeRun.safeRun(() -> {
+ log.info("[{}] Refreshing authentication credentials", remoteAddress);
+
+ if (!supportsAuthenticationRefresh()) {
+ log.warn("[{}] Closing connection because client doesn't support auth credentials refresh", remoteAddress);
+ ctx.close();
Review comment:
> if the client library is not upgraded then it closes the connection and disrupts all producers connection.
This is only if the credentials are expiring and if the authentication provider enforces that (which right now will only be the token auth provider).
Avoiding to challenge older client defeats the purpose of this feature in that it opens a backdoor to completely avoid the check.
If older clients are a concern, I'd suggest to either:
* not use this feature (or similarly working feature)
* use non-expiring credentials for older clients
* use credentials with long expire time to minimize the number of reconnections
* force clients to upgrade version
I honestly don't see any better solution for that. I'd categorically exclude the "ignore old clients" for the false sense of security and the massive sec issue it opens.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [pulsar] ivankelly commented on a change in pull request #6074:
PIP-55: Refresh Authentication Credentials
Posted by GitBox <gi...@apache.org>.
ivankelly commented on a change in pull request #6074: PIP-55: Refresh Authentication Credentials
URL: https://github.com/apache/pulsar/pull/6074#discussion_r369980020
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/PulsarChannelInitializer.java
##########
@@ -78,6 +97,19 @@ protected void initChannel(SocketChannel ch) throws Exception {
// ServerCnx ends up reading higher number of messages and broker can not throttle the messages by disabling
// auto-read.
ch.pipeline().addLast("flowController", new FlowControlHandler());
- ch.pipeline().addLast("handler", new ServerCnx(pulsar));
+ ServerCnx cnx = new ServerCnx(pulsar);
+ ch.pipeline().addLast("handler", cnx);
+
+ connections.put(ch.remoteAddress(), cnx);
+ }
+
+ private void refreshAuthenticationCredentials() {
+ connections.asMap().values().forEach(cnx -> {
+ try {
+ cnx.refreshAuthenticationCredentials();
+ } catch (Throwable t) {
+ log.warn("[{}] Failed to refresh auth credentials", cnx.getRemoteAddress());
Review comment:
Since you're using Cache to hold the connections, and the lifetime of the entry in connections is based on whether it's been GC'd, this will likely spam the logs. Maybe only log if after throwing, the cnx is still in connected state.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [pulsar] merlimat commented on a change in pull request #6074:
PIP-55: Refresh Authentication Credentials
Posted by GitBox <gi...@apache.org>.
merlimat commented on a change in pull request #6074: PIP-55: Refresh Authentication Credentials
URL: https://github.com/apache/pulsar/pull/6074#discussion_r370847133
##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/PulsarChannelInitializer.java
##########
@@ -78,6 +97,19 @@ protected void initChannel(SocketChannel ch) throws Exception {
// ServerCnx ends up reading higher number of messages and broker can not throttle the messages by disabling
// auto-read.
ch.pipeline().addLast("flowController", new FlowControlHandler());
- ch.pipeline().addLast("handler", new ServerCnx(pulsar));
+ ServerCnx cnx = new ServerCnx(pulsar);
+ ch.pipeline().addLast("handler", cnx);
+
+ connections.put(ch.remoteAddress(), cnx);
+ }
+
+ private void refreshAuthenticationCredentials() {
+ connections.asMap().values().forEach(cnx -> {
+ try {
+ cnx.refreshAuthenticationCredentials();
+ } catch (Throwable t) {
+ log.warn("[{}] Failed to refresh auth credentials", cnx.getRemoteAddress());
Review comment:
When we get the ref to `cnx`, it will be a strong ref to it, so we're not going to loose it during the iteration. Then, inside that method, i'm checking for
```java
if (getState() != State.Connected || !isActive) {
// Connection is either still being established or already closed.
return;
}
```
to avoid getting errors on a connections that's already gone
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [pulsar] sijie commented on issue #6074: PIP-55: Refresh
Authentication Credentials
Posted by GitBox <gi...@apache.org>.
sijie commented on issue #6074: PIP-55: Refresh Authentication Credentials
URL: https://github.com/apache/pulsar/pull/6074#issuecomment-575476647
@jiazhai can you review this change since you were implementing SASL authentication before?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services