簡體   English   中英

如果指定了 dbi-resource-id,則使用 IAM 角色的 AWS RDS PostgreSQL 連接不起作用

[英]AWS RDS PostgreSQL connection using IAM Role is not working if dbi-resource-id specified

我正在嘗試使用 IAM 憑證向 IAM 用戶授予對 AWS RDS PostgreSQL 的訪問權限,但如果在 IAM 策略中指定了DbiResourceId ,則出現錯誤PAM authentication failed for user
1. 我按照文檔中的描述創建了 IAM 策略。

{
   "Version": "2012-10-17",
   "Statement": [
      {
         "Effect": "Allow",
         "Action": [
             "rds-db:connect"
         ],
         "Resource": [
             "arn:aws:rds-db:us-west-2:<My_account_id>:dbuser:<My_DbiResourceId>/readwrite_user"
         ]
      }
   ]
}

2.創建數據庫用戶:

CREATE USER readwrite_user WITH LOGIN;
GRANT rds_iam TO readwrite_user;
GRANT CONNECT ON DATABASE database_iam_test TO readwrite_user;

3.嘗試連接

export PGPASSWORD="$(aws rds generate-db-auth-token --hostname $RDSHOST --port 5432 --region $REGION --username $DBUSERNAME)"
psql -h $RDSHOST -p 5432 "dbname=database_iam_test user=$DBUSERNAME sslrootcert=./rds-combined-ca-bundle.pem sslmode=verify-ca"

在這種情況下我有錯誤:

psql: error: could not connect to server: FATAL:  PAM authentication failed for user "readwrite_user"

但是,如果我使用 * 而不是 DbiResourceId — 它正在運行,那么:此策略正在運行:

 {
       "Version": "2012-10-17",
       "Statement": [
          {
             "Effect": "Allow",
             "Action": [
                 "rds-db:connect"
             ],
             "Resource": [
                 "arn:aws:rds-db:us-west-2:<My_account_id>:dbuser:*/readwrite_user"
             ]
          }
       ]
    }

我只有一個數據庫資源,而且我確信我使用了正確的 DbiResourceId,它在我的設置中由命令返回:

aws rds describe-db-instances --query "DBInstances[*].[DBInstanceIdentifier,DbiResourceId]" --region $REGION

誰能解釋為什么在這種情況下指定DbiResourceId會導致錯誤?

我正在嘗試使用 IAM 憑證授予 IAM 用戶對 AWS RDS PostgreSQL 的訪問權限,如果在 IAM 策略中指定了DbiResourceId ,則PAM authentication failed for user
1. 我按照文檔中的描述創建了 IAM 策略。

{
   "Version": "2012-10-17",
   "Statement": [
      {
         "Effect": "Allow",
         "Action": [
             "rds-db:connect"
         ],
         "Resource": [
             "arn:aws:rds-db:us-west-2:<My_account_id>:dbuser:<My_DbiResourceId>/readwrite_user"
         ]
      }
   ]
}

2.創建數據庫用戶:

CREATE USER readwrite_user WITH LOGIN;
GRANT rds_iam TO readwrite_user;
GRANT CONNECT ON DATABASE database_iam_test TO readwrite_user;

3.嘗試連接

export PGPASSWORD="$(aws rds generate-db-auth-token --hostname $RDSHOST --port 5432 --region $REGION --username $DBUSERNAME)"
psql -h $RDSHOST -p 5432 "dbname=database_iam_test user=$DBUSERNAME sslrootcert=./rds-combined-ca-bundle.pem sslmode=verify-ca"

在這種情況下我有錯誤:

psql: error: could not connect to server: FATAL:  PAM authentication failed for user "readwrite_user"

但是如果我使用 * 而不是 DbiResourceId - 它正在工作,所以:這個策略正在工作:

 {
       "Version": "2012-10-17",
       "Statement": [
          {
             "Effect": "Allow",
             "Action": [
                 "rds-db:connect"
             ],
             "Resource": [
                 "arn:aws:rds-db:us-west-2:<My_account_id>:dbuser:*/readwrite_user"
             ]
          }
       ]
    }

我只有一個數據庫資源,我確定我使用了正確的 DbiResourceId,它在我的設置中並由命令返回:

aws rds describe-db-instances --query "DBInstances[*].[DBInstanceIdentifier,DbiResourceId]" --region $REGION

誰能解釋為什么在這種情況下指定DbiResourceId會導致錯誤?

只是為了澄清@vadim-yangunaev 的回答——這是resource_id而不是cluster_id ,這有點令人困惑。 出於某種原因,我腦子里想着文檔說集群 ID,而實際上它正在尋找資源 ID。 事后看來很明顯,但我很少需要使用資源 ID 指定任何內容。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM