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

Add RequestsWrapper option to support UTF-8 for basic auth #7441

Merged
merged 2 commits into from
Aug 28, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ instances:
## - basic
## |__ username
## |__ password
## |__ use_legacy_auth_encoding
## - digest
## |__ username
## |__ password
Expand All @@ -140,6 +141,11 @@ instances:
#
# auth_type: basic

## @param use_legacy_auth_encoding - boolean - optional - default: true
## When `auth_type` is set to `basic`, this determines whether to encode as `latin1` rather than `utf-8`.
#
# use_legacy_auth_encoding: true

## @param username - string - optional
## The username to use if services are behind basic or digest auth.
#
Expand Down
6 changes: 6 additions & 0 deletions airflow/datadog_checks/airflow/data/conf.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ instances:
## - basic
## |__ username
## |__ password
## |__ use_legacy_auth_encoding
## - digest
## |__ username
## |__ password
Expand All @@ -111,6 +112,11 @@ instances:
#
# auth_type: basic

## @param use_legacy_auth_encoding - boolean - optional - default: true
## When `auth_type` is set to `basic`, this determines whether to encode as `latin1` rather than `utf-8`.
#
# use_legacy_auth_encoding: true

## @param username - string - optional
## The username to use if services are behind basic or digest auth.
#
Expand Down
6 changes: 6 additions & 0 deletions amazon_msk/datadog_checks/amazon_msk/data/conf.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ instances:
## - basic
## |__ username
## |__ password
## |__ use_legacy_auth_encoding
## - digest
## |__ username
## |__ password
Expand All @@ -229,6 +230,11 @@ instances:
#
# auth_type: basic

## @param use_legacy_auth_encoding - boolean - optional - default: true
## When `auth_type` is set to `basic`, this determines whether to encode as `latin1` rather than `utf-8`.
#
# use_legacy_auth_encoding: true

## @param username - string - optional
## The username to use if services are behind basic or digest auth.
#
Expand Down
6 changes: 6 additions & 0 deletions ambari/datadog_checks/ambari/data/conf.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ instances:
## - basic
## |__ username
## |__ password
## |__ use_legacy_auth_encoding
## - digest
## |__ username
## |__ password
Expand Down Expand Up @@ -150,6 +151,11 @@ instances:
#
# skip_proxy: false

## @param use_legacy_auth_encoding - boolean - optional - default: true
## When `auth_type` is set to `basic`, this determines whether to encode as `latin1` rather than `utf-8`.
#
# use_legacy_auth_encoding: true

## @param ntlm_domain - string - optional
## If your services use NTLM authentication, specify
## the domain used in the check. For NTLM Auth, append
Expand Down
6 changes: 6 additions & 0 deletions apache/datadog_checks/apache/data/conf.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ instances:
## - basic
## |__ username
## |__ password
## |__ use_legacy_auth_encoding
## - digest
## |__ username
## |__ password
Expand All @@ -111,6 +112,11 @@ instances:
#
# auth_type: basic

## @param use_legacy_auth_encoding - boolean - optional - default: true
## When `auth_type` is set to `basic`, this determines whether to encode as `latin1` rather than `utf-8`.
#
# use_legacy_auth_encoding: true

## @param username - string - optional
## The username to use if services are behind basic or digest auth.
#
Expand Down
6 changes: 6 additions & 0 deletions cilium/datadog_checks/cilium/data/conf.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ instances:
## - basic
## |__ username
## |__ password
## |__ use_legacy_auth_encoding
## - digest
## |__ username
## |__ password
Expand All @@ -183,6 +184,11 @@ instances:
#
# auth_type: basic

## @param use_legacy_auth_encoding - boolean - optional - default: true
## When `auth_type` is set to `basic`, this determines whether to encode as `latin1` rather than `utf-8`.
#
# use_legacy_auth_encoding: true

## @param username - string - optional
## The username to use if services are behind basic or digest auth.
#
Expand Down
5 changes: 5 additions & 0 deletions cisco_aci/datadog_checks/cisco_aci/data/conf.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ instances:
#
# skip_proxy: false

## @param use_legacy_auth_encoding - boolean - optional - default: true
## When `auth_type` is set to `basic`, this determines whether to encode as `latin1` rather than `utf-8`.
#
# use_legacy_auth_encoding: true

