403 使用 Sig v4 将数据从 AWS Lambda 索引到 Elasticsearch 时出错:“没有 [indices:data/write/bulk] 权限”

abk*_*abk 4 amazon-web-services elasticsearch kibana boto3

我的函数可以从本地 Jupyter 笔记本将单个文档和批量索引到我的 AWS Elasticsearch,但是当我部署到 Lambda 时,它不断返回此错误:

"errorMessage": "AuthorizationException(403, 'security_exception', 'no permissions for
[indices:data/write/bulk] and User [name=arn:aws:iam::xxxxxxxxxxxx:role/MyLambdaRole,
backend_roles=[arn:aws:iam::xxxxxxxxxxxx:role/MyLambdaRole], requestedTenant=null]')"
Run Code Online (Sandbox Code Playgroud)

我的 Elasticsearch 域(v7.7)配置如下:

Fine-grained access control: Enabled
Master user type: Internal user database
SAML authentication: Disabled
Amazon Cognito for authentication: Disabled
Require HTTPS: Enabled
Encryption at rest: Enabled
KMS master keyarn:aws:kms:us-east-1:xxxxxxxxxxxxx:key/<aws/es key>
Node-to-node encryption: Enabled
Run Code Online (Sandbox Code Playgroud)

域的访问策略包含:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "AWS": "*"
      },
      "Action": "es:*",
      "Resource": "*"
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

MyLambdaRole 的 IAM 策略包含:

...
        {
            "Action": [
                "es:*"
            ],
            "Resource": [
                "*"
            ],
            "Effect": "Allow"
        }
    ]
Run Code Online (Sandbox Code Playgroud)

在 Kibana 中,我已在 Security -> Role Mappings -> all_access 下映射了我的 AWS 管理员 IAM 用户和 MyLambdaRole。我尝试了不同的组合,将它们添加到后端角色并将它们添加到 security_manager。

Lambda 使用 AWS Signature v4 身份验证,elasticsearch 客户端版本为 7.7.0:

"errorMessage": "AuthorizationException(403, 'security_exception', 'no permissions for
[indices:data/write/bulk] and User [name=arn:aws:iam::xxxxxxxxxxxx:role/MyLambdaRole,
backend_roles=[arn:aws:iam::xxxxxxxxxxxx:role/MyLambdaRole], requestedTenant=null]')"
Run Code Online (Sandbox Code Playgroud)

如果我替换http_auth = awsauth为 Kibana 凭证,http_auth = (kibana_username, kibana_password)它会返回状态 200,但索引中不会创建新文档,这很奇怪。

我想知道我可能缺少什么或者我的配置可能在哪里被关闭。

小智 9

这是因为启用了细粒度访问控制。我遇到了完全相同的问题,细粒度的访问控制会导致问题。您的笔记本可能正在使用您指定的主 ARN,该主 ARN 具有访问权限并且基本上始终被允许。

我重新创建了 ES 实例并禁用了细粒度访问控制,并且仅在适合我们的设置时才使用域策略。

请在此处阅读更多内容,并注意突出显示的部分重新用户/IAM 混合且无法正常工作。

https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/fgac.html