Skip to content

Commit 67571e0

Browse files
committed
pgwire: decouple jwt authentication and authorization logic
Previously, the logic for JWT authorization (extracting group claims and synchronizing roles) was located within the `Authenticator` behavior. This was a necessary design when the JWT token was only exchanged from the `AuthConn` within the authenticator. This was inadequate because it bundled authentication and authorization logic, violating the separation of concerns intended by the `AuthBehaviors` framework and creating an inconsistency with other methods like `AuthLDAP`. A recent change (#149415) made the token available via closure capture to all behaviors, removing the original constraint and making this refactoring possible. To address this, this patch decouples the logic. The `Authenticator` is now solely responsible for validating the token (authentication). The authorization logic has been moved to a new `Authorizer` behavior, which aligns the implementation with the framework's design and improves code clarity and maintainability. Fixes: #150720 Release note: None
1 parent 511c558 commit 67571e0

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

pkg/sql/pgwire/auth_methods.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,10 @@ func authJwtToken(
916916
return authError
917917
}
918918

919+
return nil
920+
})
921+
922+
b.SetAuthorizer(func(ctx context.Context, systemIdentity string, clientConnection bool) error {
919923
// Ask the CCL verifier for groups (nil slice means feature disabled).
920924
groups, err := jwtVerifier.ExtractGroups(ctx, execCfg.Settings, []byte(token))
921925
if err != nil {
@@ -959,6 +963,7 @@ func authJwtToken(
959963

960964
return nil
961965
})
966+
962967
return b, nil
963968
}
964969

0 commit comments

Comments
 (0)