## @param tls_verify - boolean - optional - default: true
## Instructs the check to validate the TLS certificate of services.
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ instances:
#
# skip_proxy: false

## @param use_legacy_auth_encoding - boolean - optional - default: true
## When `auth_type` is set to `basic`, this determines whether to encode as `latin1` rather than `utf-8`.
#
# use_legacy_auth_encoding: true

## @param tls_verify - boolean - optional - default: true
## Instructs the check to validate the TLS certificate of services.
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ instances:
## - basic
## |__ username
## |__ password
## |__ use_legacy_auth_encoding
## - digest
## |__ username
## |__ password
Expand All @@ -207,6 +208,11 @@ instances:
#
# auth_type: basic

## @param use_legacy_auth_encoding - boolean - optional - default: true
## When `auth_type` is set to `basic`, this determines whether to encode as `latin1` rather than `utf-8`.
#
# use_legacy_auth_encoding: true

## @param username - string - optional
## The username to use if services are behind basic or digest auth.
#
Expand Down
6 changes: 6 additions & 0 deletions consul/datadog_checks/consul/data/conf.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ instances:
## - basic
## |__ username
## |__ password
## |__ use_legacy_auth_encoding
## - digest
## |__ username
## |__ password
Expand All @@ -180,6 +181,11 @@ instances:
#
# auth_type: basic

## @param use_legacy_auth_encoding - boolean - optional - default: true
## When `auth_type` is set to `basic`, this determines whether to encode as `latin1` rather than `utf-8`.
#
# use_legacy_auth_encoding: true

## @param username - string - optional
## The username to use if services are behind basic or digest auth.
#
Expand Down
6 changes: 6 additions & 0 deletions couch/datadog_checks/couch/data/conf.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ instances:
## - basic
## |__ username
## |__ password
## |__ use_legacy_auth_encoding
## - digest
## |__ username
## |__ password
Expand All @@ -186,6 +187,11 @@ instances:
#
# auth_type: basic

## @param use_legacy_auth_encoding - boolean - optional - default: true
## When `auth_type` is set to `basic`, this determines whether to encode as `latin1` rather than `utf-8`.
#
# use_legacy_auth_encoding: true

## @param ntlm_domain - string - optional
## If your services use NTLM authentication, specify
## the domain used in the check. For NTLM Auth, append
Expand Down
8 changes: 6 additions & 2 deletions datadog_checks_base/datadog_checks/base/utils/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

from ..config import is_affirmative
from ..errors import ConfigurationError
from .common import ensure_unicode
from .common import ensure_bytes, ensure_unicode
from .headers import get_default_headers, update_headers
from .warnings_util import disable_warnings_ctx

Expand Down Expand Up @@ -70,6 +70,7 @@
'tls_private_key': None,
'tls_verify': True,
'timeout': DEFAULT_TIMEOUT,
'use_legacy_auth_encoding': True,
'username': None,
}
# For any known legacy fields that may be widespread
Expand Down Expand Up @@ -428,7 +429,10 @@ def should_bypass_proxy(url, no_proxy_uris):
def create_basic_auth(config):
# Since this is the default case, only activate when all fields are explicitly set
if config['username'] and config['password']:
return (config['username'], config['password'])
if config['use_legacy_auth_encoding']:
return config['username'], config['password']
else:
return ensure_bytes(config['username']), ensure_bytes(config['password'])


def create_digest_auth(config):
Expand Down
7 changes: 7 additions & 0 deletions datadog_checks_base/tests/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,13 @@ def test_config_basic_authtype(self):

assert http.options['auth'] == ('user', 'pass')

def test_config_basic_no_legacy_encoding(self):
instance = {'username': 'user', 'password': 'pass', 'use_legacy_auth_encoding': False}
init_config = {}
http = RequestsWrapper(instance, init_config)

assert http.options['auth'] == (b'user', b'pass')

