Skip to content
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

OBS-427: Support verify_certs with self-issued certs for elastic cloud #6874

Merged
merged 1 commit into from
Jan 24, 2025
Merged
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
6 changes: 5 additions & 1 deletion socorro/external/es/connection_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@ def __init__(
self,
url="http://localhost:9200",
timeout=30,
ca_certs=None,
**kwargs,
):
"""
:arg url: the url to the elasticsearch instances
:arg timeout: the time in seconds before a query to elasticsearch fails
:arg ca_certs: path to a certs.pem file for verifying self-issued certs
"""
self.url = url
self.timeout = timeout
self.ca_certs = ca_certs

def connection(self, name=None, timeout=None):
"""Returns an instance of elasticsearch-py's Elasticsearch class as
Expand All @@ -40,7 +43,8 @@ def connection(self, name=None, timeout=None):
return Elasticsearch(
hosts=self.url,
request_timeout=timeout,
verify_certs=False,
verify_certs=True,
ca_certs=self.ca_certs,
)

def indices_client(self, name=None):
Expand Down
7 changes: 4 additions & 3 deletions socorro/external/es/crashstorage.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,11 @@ def __init__(
metrics_prefix="processor.es",
timeout=30,
shards_per_index=10,
ca_certs=None,
):
super().__init__()

self.client = self.build_client(url=url, timeout=timeout)
self.client = self.build_client(url=url, timeout=timeout, ca_certs=ca_certs)

# Create a MetricsInterface that includes the base prefix plus the prefix passed
# into __init__
Expand All @@ -299,8 +300,8 @@ def __init__(
self._mapping_cache = {}

@classmethod
def build_client(cls, url, timeout):
return ConnectionContext(url=url, timeout=timeout)
def build_client(cls, url, timeout, ca_certs=None):
return ConnectionContext(url=url, timeout=timeout, ca_certs=ca_certs)

def build_query(self):
"""Return new instance of Query."""
Expand Down
9 changes: 9 additions & 0 deletions socorro/mozilla_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,15 @@ def es_mode_parser(val):
"ELASTICSEARCH_URL",
doc="Elasticsearch url.",
),
"ca_certs": _config(
"ELASTICSEARCH_CA_CERTS",
default="",
parser=or_none(str),
doc=(
"Path to a certs.pem file to verify certs for Elasticsearch "
"clusters that use self-issued certificates."
),
),
},
}

Expand Down