pgsql: Remove explicit user option from exec_sql#2050
pgsql: Remove explicit user option from exec_sql#2050okamoto-sansan wants to merge 1 commit intoClusterLabs:mainfrom
Conversation
|
Can one of the admins check and authorise this run please: https://ci.kronosnet.org/job/resource-agents/job/resource-agents-pipeline/job/PR-2050/1/input |
|
I will look into adding a password parameter for the 2nd user, and make sure it also works for current setups. |
|
Thanks for your consideration, my understanding is that the pgdba parameter is assumed to be an OS user, and only if monitor_user is not specified is it also used as a DB user. resource-agents/heartbeat/pgsql Line 186 in fefb54b I was of the opinion that pgdba should exist only as an OS user, but considering the existing RA behavior and many usage scenarios, I think the best suggestion is to assume that pgdba is also used as a DB user name (when monitor_user is not specified) and to support password authentication in that case. I reconsider that the best suggestion is to support password authentication in that case. You are free to close this PR, Thank you. |
What i did
Removed the direct usage of -U $OCF_RESKEY_pgdba within the
exec_sql() function for specifying the psql user.
This change ensures that exec_sql() consistently uses the database
user defined in the global $psql_options. It simplifies user
management by relying on a single source for psql connection
parameters, including credentials, for operations invoked via
this function.
Problem Description
When the monitor_user attribute is configured in the pgsql RA, the main() function exports PGUSER (set to $OCF_RESKEY_monitor_user) and PGPASSWORD (set to $OCF_RESKEY_monitor_password) as global environment variables during resource startup.
The psql_options variable is set as follows:
During the PostgreSQL startup sequence initiated by the RA (pgsql_real_start() → pgsql_real_monitor()), the exec_sql() function is called to check the database's recovery status (by running SELECT pg_is_in_recovery()).
The exec_sql() function, as seen in heartbeat/pgsql#L534, constructs a psql command that explicitly includes the -U $OCF_RESKEY_pgdba option:
This leads to an authentication issue due to the interaction of psql command-line options and environment variables:
Consequently, psql attempts to authenticate as the $OCF_RESKEY_pgdba user but uses the password intended for $OCF_RESKEY_monitor_user. If these passwords differ, the authentication fails. This prevents the RA from obtaining the recovery status, ultimately causing the pgsql resource agent to report an error.
The effective psql invocation attempts the following:
Connect as user: $OCF_RESKEY_pgdba
Using password: Value of PGPASSWORD (which is $OCF_RESKEY_monitor_password)
If the monitor_user's password does not match the pgdba's password, the connection fails, and the RA cannot determine the recovery status, as shown in the logs (see also heartbeat/pgsql#L978):
If you use the same password for monitor_password and pgdba(postgres), you can get the recovery status without any problem.
Enviroment