def test_config_digest_authtype(self):
instance = {'username': 'user', 'password': 'pass', 'auth_type': 'digest'}
init_config = {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
- basic
|__ username
|__ password
|__ use_legacy_auth_encoding
- digest
|__ username
|__ password
Expand All @@ -72,6 +73,12 @@
The `aws` auth type relies on boto3 to automatically gather AWS credentials, for example: from `.aws/credentials`. /noqa
Details: https://boto3.amazonaws.com/v1/documentation/api/latest/guide/configuration.html#configuring-credentials /noqa

- name: use_legacy_auth_encoding
value:
example: true
type: boolean
description: |
When `auth_type` is set to `basic`, this determines whether to encode as `latin1` rather than `utf-8`.
- name: username
value:
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2718,6 +2718,7 @@ def test_template_array():
'proxy',
'skip_proxy',
'auth_type',
'use_legacy_auth_encoding',
'username',
'password',
'ntlm_domain',
Expand Down
6 changes: 6 additions & 0 deletions druid/datadog_checks/druid/data/conf.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ instances:
## - basic
## |__ username
## |__ password
## |__ use_legacy_auth_encoding
## - digest
## |__ username
## |__ password
Expand All @@ -111,6 +112,11 @@ instances:
#
# auth_type: basic

## @param use_legacy_auth_encoding - boolean - optional - default: true
## When `auth_type` is set to `basic`, this determines whether to encode as `latin1` rather than `utf-8`.
#
# use_legacy_auth_encoding: true

## @param username - string - optional
## The username to use if services are behind basic or digest auth.
#
Expand Down
6 changes: 6 additions & 0 deletions elastic/datadog_checks/elastic/data/conf.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ instances:
## - basic
## |__ username
## |__ password
## |__ use_legacy_auth_encoding
## - digest
## |__ username
## |__ password
Expand All @@ -194,6 +195,11 @@ instances:
#
# auth_type: basic

## @param use_legacy_auth_encoding - boolean - optional - default: true
## When `auth_type` is set to `basic`, this determines whether to encode as `latin1` rather than `utf-8`.
#
# use_legacy_auth_encoding: true

## @param username - string - optional
## The username to use if services are behind basic or digest auth.
#
Expand Down
6 changes: 6 additions & 0 deletions envoy/datadog_checks/envoy/data/conf.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ instances:
## - basic
## |__ username
## |__ password
## |__ use_legacy_auth_encoding
## - digest
## |__ username
## |__ password
Expand All @@ -199,6 +200,11 @@ instances:
#
# auth_type: basic

## @param use_legacy_auth_encoding - boolean - optional - default: true
## When `auth_type` is set to `basic`, this determines whether to encode as `latin1` rather than `utf-8`.
#
# use_legacy_auth_encoding: true

## @param ntlm_domain - string - optional
## If your services use NTLM authentication, specify
## the domain used in the check. For NTLM Auth, append
Expand Down
6 changes: 6 additions & 0 deletions fluentd/datadog_checks/fluentd/data/conf.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ instances:
## - basic
## |__ username
## |__ password
## |__ use_legacy_auth_encoding
## - digest
## |__ username
## |__ password
Expand All @@ -164,6 +165,11 @@ instances:
#
# auth_type: basic

## @param use_legacy_auth_encoding - boolean - optional - default: true
## When `auth_type` is set to `basic`, this determines whether to encode as `latin1` rather than `utf-8`.
#
# use_legacy_auth_encoding: true

## @param username - string - optional
## The username to use if services are behind basic or digest auth.
#
Expand Down
6 changes: 6 additions & 0 deletions gitlab/datadog_checks/gitlab/data/conf.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ instances:
## - basic
## |__ username
## |__ password
## |__ use_legacy_auth_encoding
## - digest
## |__ username
## |__ password
Expand All @@ -177,6 +178,11 @@ instances:
#
# auth_type: basic

## @param use_legacy_auth_encoding - boolean - optional - default: true
## When `auth_type` is set to `basic`, this determines whether to encode as `latin1` rather than `utf-8`.
#
# use_legacy_auth_encoding: true

## @param username - string - optional
## The username to use if services are behind basic or digest auth.
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ instances:
## - basic
## |__ username
## |__ password
## |__ use_legacy_auth_encoding
## - digest
## |__ username
## |__ password
Expand All @@ -261,6 +262,11 @@ instances:
#
# auth_type: basic

## @param use_legacy_auth_encoding - boolean - optional - default: true
## When `auth_type` is set to `basic`, this determines whether to encode as `latin1` rather than `utf-8`.
#
# use_legacy_auth_encoding: true

## @param username - string - optional
## The username to use if services are behind basic or digest auth.
#
Expand Down
Loading