【问题标题】:Elasticsearch Service with Cognito -- how to access via Python HTTP requestElasticsearch Service with Cognito -- 如何通过 Python HTTP 请求访问
【发布时间】:2021-04-13 20:05:04
【问题描述】:

我最近设置了一个 Elasticsearch 服务并将其配置为使用 Cognito 进行身份管理。我关注了this guide,到目前为止一切都按预期工作。我能够按预期添加新用户,并且他们可以按预期访问 Kibana。

不过,我还想使用 Python 与 Elasticsearch 服务进行交互。我关注了this guide,但我收到关于没有正确访问权限的权限错误。

from elasticsearch import Elasticsearch, RequestsHttpConnection
from requests_aws4auth import AWS4Auth
import boto3

host = 'hostname.us-east-2.es.amazonaws.com/'
region = 'us-east-2'
service = 'es'
credentials = boto3.Session().get_credentials()
awsauth = AWS4Auth(credentials.access_key, credentials.secret_key, region, service, session_token=credentials.token)

es = Elasticsearch(
    hosts = [{'host': host, 'port': 443}],
    http_auth = awsauth,
    use_ssl = True,
    verify_certs = True,
    connection_class = RequestsHttpConnection
)

print(es.info())
AuthorizationException: AuthorizationException(403, 'security_exception', 'no permissions for [indices:admin/get] and User [name=arn:aws:iam::12345678:user/username, backend_roles=[], requestedTenant=null]')

我不确定问题是否与我配置 Conginto 的方式有关,或者是否与我提交此请求的方式有关。对于找出我的问题可能出在哪里的任何帮助,我们将不胜感激。

【问题讨论】:

  • 您能否禁用/删除 congito 身份验证并尝试不使用它。还有你对你的 ES 有什么政策?

标签: python amazon-web-services elasticsearch


【解决方案1】:

这也发生在我身上。我找到了两种方法,您必须为它们创建一个 IAM 用户。

  • 打开 IAM 控制台并为 IAM 用户提供必要的策略以访问您的 elasticsearch 域(或者我仅附加了“AdministratorAccess”策略(它提供 AWS 的所有访问权限)),那么您应该使用此 IAM 帐户的凭证。
  • 或者打开 kibana -> 安全 -> 角色 -> 点击 all_access 角色 -> mapped_users -> manage_mapping。然后,您应该将 IAM 用户的 arn 添加到后端角色。您必须在代码上使用此用户的凭据而不是“boto3.Session().get_credentials()”来连接 ES。 如果您不熟悉 IAM 角色和政策,我建议您使用第二个。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-09-18
    • 1970-01-01
    • 2021-02-02
    • 1970-01-01
    • 2020-07-23
    • 2011-08-30
    相关资源
    最近更新 更多