【Kendra・IAM】AmazonKendraReadOnlyAccessにはRetrieveが含まれていない話

【Kendra・IAM】AmazonKendraReadOnlyAccessにはRetrieveが含まれていない話

Clock Icon2024.07.05

はじめに

新規事業部 生成AIチームの山本です。

Kendraを使っていて、読み取り関係のみを許可したいと思いました。そこで、AWS管理ポリシーの「AmazonKendraReadOnlyAccess」を使ったのですが、ハマって点があったので、その内容と修正した方法について記載します

エラー内容

AmazonKendraReadOnlyAccessを付与されたロールで、Kendraのインデックスに対してRetrieveを実行したところ、以下のようなエラーになりました

botocore.errorfactory.AccessDeniedException: An error occurred (AccessDeniedException) when calling the Retrieve operation: User: arn:aws:sts::(AWSアカウントID):assumed-role/(ロール名) is not authorized to perform: kendra:Retrieve on resource: arn:aws:kendra:ap-northeast-1:(AWSアカウントID):index/(KendraインデックスID) because no identity-based policy allows the kendra:Retrieve action

ハマりポイント

AmazonKendraReadOnlyAccessでは、許可するActionとしてRetrieveが含まていません(2024/07/05)。そのため上記のエラーになります

似たような動作をするQueryは、許可するActionに含まれているので、ちょっとわかりにくいポイントです。

https://docs.aws.amazon.com/ja_jp/aws-managed-policy/latest/reference/AmazonKendraReadOnlyAccess.html

(補足)

Kendraに関するAWS管理ポリシーとしては、AmazonKendraFullAccessとAmazonKendraReadOnlyAccessの2つ(のみ)が用意されています

Untitled

修正方法

IAMポリシーを新たに自分で作成しました。Retrieve以外にも、読み取りとして使えそうなAPIを含めて、下記のJSONにしました。

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "kendra:Get*",
        "kendra:Describe*",
        "kendra:List*",
        "kendra:BatchGetDocumentStatus",
        "kendra:Retrieve",
        "kendra:Query"
      ],
      "Resource": "*"
    }
  ]
}

https://docs.aws.amazon.com/kendra/latest/APIReference/API_Operations_Amazon_Kendra.html

AmazonKendraReadOnlyAccessと異なる点は「Action」の部分です

(補足)

自作ポリシーは、「IAM」のサービスページの「ポリシー」から、以下のようにして作成できます

  • 「ポリシーの作成」を選択する
  • 「ポリシーエディタ」欄の右上の「JSON」を選択する
    • 下記の"ポリシーの権限"をコピーペーストして、上書きする
  • 「次へ」を押す
  • 「ポリシー名」に「AmazonKendraReadOnlyAccessWithRetrieve」と入力する
    • 他の名前でも構いません
  • 右下の「ポリシーの作成」を押す

追記

AWS管理ポリシーの「ReadOnlyAccess」にもkendra:retrieveは含まれていないようです。

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "ReadOnlyActions",
            "Effect": "Allow",
            "Action": [
                ....
                "kendra:BatchGetDocumentStatus",
                "kendra:DescribeDataSource",
                "kendra:DescribeExperience",
                "kendra:DescribeFaq",
                "kendra:DescribeIndex",
                "kendra:DescribePrincipalMapping",
                "kendra:DescribeQuerySuggestionsBlockList",
                "kendra:DescribeQuerySuggestionsConfig",
                "kendra:DescribeThesaurus",
                "kendra:GetQuerySuggestions",
                "kendra:GetSnapshots",
                "kendra:ListDataSources",
                "kendra:ListDataSourceSyncJobs",
                "kendra:ListEntityPersonas",
                "kendra:ListExperienceEntities",
                "kendra:ListExperiences",
                "kendra:ListFaqs",
                "kendra:ListGroupsOlderThanOrderingId",
                "kendra:ListIndices",
                "kendra:ListQuerySuggestionsBlockLists",
                "kendra:ListTagsForResource",
                "kendra:ListThesauri",
                "kendra:Query",
                ....
            ],
            "Resource": "*"
        }
    ]
}

おわりに

どなたかの助けになれば幸いです。Retrieveは後からリリースされた機能なので含まれていないのかなと思いました

https://docs.aws.amazon.com/kendra/latest/dg/doc-history.html

この記事をシェアする

facebook logohatena logotwitter logo

© Classmethod, Inc. All rights reserved.