Skip to content

Simplify authentication state management in Broker's ServerCnx class when networking with proxy #19332

Open

Description

@michaeljmarshall

Search before asking

  • I searched in the issues and found nothing similar.

Motivation

The current management is confusing and is not working correctly. We should improve it.

TL;DR: The values for authState and authenticationData are ambiguous and can have different meanings depending on configuration and the lifecycle of the connection.

Current State of Client/Proxy/Broker Protocol Interaction

Here are the current cases based on proxy configuration:

A. Proxy sends connect command with only originalPrincipal (Update: this type of connection is not eligible for refreshing authentication data)
B. Proxy sends connect command with originalPrincipal and originalAuthData

Here are the two kinds of connections a proxy opens with the broker:

  1. ProxyLookupRequests - proxy handles lookup requests.
  2. ProxyConnectionToBroker - proxy handles all of other requests.

In both states, the proxy first connects with the above connect command.

In case 1, the proxy always translates requests, and as such, AuthChallenge commands sent from broker to proxy are handled by the proxy. In case A, the proxy replies with its own AuthData. In case B, the proxy forwards the AuthChallenge to the client, gets the response, and forwards it to the broker.

In case 2, after the initial connection is established (and authenticated), the proxy forwards bytes between client and broker without inspection. As such, for both cases A and B, all AuthChallenge commands are sent to the client.

The problem

The broker's ServerCnx class has the following variables:

In case A, the broker tracks variables named authState, authRole, authenticationData, and originalPrincipal. The only role that is meant for the client is the originalPrincipal. However, that is not how it actually works. In case 1, authState, authRole, authenticationData are all proxy values for the lifetime of the handler. In case 2, authState, authRole, authenticationData start out as proxy values but upon auth refresh, the values are updated to use the client's values. In order to get around some of the potential issues, we have the following code:

boolean useOriginalAuthState = (originalAuthState != null);
AuthenticationState authState = useOriginalAuthState ? originalAuthState : this.authState;
String authRole = useOriginalAuthState ? originalPrincipal : this.authRole;

However, this makes it hard to reason about the actual state because we're somewhat dependent on whether or not a refresh has taken place yet.

In case B, it is slightly more confusing. Case B2 is the same as case A2. However, case 1A started out with the proxy not forwarding auth data, but when the broker refreshes the auth data, the AuthChallenge is sent to the client, so now the auth data is sent to the broker anyway. That condition isn't possible. Note that B1 is handled by the proxy forwarding the auth challenge to the client.

Consequences

The primary issues present come though when doing authorization.

Other problems

The AuthResponse command does not indicate which entity supplied the auth data. As such, we don't actually know if we should update the "original" auth data or the proxy's auth data.

The current design does not allow for multistage authentication in certain cases.

Solution

My proposed solution is to remove the originalAuthState and originalAuthData variables. We can still authenticate both the client's and the proxy's auth data, but we don't need to make it look like we're actively tracking the state for both the proxy and the client.

As a result, we'll be able to simplify the authorization logic.

Alternatives

Update the protocol to let make it clearer who's AuthData we're receiving.

Anything else?

No response

Are you willing to submit a PR?

  • I'm willing to submit a PR!

Activity

  1. added
    type/enhancement
    on Jan 26, 2023
  2. michaeljmarshall commented on Feb 3, 2023

    @michaeljmarshall
    MemberAuthor

    While working on #19409 and 6a66c61, I came across some concrete examples of how we pass mismatched authentication information to the authorization provider. This will not affect the normal authorization provider, but it should be fixed to make custom providers work.

  3. michaeljmarshall commented on Feb 5, 2023

    @michaeljmarshall
    MemberAuthor

    Another example: when the proxy forwards the AuthResponse here, it is updating the authState, not the originalAuthState.

    ByteBuf cmd =
    Commands.newAuthResponse(clientAuthMethod, clientData, protocolVersion, clientVersion);

  4. michaeljmarshall commented on Feb 15, 2023

    @michaeljmarshall
    MemberAuthor

    A. Proxy sends connect command with only originalPrincipal

    I learned while working on #19506 that we do not actually support refreshing authentication for this case. That greatly simplifies the cases I outlined at the start of this issue.

    The remaining issues:

  5. github-actions commented on Mar 18, 2023

    @github-actions

    The issue had no activity for 30 days, mark with Stale label.

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

    Staletype/enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions