python - How do I connect to a local postgres database without password from a script within Apache -
i have python script should load data postgres when post request sent apache webserver. in script system user (dbuser) used connect database (which works fine psql). script cannot connect when executed within apache, returning following error:
peer authentication failed user dbuser
is there way allow script connect without providing user password?
the solution i've found uses ident authentication user maps.
the first thing notice that, although username provided in script, when connecting via apache, user used peer authentication (which fails, requiring password). however, system user requesting access postgresql 1 running apache (namely www-data), enabling configure user map, allowing authenticate server system user (thus leveraging ident authentication). here follows configuration files content:
in pg_ident.conf configure user map:
# mapname system-username pg-username web www-data dbuser web dbuser dbuser
in pg_hba.conf add map option local peer authentication:
# "local" unix domain socket connections # type database user address method local peer map=web
after reloading server, script can access database if executed directly the user "dbuser", without need password.
Comments
Post a Comment