Skip to content

Commit bd5d634

Browse files
committed
pgwire,provisioning: align JWT auth logging and telemetry with LDAP
Previously, the JWT authentication flow lacked specific telemetry counters for its provisioning process and had less verbose logging compared to the LDAP authentication flow. This was inadequate because it created an observability gap, making it harder to monitor and debug JWT-specific authentication and provisioning steps compared to the more mature LDAP implementation. To address this, this patch introduces JWT-specific telemetry counters for provisioning (`begin`, `success`, `enable`) and adds more detailed logging messages at each stage of the `authJwtToken` flow (provisioning, authentication, and authorization). The new logs and metrics are modeled directly after the existing implementation for LDAP, ensuring a consistent operational experience for both enterprise authentication methods. Release note: None
1 parent 67571e0 commit bd5d634

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

pkg/security/provisioning/settings.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,28 @@ const (
2424

2525
baseCounterPrefix = "auth.provisioning."
2626
ldapCounterPrefix = baseCounterPrefix + "ldap."
27+
jwtCounterPrefix = baseCounterPrefix + "jwt."
2728

2829
beginLDAPProvisionCounterName = ldapCounterPrefix + "begin"
2930
provisionLDAPSuccessCounterName = ldapCounterPrefix + "success"
3031
enableLDAPProvisionCounterName = ldapCounterPrefix + "enable"
3132

33+
beginJWTProvisionCounterName = jwtCounterPrefix + "begin"
34+
provisionJWTSuccessCounterName = jwtCounterPrefix + "success"
35+
enableJWTProvisionCounterName = jwtCounterPrefix + "enable"
36+
3237
provisionedUserLoginSuccessCounterName = baseCounterPrefix + "login_success"
3338
)
3439

3540
var (
36-
BeginLDAPProvisionUseCounter = telemetry.GetCounterOnce(beginLDAPProvisionCounterName)
37-
ProvisionLDAPSuccessCounter = telemetry.GetCounterOnce(provisionLDAPSuccessCounterName)
38-
enableLDAPProvisionCounter = telemetry.GetCounterOnce(enableLDAPProvisionCounterName)
41+
BeginLDAPProvisionUseCounter = telemetry.GetCounterOnce(beginLDAPProvisionCounterName)
42+
ProvisionLDAPSuccessCounter = telemetry.GetCounterOnce(provisionLDAPSuccessCounterName)
43+
enableLDAPProvisionCounter = telemetry.GetCounterOnce(enableLDAPProvisionCounterName)
44+
45+
BeginJWTProvisionUseCounter = telemetry.GetCounterOnce(beginJWTProvisionCounterName)
46+
ProvisionJWTSuccessCounter = telemetry.GetCounterOnce(provisionJWTSuccessCounterName)
47+
enableJWTProvisionCounter = telemetry.GetCounterOnce(enableJWTProvisionCounterName)
48+
3949
ProvisionedUserLoginSuccessCounter = telemetry.GetCounterOnce(provisionedUserLoginSuccessCounterName)
4050
)
4151

@@ -99,5 +109,10 @@ func ClusterProvisioningConfig(settings *cluster.Settings) UserProvisioningConfi
99109
telemetry.Inc(enableLDAPProvisionCounter)
100110
}
101111
})
112+
jwtProvisioningEnabled.SetOnChange(&settings.SV, func(_ context.Context) {
113+
if jwtProvisioningEnabled.Get(&settings.SV) {
114+
telemetry.Inc(enableJWTProvisionCounter)
115+
}
116+
})
102117
return clusterProvisioningConfig{settings: settings}
103118
}

pkg/sql/pgwire/auth_methods.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,9 @@ func authJwtToken(
860860
}
861861

862862
b.SetProvisioner(func(ctx context.Context) error {
863+
c.LogAuthInfof(ctx, "Starting JWT provisioning; attempting to verify token")
864+
telemetry.Inc(provisioning.BeginJWTProvisionUseCounter)
865+
863866
if validationErr != nil {
864867
return validationErr
865868
}
@@ -893,6 +896,8 @@ func authJwtToken(
893896
c.LogAuthFailed(ctx, eventpb.AuthFailReason_PROVISIONING_ERROR, err)
894897
return err
895898
}
899+
900+
telemetry.Inc(provisioning.ProvisionJWTSuccessCounter)
896901
return nil
897902
})
898903

@@ -905,6 +910,8 @@ func authJwtToken(
905910
return err
906911
}
907912

913+
c.LogAuthInfof(ctx, "JWT Provided; attempting to validate token for authentication")
914+
908915
// Validate the token and, if there's an error, log it with the correct reason.
909916
if detailedErrors, authError := jwtVerifier.ValidateJWTLogin(
910917
sctx, execCfg.Settings, user, []byte(token), identMap); authError != nil {
@@ -920,6 +927,8 @@ func authJwtToken(
920927
})
921928

922929
b.SetAuthorizer(func(ctx context.Context, systemIdentity string, clientConnection bool) error {
930+
c.LogAuthInfof(ctx, "JWT authentication succeeded; attempting authorization")
931+
923932
// Ask the CCL verifier for groups (nil slice means feature disabled).
924933
groups, err := jwtVerifier.ExtractGroups(ctx, execCfg.Settings, []byte(token))
925934
if err != nil {

0 commit comments

Comments
 (0)