-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sql,pgwire,server: factor the password expiry code
To understand this commit, it is perhaps useful to remember that password credentials, in Postgres's SQL dialect, have their own expiration timestamp, set via the VALID UNTIL role option. The timestamp is attached to the password, not the user account, such that a user can still log in using a separate authentication method even when their password is expired. Additionally, it is perhaps useful to understand that throughout the authentication stack, we distinguish the phase where we determine whether a principal *exists* and is allowed to log in (i.e. it has the LOGIN privilege); and the phase where we load its password credentials from storage (or from an in-RAM cache). In particular, we are keen to skip the loading of the password credentials in the case where the client is authenticating using another method than passwords (for example TLS client certs, which is still pretty common). In this context, this commit performs two changes. The first change is an API cleanup. Prior to this commit, we were loading the password expiration timestamp in the first phase (checking that the principal exists), rather than the second phase (loading the credentials). This was a misdesign because, as explained above, the expiry timestamp is a property of the password, and thus needs not be looked at when passwords are not used. We fix this in this commit by making the expiration timestamp part of the second phase, as it should have been from the start. The second change in this commit is a reduction of security risk. Prior to this commit, the password expiration timestamp was checked (compared to the current time) again and again in each of the call points for the password retrieval function. It was the responsibility of each caller to perform this check. This constituted a security risk because a new caller could forget to add the expiry check and bypass the expiration mechanism entirely. We fix this by performing the expiry validation in a central location, in the common function that retrieves the credentials from storage (or cache). If the password is expired, the function also hides the password hash by returning the new "password missing" pseudo-hash, so that the caller cannot any more mistakenly attempt to validate a password despite the expiration. Release note: None
- Loading branch information
Showing
6 changed files
with
61 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters