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

ADR 019 password rotation #725

Merged

Conversation

RichardIrons-neo4j
Copy link
Contributor

@RichardIrons-neo4j RichardIrons-neo4j commented Aug 15, 2023

This PR updates the preview feature "re-auth" significantly. The changes allow for catering to a wider range of use cases including simple password rotation.

As part of this PR, all auth-related namespaces have been moved to preview - previously some did not have this, although the classes therein would not have been usable.

Since this is a preview feature all changes here are breaking changes.

The OnTokenExpiredAsync method in the IAuthTokenManager interface was removed, and a new HandleSecurityExceptionAsync method was added in its place.

The ExpirationBased method in AuthTokenManagers was renamed to Bearer, and a new Basic method was added to cater for password rotation.

Copy link
Contributor

@AndyHeap-NeoTech AndyHeap-NeoTech left a comment

Choose a reason for hiding this comment

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

I had one question about handling a potential null token. All looks good to me with nothing obvious standing out.

// The token has changed or the connection needs to re-authenticate but can use the same credentials.
if (AuthorizationStatus == AuthorizationStatus.AuthorizationExpired || !token.Equals(AuthToken))
var authExpired = AuthorizationStatus == AuthorizationStatus.AuthorizationExpired;
if (authExpired || !token.Equals(AuthToken))
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a situation here where the code would need to handle a null token being supplied from the AuthTokenManager. Previous code threw an exception in that case (see line 354 for conditional on null check).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a null check.

}

if (exception is AuthorizationException)
{
// if an auth exception occured the pool member, all connections in the pool that are using that token
// should be closed. This is because the token is now invalid and all connections using it will fail.
foreach (var conn in _inUseConnections)
Copy link
Contributor

Choose a reason for hiding this comment

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

do we care about setting it for idle connections, _inUseConnections are connections that another session or transaction currently has borrowed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it's right to let those connections fail the next time they're attempted to be used?

Copy link
Contributor

Choose a reason for hiding this comment

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

why do we want idle connections to lazily discover the auth token is expired but set in use connections as expired?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, thinking about it, you're right, let me alter that.

@thelonelyvulpes thelonelyvulpes self-requested a review August 22, 2023 09:41
@RichardIrons-neo4j RichardIrons-neo4j marked this pull request as ready for review August 22, 2023 11:30
@RichardIrons-neo4j RichardIrons-neo4j merged commit 6f36b08 into neo4j:5.0 Aug 22, 2023
Copy link
Member

@robsdedude robsdedude left a comment

Choose a reason for hiding this comment

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

I'm a bit late to the party, but please note that the TestKit tests for this feature introduced a new feature flag API_RETRYABLE_EXCEPTION = "Feature:API:RetryableExceptions". For better test coverage, I highly recommend implementing it in the backend.

RichardIrons-neo4j added a commit to RichardIrons-neo4j/neo4j-dotnet-driver that referenced this pull request Sep 25, 2023
commit 7b8ef91
Author: Richard Irons <[email protected]>
Date:   Thu Aug 31 11:58:24 2023 +0100

    Version bump (neo4j#727)

commit 6f36b08
Author: Richard Irons <[email protected]>
Date:   Tue Aug 22 12:31:10 2023 +0100

    ADR 019 password rotation (neo4j#725)

    This PR updates the preview feature "re-auth" significantly. The changes allow for catering to a wider range of use cases including simple password rotation.

    As part of this PR, all auth-related namespaces have been moved to preview - previously some did not have this, although the classes therein would not have been usable.

    Since this is a preview feature all changes here are breaking changes.

    The OnTokenExpiredAsync method in the IAuthTokenManager interface was removed, and a new HandleSecurityExceptionAsync method was added in its place.

    The ExpirationBased method in AuthTokenManagers was renamed to Bearer, and a new Basic method was added to cater for password rotation.

    ---------

    Co-authored-by: grant lodge <[email protected]>

commit 7c93291
Author: grant lodge <[email protected]>
Date:   Fri Aug 18 15:49:18 2023 +0100

    Implement pipelined begin for executable query (neo4j#724)

    * Implement pipelined begin

    * Add unit tests

commit d024d70
Author: grant lodge <[email protected]>
Date:   Wed Jul 26 14:53:47 2023 +0100

    [5.11] Zoned date time fixes (neo4j#715)

    Fixes for ZonedDateTime.
    * Introduce Ambiguous bool property, Creating ZonedDateTime with out a datetime kind, or using a datetime kind local with a named Zone:Zone.of(string), meant we could create an ambiguous date time.
    * Introduce ZonedDateTime.AmbiguityReason enum flags type.
    * Introduce Reason AmbiguityReason property for ZonedDateTimes, to allow users to see why a value is considered ambiguous.
    * Introduce UtcSeconds long property which is the understood monotonic timestamp from unix epoch in UTC.
    * Fix ZonedDateTime lazily parsing when returned from a query, now it is parsed immediately.
    * Fix ZonedDateTime not supporting values outside of range of BCL Date Types
    * Add EpochTicks Property, and constructor which can be used for easy interop with nodatime's Instant
@RichardIrons-neo4j RichardIrons-neo4j deleted the adr-019-password-rotation branch October 18, 2023 12:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants