1: f36e6becc34 ! 1: a9a507604c5 oauth: Let validators provide failure DETAILs @@ Commit message Reported-by: Álvaro Herrera Reported-by: Zsolt Parragi + Reviewed-by: Chao Li + Reviewed-by: Daniel Gustafsson + Reviewed-by: Zsolt Parragi Discussion: https://postgr.es/m/202601241015.y5uvxd7oxnfs%40alvherre.pgsql - Discussion: TODO ## doc/src/sgml/oauth-validators.sgml ## @@ @@ doc/src/sgml/oauth-validators.sgml - Modules may use the same logging -+ To simply log the reason for a validation failure, validators may set -+ the freeform error_detail field during the -+ . This is printed only -+ to the server log, as part of the final authentication failure message, -+ and it is not shared with the client. ++ To simply log the reason for a validation failure, modules may set the ++ freeform error_detail field during the ++ validate callback. ++ ( has guidelines for writing good ++ DETAIL messages.) error_detail ++ is printed only to the server log, as part of the final authentication ++ failure message, and it is not shared with the client. + + + Modules may also use the same logging @@ src/backend/libpq/auth-oauth.c: struct oauth_ctx /* Constants seen in an OAUTHBEARER client initial response. */ #define KVSEP 0x01 /* separator byte for key/value pairs */ @@ src/backend/libpq/auth-oauth.c: oauth_exchange(void *opaq, const char *input, int inputlen, - errmsg("malformed OAUTHBEARER message"), - errdetail("Message contains additional data after the final terminator.")); - -- if (!validate(ctx->port, auth)) -+ if (!validate(ctx->port, auth, logdetail)) + ctx->state = OAUTH_STATE_ERROR_DISCOVERY; + status = PG_SASL_EXCHANGE_CONTINUE; + } +- else if (!validate(ctx->port, auth)) ++ else if (!validate(ctx->port, auth, logdetail)) { generate_error_response(ctx, output, outputlen); @@ src/backend/libpq/auth.c: ClientAuthentication(Port *port) status = STATUS_OK; break; case uaOAuth: -- status = CheckSASLAuth(&pg_be_oauth_mech, port, NULL, NULL); -+ status = CheckSASLAuth(&pg_be_oauth_mech, port, NULL, &logdetail); +- status = CheckSASLAuth(&pg_be_oauth_mech, port, NULL, NULL, ++ status = CheckSASLAuth(&pg_be_oauth_mech, port, NULL, &logdetail, + &abandoned); break; } - ## src/test/modules/oauth_validator/t/001_server.pl ## @@ src/test/modules/oauth_validator/t/001_server.pl: $node->connect_fails(