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

Python Regression: Issue with connecting to Azure SQL using User Managed Identity in #1008

Open
thomasfrederikhoeck opened this issue Nov 23, 2023 · 1 comment

Comments

@thomasfrederikhoeck
Copy link

There is a regression in newer releases of mcr.microsoft.com/azure-functions/python:4-python3.8-slim when connecting to an Azure SQL database when using User Managed Identity as authenication (the problem doesn't happen for Service Principal).

When the following python script runs on an docker image based on this older image it works fine
mcr.microsoft.com/azure-functions/python:4-python3.8-slim@sha256:691c02f8c5d40e8ee93f9d9af1ec4d815d524d8a6d11b473a819e5f3dbba7601

If I run in an image based on this newer image:
mcr.microsoft.com/azure-functions/python:4-python3.8-slim@sha256:74f2a9774e5b7f65965846cfd4b195177def72f283f4736760c1e43c12f66c0f I get Login timeout expired (0)

I connect ot the Azure SQL database using VNet Integration where the Function is joined into a subnet which is then whitelisted(https://learn.microsoft.com/en-us/azure/azure-functions/functions-networking-options?tabs=azure-cli) and I'm on a Premium App service plan.

import pyodbc 

driver = "ODBC Driver 17 for SQL Server"
server = "YOUR_SERVER_NAME.database.windows.net"
database = "YOUR_DB_NAME"
user = "CLIENT_ID_OF_USER_MANAGED_IDENTITY"
auth_type = "ActiveDirectoryMsi"


connect_params = [
        f"DRIVER={{{driver}}}",
        f"SERVER={{{server}}}",
        f"DATABASE={{{database}}}",
        "Encrypt=yes", 
        "TrustServerCertificate=no", 
        f"UID={{{user}}}", 
        f"Authentication={{{auth_type}}}",
        "Connection Timeout=30",    
        ]
        
conn = pyodbc.connect(";".join(connect_params))
@thomasfrederikhoeck
Copy link
Author

@kshyju Sorry for tag but I'm unsure if the issue is picked up directly here, or need to be reported via other channels as it seems to be the case for some Azure products :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant