Skip to content

Address thread safety concerns in ServerCnx for auth related data #19431

Description

@michaeljmarshall

Search before asking

  • I searched in the issues and found nothing similar.

Motivation

There is access to auth related data that is not obviously thread safe.

Here are two methods called by other threads:

private CompletableFuture<Boolean> isTopicOperationAllowed(TopicName topicName, String subscriptionName,
TopicOperation operation) {
if (service.isAuthorizationEnabled()) {
AuthenticationDataSource authDataSource =
new AuthenticationDataSubscription(authenticationData, subscriptionName);
AuthenticationDataSource originalAuthDataSource = null;
if (originalAuthData != null) {
originalAuthDataSource = new AuthenticationDataSubscription(originalAuthData, subscriptionName);
}
return isTopicOperationAllowed(topicName, operation, authDataSource, originalAuthDataSource);
} else {
return CompletableFuture.completedFuture(true);
}
}

public void refreshAuthenticationCredentials() {
AuthenticationState authState = this.originalAuthState != null ? originalAuthState : this.authState;
if (authState == null) {
// Authentication is disabled or there's no local state to refresh
return;
} else if (getState() != State.Connected || !isActive) {
// Connection is either still being established or already closed.
return;
} else if (!authState.isExpired()) {
// Credentials are still valid. Nothing to do at this point
return;
} else if (originalPrincipal != null && originalAuthState == null) {
log.info(
"[{}] Cannot revalidate user credential when using proxy and"
+ " not forwarding the credentials. Closing connection",
remoteAddress);
return;
}

Solution

It would be better to update the paradigm to ensure correct access of the data. I think we should avoid making the variables volatile and instead make them only accessed from the netty event loop.

Alternatives

Make the variables volatile.

Anything else?

No response

Are you willing to submit a PR?

  • I'm willing to submit a PR!

Activity

  1. added
    type/enhancement
    on Feb 5, 2023
  2. sunheyi6 commented on Feb 7, 2023

    @sunheyi6
    Contributor

    @michaeljmarshall the first method that causes thread insecurity should be this code

    CompletableFuture<Boolean> isAuthorizedFuture = isTopicOperationAllowed(
    topicName,
    subscriptionName,
    TopicOperation.CONSUME
    );

    Both methods do cause thread safety issues

  3. added 6 commits that reference this issue on Feb 14, 2023
    c4c1744
    e1d9941
    1ba48c0
    0d69ead
    f8de0fb
    2ff4848
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/brokertype/enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions