Skip to content

Commit 8306e98

Browse files
committed
feat(connection): add ssl_insecure parameter default to True
1 parent b65d8c1 commit 8306e98

11 files changed

+43
-8
lines changed

README.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ Connection Parameters
144144
+-------------------------+--------------------------------------------------------------------------------------------+---------------+----------+
145145
| cluster_identifier | String. The cluster identifier of the Amazon Redshift Cluster | None | No |
146146
+-------------------------+--------------------------------------------------------------------------------------------+---------------+----------+
147+
| ssl_insecure | Bool. Specifies if IDP hosts server certificate will be verified | True | No |
148+
+-------------------------+--------------------------------------------------------------------------------------------+---------------+----------+
147149
| db_user | String. The user ID to use with Amazon Redshift | None | No |
148150
+-------------------------+--------------------------------------------------------------------------------------------+---------------+----------+
149151
| db_groups | String. A comma-separated list of existing database group names that the DbUser joins for | None | No |

redshift_connector/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ def connect(
111111
allow_db_user_override: bool = False,
112112
client_protocol_version: int = DEFAULT_PROTOCOL_VERSION,
113113
database_metadata_current_db_only: bool = True,
114+
ssl_insecure: typing.Optional[bool] = None,
114115
) -> Connection:
115116

116117
info: RedshiftProperty = RedshiftProperty()
@@ -153,6 +154,7 @@ def connect(
153154
allow_db_user_override=allow_db_user_override,
154155
client_protocol_version=client_protocol_version,
155156
database_metadata_current_db_only=database_metadata_current_db_only,
157+
ssl_insecure=ssl_insecure,
156158
)
157159

