Skip to content

Elasticsearch API Key Authentication support #4164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion aleph/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ def get_es():
"verify_certs": SETTINGS.ELASTICSEARCH_TLS_VERIFY_CERTS,
"client_cert": SETTINGS.ELASTICSEARCH_TLS_CLIENT_CERT,
"client_key": SETTINGS.ELASTICSEARCH_TLS_CLIENT_KEY,
"api_key": SETTINGS.ELASTICSEARCH_API_KEY,
}
)
for attempt in service_retries():
Expand All @@ -150,12 +151,24 @@ def get_es():
if sls.LOG_FORMAT == LOG_FORMAT_JSON:
es = Elasticsearch(
url,
api_key=(
SETTINGS.ELASTICSEARCH_API_ID,
SETTINGS.ELASTICSEARCH_API_KEY,
),
transport_class=LoggingTransport,
timeout=timeout,
**con_opts,
)
else:
es = Elasticsearch(url, timeout=timeout, **con_opts)
es = Elasticsearch(
url,
api_key=(
SETTINGS.ELASTICSEARCH_API_ID,
SETTINGS.ELASTICSEARCH_API_KEY,
),
timeout=timeout,
**con_opts,
)
es.info()
SETTINGS._es_instance = es
return SETTINGS._es_instance
Expand Down
2 changes: 2 additions & 0 deletions aleph/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ def __init__(self) -> None:
)
self.ELASTICSEARCH_TLS_CLIENT_CERT = env.get("ELASTICSEARCH_TLS_CLIENT_CERT")
self.ELASTICSEARCH_TLS_CLIENT_KEY = env.get("ELASTICSEARCH_TLS_CLIENT_KEY")
self.ELASTICSEARCH_API_ID = env.get("ELASTICSEARCH_API_ID", None)
self.ELASTICSEARCH_API_KEY = env.get("ELASTICSEARCH_API_KEY", None)
self.ELASTICSEARCH_TIMEOUT = env.to_int("ELASTICSEARCH_TIMEOUT", 60)
self.XREF_SCROLL = env.get("ALEPH_XREF_SCROLL", "5m")
self.XREF_SCROLL_SIZE = env.get("ALEPH_XREF_SCROLL_SIZE", "1000")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ services:
- name: 'ALEPH_ELASTICSEARCH_URI'
description: 'ElasticSearch API endpoint'
defaultValue: 'http://elasticsearch:9200'
- name: 'ELASTICSEARCH_API_ID'
description: 'Elasticsearch Api Id for Aleph indexes.'
defaultValue: '<YOUR API ID>'
- name: 'ELASTICSEARCH_API_KEY'
description: 'Elasticsearch Api Id for Aleph indexes.'
defaultValue: '<YOUR API KEY>'
- name: 'ELASTICSEARCH_TIMEOUT'
description: 'Timeout for ElasticSearch requests in seconds.'
defaultValue: '60'
Expand Down