Re: [OAuth2] Infrastructure for tracking token expiry time - Mailing list pgsql-hackers

From VASUKI M
Subject Re: [OAuth2] Infrastructure for tracking token expiry time
Date
Msg-id CAE2r8H5QAng_rRrkVmGbLuQSgbMz94tpOOOdJKeuHj=go0nXqg@mail.gmail.com
Whole thread
In response to [OAuth2] Infrastructure for tracking token expiry time  (Ajit Awekar <ajitpostgres@gmail.com>)
Responses Re: [OAuth2] Infrastructure for tracking token expiry time
List pgsql-hackers
On Mon, Feb 16, 2026 at 3:44 PM Ajit Awekar <ajitpostgres@gmail.com> wrote:
Hi Hackers,

Currently, during OAuth2 authentication,  the ValidatorModuleResult structure allows a validator(extension) to return the authentication status and the authn_id.
However, we ignore the token expiry time (exp claim).

Once a token is validated, the backend has no record of when that token actually expires. A session can remain open indefinitely even if the underlying access token has expired shortly after the connection was established.

This patch adds the infrastructure to capture and store this expiration timestamp within the backend session state. It does not implement an enforcement policy (such as auto-termination).

Hi Ajit,

Thanks for working on this. Storing the token expiry in the backend session state makes sense as groundwork for future enforcement.

I had a couple of questions while reading the patch.

First, is Port always zero-initialized? If not, we might want to explicitly initialize the new expiry field to a known value. Right now it looks like we’re relying on zero to mean “not provided”, but since TimestampTz value 0 is a valid timestamp (Postgres epoch), I’m wondering whether it would be clearer to use an explicit invalid/sentinel value instead.

Also, in the case where the validator returns an expiry that is already in the past, should we reject the authentication immediately? Or is that expected to be fully handled inside the validator module?

Finally, do you have a particular enforcement model in mind for follow-up work (e.g., check at statement start, transaction boundaries, or via some timeout mechanism)? It would help to understand how you see this being used.

The change itself looks straightforward, just trying to clarify the intended semantics.

Best regards,
Vasuki M
C-DAC,Chennai. 

pgsql-hackers by date:

Previous
From: Alexandre Felipe
Date:
Subject: Re: index prefetching
Next
From: Nazir Bilal Yavuz
Date:
Subject: Re: Improve docs syntax checking and enable it in the meson build