Skip to content

Commit a87b311

Browse files
Merge pull request DataDog#174 from DataDog/gaetan.deputier/disable-ssl-validation-lambda
[Lambda]: Add DD_SKIP_SSL_VALIDATION option to disable hostname validation for HTTP forwarding
2 parents c9d0b85 + 3896b02 commit a87b311

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

aws/logs_monitoring/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,3 +181,8 @@ If there are multiline logs in s3, set `DD_MULTILINE_LOG_REGEX_PATTERN` environm
181181
### 10. (optional) Disable log forwarding
182182

183183
The datadog forwarder **ALWAYS** forwards logs by default. If you do NOT use the Datadog log management product, you **MUST** set environment variable `DD_FORWARD_LOG` to `False`, to avoid sending logs to Datadog. The forwarder will then only forward other observability data, such as metrics.
184+
185+
### 11. (optional) Disable SSL validation
186+
187+
If you need to ignore SSL certificate validation when forwarding logs using HTTPS, you can set the environment variable `DD_SKIP_SSL_VALIDATION` to `True`.
188+
This will still encrypt the traffic between the forwarder and the endpoint provided with `DD_URL` but will not check if the destination SSL certificate is valid.

aws/logs_monitoring/lambda_function.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ def get_bool_env_var(envvar, default):
111111
#
112112
DD_NO_SSL = get_bool_env_var("DD_NO_SSL", "false")
113113

114+
## @param DD_SKIP_SSL_VALIDATION - boolean - optional -default: false
115+
## Disable SSL certificate validation when forwarding logs via HTTP.
116+
#
117+
DD_SKIP_SSL_VALIDATION = get_bool_env_var("DD_SKIP_SSL_VALIDATION", "false")
118+
114119
## @param DD_SITE - String - optional -default: datadoghq.com
115120
## Define the Datadog Site to send your logs and metrics to.
116121
## Set it to `datadoghq.eu` to send your logs and metrics to Datadog EU site.
@@ -250,7 +255,7 @@ def compileRegex(rule, pattern):
250255
DD_CUSTOM_TAGS = "ddtags"
251256
DD_SERVICE = "service"
252257
DD_HOST = "host"
253-
DD_FORWARDER_VERSION = "2.3.1"
258+
DD_FORWARDER_VERSION = "2.3.2"
254259

255260
class RetriableException(Exception):
256261
pass
@@ -346,12 +351,13 @@ class DatadogHTTPClient(object):
346351
_POST = "POST"
347352
_HEADERS = {"Content-type": "application/json"}
348353

349-
def __init__(self, host, port, no_ssl, api_key, scrubber, timeout=10):
354+
def __init__(self, host, port, no_ssl, skip_ssl_validation, api_key, scrubber, timeout=10):
350355
protocol = "http" if no_ssl else "https"
351356
self._url = "{}://{}:{}/v1/input/{}".format(protocol, host, port, api_key)
352357
self._scrubber = scrubber
353358
self._timeout = timeout
354359
self._session = None
360+
self._ssl_validation = not skip_ssl_validation
355361

356362
def _connect(self):
357363
self._session = requests.Session()
@@ -369,6 +375,7 @@ def send(self, logs):
369375
self._url,
370376
data=self._scrubber.scrub("[{}]".format(",".join(logs))),
371377
timeout=self._timeout,
378+
verify=self._ssl_validation
372379
)
373380
except ScrubbingException:
374381
raise Exception("could not scrub the payload")
@@ -500,7 +507,7 @@ def forward_logs(logs):
500507
cli = DatadogTCPClient(DD_URL, DD_PORT, DD_NO_SSL, DD_API_KEY, scrubber)
501508
else:
502509
batcher = DatadogBatcher(256 * 1000, 2 * 1000 * 1000, 200)
503-
cli = DatadogHTTPClient(DD_URL, DD_PORT, DD_NO_SSL, DD_API_KEY, scrubber)
510+
cli = DatadogHTTPClient(DD_URL, DD_PORT, DD_NO_SSL, DD_SKIP_SSL_VALIDATION, DD_API_KEY, scrubber)
504511

505512
with DatadogClient(cli) as client:
506513
for batch in batcher.batch(logs):

0 commit comments

Comments
 (0)