158160
return Connection(

redshift_connector/iam_helper.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ def set_iam_properties(
6565
allow_db_user_override: bool,
6666
client_protocol_version: int,
6767
database_metadata_current_db_only: bool,
68+
ssl_insecure: typing.Optional[bool],
6869
) -> None:
6970
if info is None:
7071
raise InterfaceError("Invalid connection property setting. info must be specified")
@@ -90,6 +91,8 @@ def set_iam_properties(
9091
raise InterfaceError(
9192
"Invalid connection property setting. IAM must be enabled when using credentials " "via identity provider"
9293
)
94+
elif (info.iam is False) and (ssl_insecure is not None):
95+
raise InterfaceError("Invalid connection property setting. IAM must be enabled when using ssl_insecure")
9396
elif (info.iam is True) and (credentials_provider is None):
9497
raise InterfaceError(
9598
"Invalid connection property setting. " "Credentials provider cannot be None when IAM is enabled"
@@ -148,6 +151,9 @@ def set_iam_properties(
148151
info.force_lowercase = force_lowercase
149152
info.allow_db_user_override = allow_db_user_override
150153

154+
if ssl_insecure is not None:
155+
info.sslInsecure = ssl_insecure
156+
151157
# Azure specified parameters
152158
info.client_id = client_id
153159
info.idp_tenant = idp_tenant

redshift_connector/plugin/adfs_credentials_provider.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def form_based_authentication(self: "AdfsCredentialsProvider") -> str:
3030
host=self.idp_host, port=str(self.idpPort)
3131
)
3232
try:
33-
response: "requests.Response" = requests.get(url)
33+
response: "requests.Response" = requests.get(url, verify=self.do_verify_ssl_cert())
3434
response.raise_for_status()
3535
except requests.exceptions.HTTPError as e:
3636
_logger.error("Request for SAML assertion when refreshing credentials was unsuccessful. {}".format(str(e)))
@@ -73,7 +73,7 @@ def form_based_authentication(self: "AdfsCredentialsProvider") -> str:
7373
url = "https://{host}:{port}{action}".format(host=self.idp_host, port=str(self.idpPort), action=action)
7474

7575
try:
76-
response = requests.post(url, data=payload)
76+
response = requests.post(url, data=payload, verify=self.do_verify_ssl_cert())
7777
response.raise_for_status()
7878
except requests.exceptions.HTTPError as e:
7979
_logger.error("Request to refresh credentials was unsuccessful. {}".format(str(e)))

redshift_connector/plugin/azure_credentials_provider.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ def azure_oauth_based_authentication(self: "AzureCredentialsProvider") -> str:
6969
}
7070

7171
try:
72-
response: "requests.Response" = requests.post(url, data=payload, headers=headers)
72+
response: "requests.Response" = requests.post(
73+
url, data=payload, headers=headers, verify=self.do_verify_ssl_cert()
74+
)
7375
response.raise_for_status()
7476
except requests.exceptions.HTTPError as e:
7577
_logger.error("Request for authentication from Azure was unsuccessful. {}".format(str(e)))

redshift_connector/plugin/browser_azure_credentials_provider.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def fetch_saml_response(self: "BrowserAzureCredentialsProvider", token):
114114
"redirect_uri": self.redirectUri,
115115
}
116116
try:
117-
response = requests.post(url, data=payload, headers=headers)
117+
response = requests.post(url, data=payload, headers=headers, verify=self.do_verify_ssl_cert())
118118
response.raise_for_status()
119119
except requests.exceptions.HTTPError as e:
120120
_logger.error("Request for authentication from Microsoft was unsuccessful. {}".format(str(e)))

redshift_connector/plugin/okta_credentials_provider.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ def okta_authentication(self: "OktaCredentialsProvider") -> str:
3939
headers: typing.Dict[str, str] = okta_headers
4040
payload: typing.Dict[str, typing.Optional[str]] = {"username": self.user_name, "password": self.password}
4141
try:
42-
response: "requests.Response" = requests.post(url, data=json.dumps(payload), headers=headers)
42+
response: "requests.Response" = requests.post(
43+
url, data=json.dumps(payload), headers=headers, verify=self.do_verify_ssl_cert()
44+
)
4345
response.raise_for_status()
4446
except requests.exceptions.HTTPError as e:
4547
_logger.error("Request for authentication from Okta was unsuccessful. {}".format(str(e)))
@@ -76,7 +78,7 @@ def handle_saml_assertion(self: "OktaCredentialsProvider", okta_session_token: s
7678
host=self.idp_host, app_name=self.app_name, app_id=self.app_id, session_token=okta_session_token
7779
)
7880
try:
79-
response: "requests.Response" = requests.get(url)
81+
response: "requests.Response" = requests.get(url, verify=self.do_verify_ssl_cert())
8082
response.raise_for_status()
8183
except requests.exceptions.HTTPError as e:
8284
_logger.error("Request for SAML assertion from Okta was unsuccessful. {}".format(str(e)))

redshift_connector/plugin/ping_credentials_provider.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def get_saml_assertion(self: "PingCredentialsProvider") -> str:
3232
host=self.idp_host, port=str(self.idpPort), sp_id=self.partner_sp_id
3333
)
3434
try:
35-
response: "requests.Response" = requests.get(url)
35+
response: "requests.Response" = requests.get(url, verify=self.do_verify_ssl_cert())
3636
response.raise_for_status()
3737
except requests.exceptions.HTTPError as e:
3838
_logger.error("Request for SAML assertion when refreshing credentials was unsuccessful. {}".format(str(e)))
@@ -90,7 +90,7 @@ def get_saml_assertion(self: "PingCredentialsProvider") -> str:
9090
if action and action.startswith("/"):
9191
url = "https://{host}:{port}{action}".format(host=self.idp_host, port=str(self.idpPort), action=action)
9292
try:
93-
response = requests.post(url, data=payload)
93+
response = requests.post(url, data=payload, verify=self.do_verify_ssl_cert())
9494
response.raise_for_status()
9595
except requests.exceptions.HTTPError as e:
9696
_logger.error("Request to refresh credentials was unsuccessful. {}".format(str(e)))

redshift_connector/plugin/saml_credentials_provider.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ def add_parameter(self: "SamlCredentialsProvider", info: RedshiftProperty) -> No
4646
self.region = info.region
4747
self.principal = info.principal
4848

49+
def do_verify_ssl_cert(self: "SamlCredentialsProvider") -> bool:
50+
return not self.sslInsecure
51+
4952
def get_credentials(self: "SamlCredentialsProvider") -> CredentialsHolder:
5053
key: str = self.get_cache_key()
5154
if key not in self.cache or self.cache[key].is_expired():

test/integration/plugin/test_credentials_providers.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,15 @@ def test_invalid_db_group(idp_arg):
115115
redshift_connector.connect(**idp_arg)
116116

117117

118+
@pytest.mark.parametrize("idp_arg", NON_BROWSER_IDP, indirect=True)
119+
@pytest.mark.parametrize("ssl_insecure_val", [True, False])
120+
def test_ssl_insecure_is_used(idp_arg, ssl_insecure_val):
121+
idp_arg["ssl_insecure"] = ssl_insecure_val
122+
123+
with redshift_connector.connect(**idp_arg):
124+
pass
125+
126+
118127
@pytest.mark.parametrize("idp_arg", ALL_IDP, indirect=True)
119128
def testSslAndIam(idp_arg):
120129
idp_arg["ssl"] = False

0 commit comments

Comments
 (0)