Skip to content

Commit c2150f9

Browse files
sfc-gh-pmansoursfc-gh-pczajka
authored andcommitted
Accept both v1 and v2 Entra ID issuer formats for WIF (#2281)
1 parent 906ab16 commit c2150f9

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/snowflake/connector/wif_util.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,10 @@ def create_azure_attestation(
238238
issuer, subject = extract_iss_and_sub_without_signature_verification(jwt_str)
239239
if not issuer or not subject:
240240
return None
241-
if not issuer.startswith("https://sts.windows.net/"):
241+
if not (
242+
issuer.startswith("https://sts.windows.net/")
243+
or issuer.startswith("https://login.microsoftonline.com/")
244+
):
242245
# This might happen if we're running on a different platform that responds to the same metadata request signature as Azure.
243246
logger.debug("Unexpected Azure token issuer '%s'", issuer)
244247
return None

test/unit/test_auth_workload_identity.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,14 +240,32 @@ def test_explicit_azure_metadata_server_error_raises_auth_error(exception):
240240

241241

242242
def test_explicit_azure_wrong_issuer_raises_error(fake_azure_metadata_service):
243-
fake_azure_metadata_service.iss = "not-azure"
243+
fake_azure_metadata_service.iss = "https://notazure.com"
244244

245245
auth_class = AuthByWorkloadIdentity(provider=AttestationProvider.AZURE)
246246
with pytest.raises(ProgrammingError) as excinfo:
247247
auth_class.prepare()
248248
assert "No workload identity credential was found for 'AZURE'" in str(excinfo.value)
249249

250250

251+
@pytest.mark.parametrize(
252+
"issuer",
253+
[
254+
"https://sts.windows.net/067802cd-8f92-4c7c-bceb-ea8f15d31cc5",
255+
"https://login.microsoftonline.com/067802cd-8f92-4c7c-bceb-ea8f15d31cc5",
256+
"https://login.microsoftonline.com/067802cd-8f92-4c7c-bceb-ea8f15d31cc5/v2.0",
257+
],
258+
ids=["v1", "v2_without_suffix", "v2_with_suffix"],
259+
)
260+
def test_explicit_azure_v1_and_v2_issuers_accepted(fake_azure_metadata_service, issuer):
261+
fake_azure_metadata_service.iss = issuer
262+
263+
auth_class = AuthByWorkloadIdentity(provider=AttestationProvider.AZURE)
264+
auth_class.prepare()
265+
266+
assert issuer == json.loads(auth_class.assertion_content)["iss"]
267+
268+
251269
def test_explicit_azure_plumbs_token_to_api(fake_azure_metadata_service):
252270
auth_class = AuthByWorkloadIdentity(provider=AttestationProvider.AZURE)
253271
auth_class.prepare()

0 commit comments

Comments
 (0)