Skip to content

Commit 4247f99

Browse files
committed
feat(auth, iam): allowed use of getClusterCredentials V2 API when IdP Plugin authentication is used and group_federation=True. Previously an unsupported error was thrown.
1 parent 62a4d4e commit 4247f99

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

redshift_connector/iam_helper.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def can_support_v2(provider_type: "IamHelper.IAMAuthenticationType") -> bool:
5959
IamHelper.IAMAuthenticationType.PROFILE,
6060
IamHelper.IAMAuthenticationType.IAM_KEYS,
6161
IamHelper.IAMAuthenticationType.IAM_KEYS_WITH_SESSION,
62+
IamHelper.IAMAuthenticationType.PLUGIN,
6263
)
6364
) and IdpAuthHelper.get_pkg_version("boto3") >= Version("1.24.5")
6465

@@ -72,6 +73,11 @@ def get_cluster_credentials_api_type(
7273
Returns an enum representing the Python SDK method to use for getting temporary IAM credentials.
7374
"""
7475
_logger.debug("Determining which Redshift API to use for retrieving temporary Redshift instance credentials")
76+
FAILED_TO_USE_V2_API_ERROR_MSG: str = (
77+
"Environment does not meet requirements to use {} API. "
78+
"This could be due to the connection properties provided or the version of boto3 in use. "
79+
"Please try updating the boto3 version or consider setting group_federation connection parameter to False."
80+
)
7581

7682
if not info._is_serverless:
7783
_logger.debug("Redshift provisioned")
@@ -82,7 +88,7 @@ def get_cluster_credentials_api_type(
8288
_logger.debug("Provisioned cluster GetClusterCredentialsAPIType.IAM_V2")
8389
return IamHelper.GetClusterCredentialsAPIType.IAM_V2
8490
else:
85-
raise InterfaceError("Authentication with plugin is not supported for group federation")
91+
raise InterfaceError(FAILED_TO_USE_V2_API_ERROR_MSG.format("GetClusterCredentials V2 API"))
8692
elif not info.group_federation:
8793
_logger.debug("Serverless cluster GetClusterCredentialsAPIType.SERVERLESS_V1")
8894
return IamHelper.GetClusterCredentialsAPIType.SERVERLESS_V1
@@ -93,7 +99,7 @@ def get_cluster_credentials_api_type(
9399
_logger.debug("Serverless cluster GetClusterCredentialsAPIType.IAM_V2")
94100
return IamHelper.GetClusterCredentialsAPIType.IAM_V2
95101
else:
96-
raise InterfaceError("Authentication with plugin is not supported for group federation")
102+
raise InterfaceError(FAILED_TO_USE_V2_API_ERROR_MSG.format("GetClusterCredentials V2 API"))
97103

98104
@staticmethod
99105
def set_iam_properties(info: RedshiftProperty) -> RedshiftProperty:

test/integration/plugin/test_credentials_providers.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,3 +207,11 @@ def uses_db_groups_nominal(idp_arg, db_groups):
207207

208208
with redshift_connector.connect(**idp_arg):
209209
pass
210+
211+
212+
@pytest.mark.parametrize("idp_arg", NON_BROWSER_IDP, indirect=True)
213+
def test_connect_with_group_federation(idp_arg):
214+
idp_arg["group_federation"] = True
215+
216+
with redshift_connector.connect(**idp_arg):
217+
pass

test/unit/test_iam_helper.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -781,12 +781,12 @@ def test_get_authentication_type_for_iam_with_plugin() -> None:
781781
(
782782
{"group_federation": True, "credentials_provider": "BrowserSamlCredentialsProvider"},
783783
IamHelper.IAMAuthenticationType.PLUGIN,
784-
"Authentication with plugin is not supported for group federation",
784+
IamHelper.GetClusterCredentialsAPIType.IAM_V2,
785785
),
786786
(
787787
{"is_serverless": True, "group_federation": True, "credentials_provider": "BrowserSamlCredentialsProvider"},
788788
IamHelper.IAMAuthenticationType.PLUGIN,
789-
"Authentication with plugin is not supported for group federation",
789+
IamHelper.GetClusterCredentialsAPIType.IAM_V2,
790790
),
791791
(
792792
{"is_serverless": True, "group_federation": True, "is_cname": True},

0 commit comments

Comments
 (0)