gpt4 book ai didi

Ruby -> PostgreSQL 连接 pg_hba.conf 设置为 "ident sameuser"而不是 "trust"

转载 作者:行者123 更新时间:2023-11-29 14:24:05 25 4
gpt4 key购买 nike

我已经尝试了所有我能想到的谷歌搜索词,但我发现的所有内容都在说要在 pg_hba.conf 中将本地连接设置为 trust(似乎是如果本地任何人都可以像他们所说的那样登录和访问数据库,则存在安全漏洞)。

pg_hba.conf 中,本地连接设置为 ident sameuser。该脚本应该作为该用户运行,但我收到此错误:

A database error occurred: 
fe_sendauth: no password supplied

Ruby 代码非常通用:

conn_str = "DBI:pg:dbname=mydb;host=" + localhost
@connection = DBI.connect(conn_str, "myuser", '')

我可以通过创建一个 ~/.pgpass 文件来解决这个问题 as described here ,但我更希望能够让用户登录并访问数据库服务器。

有人能够让 PostgreSQL 的 ident sameuser 为本地脚本正常工作吗?

最佳答案

我怀疑是这样的:

In pg_hba.conf local connections are set to ident sameuser. The script should be running as that user, but I get this error [...]

conn_str = "DBI:pg:dbname=mydb;host=" + localhost
@connection = DBI.connect(conn_str, "myuser", '')

请注意“本地”连接与“本地主机”连接不同。只要您在连接 URL 中提到“localhost”,就会创建一个 TCP/IP 套接字。这些由`pg_hba.conf 中的host 规则管理。

要使用真正的“本地”连接,必须使用 Unix 域套接字。但我不知道 Ruby DBI 连接器是否支持它们。

关于Ruby -> PostgreSQL 连接 pg_hba.conf 设置为 "ident sameuser"而不是 "trust",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8948413/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com