Allow larger packets during GSSAPI authentication exchange.
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 30 May 2025 16:55:15 +0000 (12:55 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 30 May 2025 16:55:15 +0000 (12:55 -0400)
commitd98cefe1143eea010048dc1525a51b77e11b2935
tree664a5a497d870c0e47fb654c308d42177ccb7f71
parent961553daf5d6087b175aa98f3031a46a8666cecf
Allow larger packets during GSSAPI authentication exchange.

Our GSSAPI code only allows packet sizes up to 16kB.  However it
emerges that during authentication, larger packets might be needed;
various authorities suggest 48kB or 64kB as the maximum packet size.
This limitation caused login failure for AD users who belong to many
AD groups.  To add insult to injury, we gave an unintelligible error
message, typically "GSSAPI context establishment error: The routine
must be called again to complete its function: Unknown error".

As noted in code comments, the 16kB packet limit is effectively a
protocol constant once we are doing normal data transmission: the
GSSAPI code splits the data stream at those points, and if we change
the limit then we will have cross-version compatibility problems
due to the receiver's buffer being too small in some combinations.
However, during the authentication exchange the packet sizes are
not determined by us, but by the underlying GSSAPI library.  So we
might as well just try to send what the library tells us to.
An unpatched recipient will fail on a packet larger than 16kB,
but that's not worse than the sender failing without even trying.
So this doesn't introduce any meaningful compatibility problem.

We still need a buffer size limit, but we can easily make it be
64kB rather than 16kB until transport negotiation is complete.
(Larger values were discussed, but don't seem likely to add
anything.)

Reported-by: Chris Gooch <cgooch@bamfunds.com>
Fix-suggested-by: Jacob Champion <jacob.champion@enterprisedb.com>
Author: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Jacob Champion <jacob.champion@enterprisedb.com>
Discussion: https://postgr.es/m/DS0PR22MB5971A9C8A3F44BCC6293C4DABE99A@DS0PR22MB5971.namprd22.prod.outlook.com
Backpatch-through: 13
src/backend/libpq/be-secure-gssapi.c
src/interfaces/libpq/fe-secure-gssapi.c