<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Managed Identity Archives - AzureOps</title>
	<atom:link href="https://azureops.org/articles/category/azure/managed-identity/feed/" rel="self" type="application/rss+xml" />
	<link>https://azureops.org/articles/category/azure/managed-identity/</link>
	<description>Notable things about Cloud, Data and DevOps.</description>
	<lastBuildDate>Mon, 13 Oct 2025 14:27:22 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://i0.wp.com/azureops.org/wp-content/uploads/2021/04/cropped-android-chrome-512x512-1.png?fit=32%2C32&#038;ssl=1</url>
	<title>Managed Identity Archives - AzureOps</title>
	<link>https://azureops.org/articles/category/azure/managed-identity/</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">190208641</site>	<item>
		<title>Connect Python Azure Function to Azure SQL Using Managed Identity</title>
		<link>https://azureops.org/articles/connect-python-azure-function-to-azure-sql-using-managed-identity/</link>
		
		<dc:creator><![CDATA[Kunal Rathi]]></dc:creator>
		<pubDate>Thu, 18 Sep 2025 18:21:20 +0000</pubDate>
				<category><![CDATA[Azure]]></category>
		<category><![CDATA[Function]]></category>
		<category><![CDATA[Managed Identity]]></category>
		<category><![CDATA[Python]]></category>
		<guid isPermaLink="false">https://azureops.org/?p=8874</guid>

					<description><![CDATA[<p>An Azure Function is a lightweight, serverless compute option in Azure that lets you execute small chunks of code in response to events or schedules without managing servers. When connecting Azure Functions to Azure SQL Database, you need a secure way to authenticate without storing credentials. That’s where Managed Identity steps in. Managed Identity allows [&#8230;]</p>
<p>The post <a href="https://azureops.org/articles/connect-python-azure-function-to-azure-sql-using-managed-identity/">Connect Python Azure Function to Azure SQL Using Managed Identity</a> appeared first on <a href="https://azureops.org">AzureOps</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">An <strong>Azure Function</strong> is a lightweight, serverless compute option in Azure that lets you execute small chunks of code in response to events or schedules without managing servers. When connecting Azure Functions to <strong>Azure SQL Database</strong>, you need a secure way to authenticate without storing credentials. That’s where <strong>Managed Identity</strong> steps in. Managed Identity allows Azure resources (like Functions, VMs, Logic Apps) to access other Azure services securely by leveraging <strong>Azure Active Directory (AAD)</strong>.In this article, we’ll explore how to connect <a href="https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-python?tabs=get-started%2Casgi%2Capplication-level&amp;pivots=python-mode-decorators" target="_blank" rel="noreferrer noopener">Python Azure Function</a><strong> to Azure SQL</strong> using <strong>Managed Identity</strong>. You’ll learn step-by-step setup, Python code implementation, troubleshooting, and best practices to ensure your solution is secure and scalable.</p>



<h2 class="wp-block-heading">Why Use Managed Identity with Azure SQL?</h2>



<p class="wp-block-paragraph">Storing passwords in configuration files is risky. Managed Identity solves this problem by:</p>



<ul class="wp-block-list">
<li class=""><strong>Eliminating Secrets</strong> → No passwords, no connection strings with credentials.</li>



<li class=""><strong>Centralized Identity Management</strong> → Uses <strong>Azure AD authentication</strong> for consistency.</li>



<li class=""><strong>Least Privilege Principle</strong> → Assigns only the required SQL permissions.</li>



<li class=""><strong>Automatic Rotation</strong> → No need to update or rotate credentials manually.</li>
</ul>



<p class="wp-block-paragraph">This makes it the <strong>recommended authentication method</strong> when connecting Azure Functions to SQL Database.</p>



<p class="has-pale-cyan-blue-background-color has-background wp-block-paragraph"><strong>Prerequisites:</strong><br>Before implementing, ensure you have:<br>1. An Azure subscription.<br>2. An Azure SQL Database already created.<br>3. An Azure Function App (Python runtime).<br>4. Azure CLI or Portal access.</p>



<p class="wp-block-paragraph">This guide assumes you already have a basic understanding of creating an Azure Function. If you need a refresher, please refer to our previous article on <a href="https://azureops.org/articles/create-python-azure-function/" target="_blank" rel="noreferrer noopener">How to Create a Python Azure Function</a>.</p>



<p class="wp-block-paragraph">Let&#8217;s now see how to connect Python Azure Function to Azure SQL database using managed identity authentication. In this example we will fetch data from a public API and securely write it to an <strong>Azure SQL Database</strong> table..</p>



<h3 class="wp-block-heading">Step 1: Set Up Your Azure SQL Database</h3>



<h4 class="wp-block-heading">Creating WeatherData Table</h4>



<p class="wp-block-paragraph">In this guide, we’ll simulate fetching weather data from an API and storing it in Azure SQL.</p>



<p class="wp-block-paragraph">Run the following SQL script inside your Azure SQL database:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: sql; gutter: false; title: ; notranslate">
CREATE TABLE WeatherData (
    Id INT PRIMARY KEY IDENTITY(1,1),
    City VARCHAR(100),
    Temperature DECIMAL(5,2),
    Humidity INT,
    ForecastDate DATETIME
);

</pre></div>


<h3 class="wp-block-heading">Step 2: Enabling Managed Identity for Azure Function</h3>



<p class="wp-block-paragraph">INavigate to your <strong>Function App</strong> in Azure Portal.</p>



<p class="wp-block-paragraph">Under <strong>Settings → Identity</strong>, enable <strong>System Assigned Managed Identity</strong>.</p>



<p class="wp-block-paragraph">Azure will create an identity in Microsoft Entra representing your Function.</p>



<figure class="wp-block-image size-full is-resized"><a href="https://i0.wp.com/azureops.org/wp-content/uploads/2025/09/Enable-Azure-function-managed-identity.png?ssl=1"><img fetchpriority="high" decoding="async" width="1072" height="715" data-attachment-id="8884" data-permalink="https://azureops.org/articles/connect-python-azure-function-to-azure-sql-using-managed-identity/enable-azure-function-managed-identity/" data-orig-file="https://i0.wp.com/azureops.org/wp-content/uploads/2025/09/Enable-Azure-function-managed-identity.png?fit=1072%2C715&amp;ssl=1" data-orig-size="1072,715" data-comments-opened="0" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="Enable Azure function managed identity" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/azureops.org/wp-content/uploads/2025/09/Enable-Azure-function-managed-identity.png?fit=1072%2C715&amp;ssl=1" src="https://i0.wp.com/azureops.org/wp-content/uploads/2025/09/Enable-Azure-function-managed-identity.png?fit=1072%2C715&amp;ssl=1" alt="Connect Python Azure Function to Azure SQL" class="wp-image-8884" style="width:821px;height:auto" srcset="https://i0.wp.com/azureops.org/wp-content/uploads/2025/09/Enable-Azure-function-managed-identity.png?w=1072&amp;ssl=1 1072w, https://i0.wp.com/azureops.org/wp-content/uploads/2025/09/Enable-Azure-function-managed-identity.png?resize=300%2C200&amp;ssl=1 300w, https://i0.wp.com/azureops.org/wp-content/uploads/2025/09/Enable-Azure-function-managed-identity.png?resize=930%2C620&amp;ssl=1 930w, https://i0.wp.com/azureops.org/wp-content/uploads/2025/09/Enable-Azure-function-managed-identity.png?resize=768%2C512&amp;ssl=1 768w, https://i0.wp.com/azureops.org/wp-content/uploads/2025/09/Enable-Azure-function-managed-identity.png?resize=450%2C300&amp;ssl=1 450w, https://i0.wp.com/azureops.org/wp-content/uploads/2025/09/Enable-Azure-function-managed-identity.png?resize=600%2C400&amp;ssl=1 600w" sizes="(max-width: 1072px) 100vw, 1072px" /></a></figure>



<h3 class="wp-block-heading">Step 3: Grant the Managed Identity Access to Azure SQL</h3>



<h4 class="wp-block-heading">Configuring Azure Entra Admin</h4>



<p class="wp-block-paragraph">To allow <strong>Managed Identity</strong> to authenticate, assign an <strong>Azure Entra admin</strong> for your SQL server.</p>



<ol class="wp-block-list">
<li class="">Go to Azure Portal → SQL Server → <strong>Active Entra Admin</strong>.</li>



<li class="">Assign an Azure Entra user/group as the admin.</li>



<li class="">Save changes.</li>
</ol>



<h3 class="wp-block-heading">Grant the permissions</h3>



<p class="wp-block-paragraph">Now, connect to to your Azure SQL Database using the Entra ID authentication. You need to grant the Managed Identity permission to write to the database. Use the following T-SQL commands, replacing <code>&lt;your-azure-function-name&gt;</code> with the name of your function:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: sql; gutter: false; title: ; notranslate">
CREATE USER &#x5B;your-azure-function-name] FROM EXTERNAL PROVIDER;
ALTER ROLE db_datawriter ADD MEMBER &#x5B;your-azure-function-name];
</pre></div>


<ul class="wp-block-list">
<li class=""><code>CREATE USER</code> creates the identity inside SQL.</li>



<li class=""><code>ALTER ROLE</code> gives write permissions to insert/update/delete.</li>
</ul>



<p class="wp-block-paragraph">Learn how to grant access to Azure SQL databases in this <a href="https://azureops.org/articles/grant-access-to-azure-sql-database/" target="_blank" rel="noreferrer noopener">post</a>.</p>



<h3 class="wp-block-heading">Step 4: Configure Application Settings</h3>



<p class="wp-block-paragraph">In the Function App Environment variables, define following variables.</p>



<ul class="wp-block-list">
<li class=""><strong>SqlConnectionInfo</strong> → <code>Server=&lt;your-sql-server&gt;.database.windows.net;Database=&lt;your-db&gt;;</code></li>



<li class=""><strong>WEATHER_API_URL</strong> → https://api.open-meteo.com/v1/forecast?latitude=60.17&amp;longitude=24.94&amp;hourly=temperature_2m,relative_humidity_2m</li>



<li class=""><strong>TIMER_SCHEDULE</strong> → <code>0 * * * * *</code> (Runs every hour).</li>
</ul>



<figure class="wp-block-image size-full is-resized"><a href="https://i0.wp.com/azureops.org/wp-content/uploads/2025/09/Add-environment-variables-to-Azure-function.png?ssl=1"><img decoding="async" width="975" height="677" data-attachment-id="8886" data-permalink="https://azureops.org/articles/connect-python-azure-function-to-azure-sql-using-managed-identity/add-environment-variables-to-azure-function/" data-orig-file="https://i0.wp.com/azureops.org/wp-content/uploads/2025/09/Add-environment-variables-to-Azure-function.png?fit=975%2C677&amp;ssl=1" data-orig-size="975,677" data-comments-opened="0" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="Add environment variables to Azure function" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/azureops.org/wp-content/uploads/2025/09/Add-environment-variables-to-Azure-function.png?fit=975%2C677&amp;ssl=1" src="https://i0.wp.com/azureops.org/wp-content/uploads/2025/09/Add-environment-variables-to-Azure-function.png?fit=975%2C677&amp;ssl=1" alt="Azure Function configuration settings
" class="wp-image-8886" style="width:850px;height:auto" srcset="https://i0.wp.com/azureops.org/wp-content/uploads/2025/09/Add-environment-variables-to-Azure-function.png?w=975&amp;ssl=1 975w, https://i0.wp.com/azureops.org/wp-content/uploads/2025/09/Add-environment-variables-to-Azure-function.png?resize=300%2C208&amp;ssl=1 300w, https://i0.wp.com/azureops.org/wp-content/uploads/2025/09/Add-environment-variables-to-Azure-function.png?resize=893%2C620&amp;ssl=1 893w, https://i0.wp.com/azureops.org/wp-content/uploads/2025/09/Add-environment-variables-to-Azure-function.png?resize=768%2C533&amp;ssl=1 768w, https://i0.wp.com/azureops.org/wp-content/uploads/2025/09/Add-environment-variables-to-Azure-function.png?resize=450%2C312&amp;ssl=1 450w, https://i0.wp.com/azureops.org/wp-content/uploads/2025/09/Add-environment-variables-to-Azure-function.png?resize=600%2C417&amp;ssl=1 600w" sizes="(max-width: 975px) 100vw, 975px" /></a></figure>



<h3 class="wp-block-heading">Step 5: Writing Python Azure Function Code</h3>



<p class="wp-block-paragraph">Now, it&#8217;s time to write the code that will perform the data fetching and insertion. For this example, we&#8217;ll use a Python HTTP-triggered function and the <code>requests</code> and <code>pyodbc</code> libraries. You will also need the <code>azure-identity</code> package to handle the Managed Identity authentication.</p>



<h4 class="wp-block-heading">1. Installing Required Packages</h4>



<p class="wp-block-paragraph">Add to <code>requirements.txt</code>:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; gutter: false; title: ; notranslate">
azure-functions
requests
pypyodbc
</pre></div>


<h4 class="wp-block-heading">2. Write the function code (<code>__init__.py</code>):</h4>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: python; title: ; notranslate">
import azure.functions as func
import logging, os, requests, pypyodbc

app = func.FunctionApp()

@app.timer_trigger(schedule=&quot;%TIMER_SCHEDULE%&quot;, arg_name=&quot;myTimer&quot;)
def load_weather_data_to_sql(myTimer: func.TimerRequest):
    if myTimer.past_due:
        logging.info(&quot;The timer is past due!&quot;)

    try:
        url = os.getenv(&quot;WEATHER_API_URL&quot;)
        response = requests.get(url)
        data = response.json().get(&quot;current&quot;, {})
        
        temperature = data.get(&quot;temperature_2m&quot;)
        humidity = data.get(&quot;relative_humidity_2m&quot;)
        city = &quot;Berlin&quot;

        conn = get_sql_connection()
        cursor = conn.cursor()
        cursor.execute(
            &quot;INSERT INTO WeatherData (City, Temperature, Humidity, ForecastDate) VALUES (?, ?, ?, GETDATE())&quot;,
            (city, temperature, humidity)
        )
        conn.commit()
        cursor.close()
        conn.close()
        logging.info(&quot;Weather data inserted successfully&quot;)

    except Exception as e:
        logging.error(f&quot;Error: {e}&quot;)

def get_sql_connection():
    conn_info = os.getenv(&quot;SqlConnectionInfo&quot;)
    parts = dict(item.split(&quot;=&quot;,1) for item in conn_info.split(&quot;;&quot;) if &quot;=&quot; in item)
    server, db = parts.get(&quot;Server&quot;), parts.get(&quot;Database&quot;)
# Depending on the python version, select appropriate ODBC Driver. For latest version 3.12, use ODBC Driver 18. For previous versions, try ODBC Driver 17.
    conn_str = f&quot;DRIVER={{ODBC Driver 18 for SQL Server}};Server={server};Database={db};Authentication=ActiveDirectoryMsi;&quot;
    return pypyodbc.connect(conn_str)

</pre></div>


<figure class="is-style-default wp-block-image size-large is-resized"><a href="https://marketplace.visualstudio.com/items?itemName=AzureOps.ssiscatalogerpro&amp;ssr=false#overview" target="_blank" rel="noopener"><img data-recalc-dims="1" decoding="async" width="1200" height="148" data-attachment-id="4839" data-permalink="https://azureops.org/articles/azure-data-studio-for-sql-developers/scmw-horizontal-ad/" data-orig-file="https://i0.wp.com/azureops.org/wp-content/uploads/2023/01/SCMW-horizontal-ad.png?fit=1326%2C163&amp;ssl=1" data-orig-size="1326,163" data-comments-opened="0" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="SCMW-horizontal-ad" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/azureops.org/wp-content/uploads/2023/01/SCMW-horizontal-ad.png?fit=1200%2C148&amp;ssl=1" src="https://i0.wp.com/azureops.org/wp-content/uploads/2023/01/SCMW-horizontal-ad.png?resize=1200%2C148&#038;ssl=1" alt="" class="wp-image-4839" style="object-fit:cover;width:811px;height:99px" srcset="https://i0.wp.com/azureops.org/wp-content/uploads/2023/01/SCMW-horizontal-ad.png?resize=1200%2C148&amp;ssl=1 1200w, https://i0.wp.com/azureops.org/wp-content/uploads/2023/01/SCMW-horizontal-ad.png?resize=450%2C55&amp;ssl=1 450w, https://i0.wp.com/azureops.org/wp-content/uploads/2023/01/SCMW-horizontal-ad.png?resize=600%2C74&amp;ssl=1 600w, https://i0.wp.com/azureops.org/wp-content/uploads/2023/01/SCMW-horizontal-ad.png?resize=300%2C37&amp;ssl=1 300w, https://i0.wp.com/azureops.org/wp-content/uploads/2023/01/SCMW-horizontal-ad.png?resize=768%2C94&amp;ssl=1 768w, https://i0.wp.com/azureops.org/wp-content/uploads/2023/01/SCMW-horizontal-ad.png?w=1326&amp;ssl=1 1326w" sizes="(max-width: 1200px) 100vw, 1200px" /></a></figure>



<h3 class="wp-block-heading">Step 6: Testing the Integration</h3>



<h4 class="wp-block-heading">Running Function Locally</h4>



<ul class="wp-block-list">
<li class="">Use <strong>Azure Functions Core Tools</strong>.</li>



<li class="">Set local.settings.json with required env variables.</li>



<li class="">Test the API call and SQL insertion.</li>
</ul>



<h4 class="wp-block-heading">Deploying to Azure</h4>



<ul class="wp-block-list">
<li class="">Push code to Azure Function App.</li>



<li class="">Check logs in <strong>Application Insights</strong> or <code>Log Stream</code>.</li>



<li class="">Common Issues and Troubleshooting.</li>
</ul>



<h2 class="wp-block-heading">Best Practices for Secure and Scalable Integration</h2>



<ul class="wp-block-list">
<li class="">Use <strong>least privilege</strong> for SQL roles.</li>



<li class="">Store configs in <strong>Azure Key Vault</strong>.</li>



<li class="">Monitor using <strong>Azure Monitor + Application Insights</strong>.</li>



<li class="">Implement retry logic for transient failures.</li>
</ul>



<h2 class="wp-block-heading">FAQs</h2>


<div class="wp-block-uagb-faq uagb-faq__outer-wrap uagb-block-1f3f6ec0 uagb-faq-icon-row uagb-faq-layout-accordion uagb-faq-expand-first-true uagb-faq-inactive-other-true uagb-faq__wrap uagb-buttons-layout-wrap uagb-faq-equal-height     " data-faqtoggle="true" role="tablist"><div class="wp-block-uagb-faq-child uagb-faq-child__outer-wrap uagb-faq-item uagb-block-152cbd76 " role="tab" tabindex="0"><div class="uagb-faq-questions-button uagb-faq-questions">			<span class="uagb-icon uagb-faq-icon-wrap">
								<svg xmlns="https://www.w3.org/2000/svg" viewBox= "0 0 448 512"><path d="M432 256c0 17.69-14.33 32.01-32 32.01H256v144c0 17.69-14.33 31.99-32 31.99s-32-14.3-32-31.99v-144H48c-17.67 0-32-14.32-32-32.01s14.33-31.99 32-31.99H192v-144c0-17.69 14.33-32.01 32-32.01s32 14.32 32 32.01v144h144C417.7 224 432 238.3 432 256z"></path></svg>
							</span>
						<span class="uagb-icon-active uagb-faq-icon-wrap">
								<svg xmlns="https://www.w3.org/2000/svg" viewBox= "0 0 448 512"><path d="M400 288h-352c-17.69 0-32-14.32-32-32.01s14.31-31.99 32-31.99h352c17.69 0 32 14.3 32 31.99S417.7 288 400 288z"></path></svg>
							</span>
			<span class="uagb-question">Can I use User-Assigned Managed Identity instead of System-Assigned?</span></div><div class="uagb-faq-content"><p>Yes, both are supported. User-assigned is better for multiple Functions sharing one identity.</p></div></div><div class="wp-block-uagb-faq-child uagb-faq-child__outer-wrap uagb-faq-item uagb-block-588ab62f " role="tab" tabindex="0"><div class="uagb-faq-questions-button uagb-faq-questions">			<span class="uagb-icon uagb-faq-icon-wrap">
								<svg xmlns="https://www.w3.org/2000/svg" viewBox= "0 0 448 512"><path d="M432 256c0 17.69-14.33 32.01-32 32.01H256v144c0 17.69-14.33 31.99-32 31.99s-32-14.3-32-31.99v-144H48c-17.67 0-32-14.32-32-32.01s14.33-31.99 32-31.99H192v-144c0-17.69 14.33-32.01 32-32.01s32 14.32 32 32.01v144h144C417.7 224 432 238.3 432 256z"></path></svg>
							</span>
						<span class="uagb-icon-active uagb-faq-icon-wrap">
								<svg xmlns="https://www.w3.org/2000/svg" viewBox= "0 0 448 512"><path d="M400 288h-352c-17.69 0-32-14.32-32-32.01s14.31-31.99 32-31.99h352c17.69 0 32 14.3 32 31.99S417.7 288 400 288z"></path></svg>
							</span>
			<span class="uagb-question">What if I want read-only access to SQL?</span></div><div class="uagb-faq-content"><p>Assign the <code>db_datareader</code> role instead of <code>db_datawriter</code>.</p></div></div><div class="wp-block-uagb-faq-child uagb-faq-child__outer-wrap uagb-faq-item uagb-block-81419b26 " role="tab" tabindex="0"><div class="uagb-faq-questions-button uagb-faq-questions">			<span class="uagb-icon uagb-faq-icon-wrap">
								<svg xmlns="https://www.w3.org/2000/svg" viewBox= "0 0 448 512"><path d="M432 256c0 17.69-14.33 32.01-32 32.01H256v144c0 17.69-14.33 31.99-32 31.99s-32-14.3-32-31.99v-144H48c-17.67 0-32-14.32-32-32.01s14.33-31.99 32-31.99H192v-144c0-17.69 14.33-32.01 32-32.01s32 14.32 32 32.01v144h144C417.7 224 432 238.3 432 256z"></path></svg>
							</span>
						<span class="uagb-icon-active uagb-faq-icon-wrap">
								<svg xmlns="https://www.w3.org/2000/svg" viewBox= "0 0 448 512"><path d="M400 288h-352c-17.69 0-32-14.32-32-32.01s14.31-31.99 32-31.99h352c17.69 0 32 14.3 32 31.99S417.7 288 400 288z"></path></svg>
							</span>
			<span class="uagb-question">Does Managed Identity work with Elastic Pools?</span></div><div class="uagb-faq-content"><p>Yes, it works across all Azure SQL deployment models.</p></div></div><div class="wp-block-uagb-faq-child uagb-faq-child__outer-wrap uagb-faq-item uagb-block-9bb291eb " role="tab" tabindex="0"><div class="uagb-faq-questions-button uagb-faq-questions">			<span class="uagb-icon uagb-faq-icon-wrap">
								<svg xmlns="https://www.w3.org/2000/svg" viewBox= "0 0 448 512"><path d="M432 256c0 17.69-14.33 32.01-32 32.01H256v144c0 17.69-14.33 31.99-32 31.99s-32-14.3-32-31.99v-144H48c-17.67 0-32-14.32-32-32.01s14.33-31.99 32-31.99H192v-144c0-17.69 14.33-32.01 32-32.01s32 14.32 32 32.01v144h144C417.7 224 432 238.3 432 256z"></path></svg>
							</span>
						<span class="uagb-icon-active uagb-faq-icon-wrap">
								<svg xmlns="https://www.w3.org/2000/svg" viewBox= "0 0 448 512"><path d="M400 288h-352c-17.69 0-32-14.32-32-32.01s14.31-31.99 32-31.99h352c17.69 0 32 14.3 32 31.99S417.7 288 400 288z"></path></svg>
							</span>
			<span class="uagb-question">Is pypyodbc required or can I use pyodbc?</span></div><div class="uagb-faq-content"><p>In Azure Functions Linux consumption plan, <code>pypyodbc</code> works more reliably.</p></div></div><div class="wp-block-uagb-faq-child uagb-faq-child__outer-wrap uagb-faq-item uagb-block-e8d40354 " role="tab" tabindex="0"><div class="uagb-faq-questions-button uagb-faq-questions">			<span class="uagb-icon uagb-faq-icon-wrap">
								<svg xmlns="https://www.w3.org/2000/svg" viewBox= "0 0 448 512"><path d="M432 256c0 17.69-14.33 32.01-32 32.01H256v144c0 17.69-14.33 31.99-32 31.99s-32-14.3-32-31.99v-144H48c-17.67 0-32-14.32-32-32.01s14.33-31.99 32-31.99H192v-144c0-17.69 14.33-32.01 32-32.01s32 14.32 32 32.01v144h144C417.7 224 432 238.3 432 256z"></path></svg>
							</span>
						<span class="uagb-icon-active uagb-faq-icon-wrap">
								<svg xmlns="https://www.w3.org/2000/svg" viewBox= "0 0 448 512"><path d="M400 288h-352c-17.69 0-32-14.32-32-32.01s14.31-31.99 32-31.99h352c17.69 0 32 14.3 32 31.99S417.7 288 400 288z"></path></svg>
							</span>
			<span class="uagb-question">Can I connect to SQL Server on-prem using Managed Identity?</span></div><div class="uagb-faq-content"><p>Not directly. You’d need a Hybrid Connection or VPN.</p></div></div><div class="wp-block-uagb-faq-child uagb-faq-child__outer-wrap uagb-faq-item uagb-block-8a7feb69 " role="tab" tabindex="0"><div class="uagb-faq-questions-button uagb-faq-questions">			<span class="uagb-icon uagb-faq-icon-wrap">
								<svg xmlns="https://www.w3.org/2000/svg" viewBox= "0 0 448 512"><path d="M432 256c0 17.69-14.33 32.01-32 32.01H256v144c0 17.69-14.33 31.99-32 31.99s-32-14.3-32-31.99v-144H48c-17.67 0-32-14.32-32-32.01s14.33-31.99 32-31.99H192v-144c0-17.69 14.33-32.01 32-32.01s32 14.32 32 32.01v144h144C417.7 224 432 238.3 432 256z"></path></svg>
							</span>
						<span class="uagb-icon-active uagb-faq-icon-wrap">
								<svg xmlns="https://www.w3.org/2000/svg" viewBox= "0 0 448 512"><path d="M400 288h-352c-17.69 0-32-14.32-32-32.01s14.31-31.99 32-31.99h352c17.69 0 32 14.3 32 31.99S417.7 288 400 288z"></path></svg>
							</span>
			<span class="uagb-question">Azure function execution giving Error: Error during function execution: (&#8216;01000&#8217;, &#8220;[01000] [unixODBC][Driver Manager]Can&#8217;t open lib &#8216;ODBC Driver 17 for SQL Server&#8217; : file not found&#8221;)</span></div><div class="uagb-faq-content"><p>This error usually occurs due to mismatch of ODBC Driver version. Depending on the python version, select appropriate ODBC Driver. For latest version 3.12, use ODBC Driver 18. For previous versions, try ODBC Driver 17.</p></div></div></div>


<h2 class="wp-block-heading">Conclusion</h2>



<p class="wp-block-paragraph">By following these steps, you’ve securely connected a <strong>Python Azure Function</strong> to an <strong>Azure SQL Database</strong> using <strong>Managed Identity</strong>. This approach avoids hardcoding credentials, ensures automatic rotation, and aligns with cloud security best practices.</p>



<p class="wp-block-paragraph">With this foundation, you can extend the Function to handle more APIs, perform ETL pipelines, or automate reporting tasks, all while staying secure and compliant.</p>



<p class="has-background wp-block-paragraph" style="background-color:#beefca"><strong>Pro tips:</strong><br>1. Always prefer pypyodbc in Functions to avoid dependency issues.<br>2. Use retry policies when inserting data into SQL.<br>3. Keep Functions lightweight, offload heavy processing to Azure Data Factory or Microsoft Fabric.<br>4. If scaling out, validate SQL performance with connection pooling.<br>5. Learn how to <a href="https://azureops.org/articles/connect-azure-sql-from-data-factory-using-managed-identity/" target="_blank" rel="noreferrer noopener">connect to Azure SQL from Azure Data Factory</a> using managed identity.<br></p>



<h2 class="wp-block-heading">See more</h2>



<iframe width="700" height="394" src="https://www.youtube.com/embed/t2h6xNVFQkc" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>



<div class="wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex">
<div class="is-style-fill wp-block-button"><a class="wp-block-button__link has-white-color has-blush-light-purple-gradient-background has-text-color has-background has-link-color wp-element-button" href="https://azureops.org/product/ssis-catalog-migration-wizard-pro/" target="_blank" rel="noreferrer noopener">Download Now</a></div>
</div>

    <div class="xs_social_share_widget xs_share_url after_content 		main_content  wslu-style-1 wslu-share-box-shaped wslu-fill-colored wslu-none wslu-share-horizontal wslu-theme-font-no wslu-main_content">

		
        <ul>
			        </ul>
    </div> 
<p>The post <a href="https://azureops.org/articles/connect-python-azure-function-to-azure-sql-using-managed-identity/">Connect Python Azure Function to Azure SQL Using Managed Identity</a> appeared first on <a href="https://azureops.org">AzureOps</a>.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">8874</post-id>	</item>
		<item>
		<title>Create user assigned managed identity in Azure</title>
		<link>https://azureops.org/articles/create-user-assigned-managed-identity-in-azure/</link>
		
		<dc:creator><![CDATA[Kunal Rathi]]></dc:creator>
		<pubDate>Wed, 05 Jun 2024 17:26:48 +0000</pubDate>
				<category><![CDATA[Azure]]></category>
		<category><![CDATA[Managed Identity]]></category>
		<guid isPermaLink="false">https://azureops.org/?p=7114</guid>

					<description><![CDATA[<p>Managed identity in Azure simplifies access management by automatically associating service principals with resources, like creating apps in Microsoft Entra when setting up a data factory. It facilitates secure access to Azure SQL without managing credentials, supporting Azure AD authentication at no extra cost. Azure offers both system-assigned and user-assigned managed identities, with the latter being customizable in the Azure portal. This technique enhances security and ease of management in Azure environments.</p>
<p>The post <a href="https://azureops.org/articles/create-user-assigned-managed-identity-in-azure/">Create user assigned managed identity in Azure</a> appeared first on <a href="https://azureops.org">AzureOps</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph"><a href="https://learn.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/overview" target="_blank" rel="noreferrer noopener">Managed identity&nbsp;</a>is a&nbsp;<a href="https://learn.microsoft.com/en-us/azure/active-directory/develop/app-objects-and-service-principals" target="_blank" rel="noreferrer noopener">service principal</a>&nbsp;associated with resources in Azure. When we create a data factory in Azure, it automatically creates an app in Microsoft Entra. Suppose we want to connect Azure SQL using Azure Data Factory. In that case, we need to grant Azure Data Factory app access to the Azure SQL database like any other Microsoft Entra ID user. This makes access management more secure and easy.</p>



<h3 class="wp-block-heading">Benefits of using managed identity authentication</h3>



<p class="wp-block-paragraph">1. You don’t need to manage credentials in code.&nbsp;<br>2. You can use managed identities to authenticate to any resource that supports Azure AD authentication, including your applications.<br>3. Managed identities can be used at no extra cost.</p>



<h3 class="wp-block-heading">Types of managed identities</h3>



<p class="wp-block-paragraph">There are two types of managed identities:<br>1. System assigned managed identity – This is the identity that is associated with Azure resources like Azure Data Factory.<br>2. User-assigned managed identity – This identity is created and managed by user in Azure portal. Learn more about it&nbsp;<a href="https://learn.microsoft.com/en-us/entra/identity/managed-identities-azure-resources/how-manage-user-assigned-managed-identities?pivots=identity-mi-methods-azp" target="_blank" rel="noreferrer noopener">here</a>.</p>



<p class="wp-block-paragraph">This article will cover how to create user-assigned managed identity in Azure.</p>



<p class="wp-block-paragraph">1. Connect to Azure portal and click search for <a href="https://portal.azure.com/#create/Microsoft.ManagedIdentity" target="_blank" rel="noreferrer noopener">managed identity</a> resource. </p>



<p class="wp-block-paragraph">2. Provide a name for the UMI, review the options, and click ‘Review + create’.</p>



<figure class="wp-block-image size-full is-resized"><a href="https://i0.wp.com/azureops.org/wp-content/uploads/2024/05/image.png?ssl=1"><img data-recalc-dims="1" loading="lazy" decoding="async" width="1034" height="581" data-attachment-id="7813" data-permalink="https://azureops.org/articles/create-user-assigned-managed-identity-in-azure/image-21/" data-orig-file="https://i0.wp.com/azureops.org/wp-content/uploads/2024/05/image.png?fit=1034%2C581&amp;ssl=1" data-orig-size="1034,581" data-comments-opened="0" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="image" data-image-description="" data-image-caption="" data-large-file="https://i0.wp.com/azureops.org/wp-content/uploads/2024/05/image.png?fit=1034%2C581&amp;ssl=1" src="https://i0.wp.com/azureops.org/wp-content/uploads/2024/05/image.png?resize=1034%2C581&#038;ssl=1" alt="Create user assigned managed identity in Azure" class="wp-image-7813" style="width:970px;height:auto" srcset="https://i0.wp.com/azureops.org/wp-content/uploads/2024/05/image.png?w=1034&amp;ssl=1 1034w, https://i0.wp.com/azureops.org/wp-content/uploads/2024/05/image.png?resize=300%2C169&amp;ssl=1 300w, https://i0.wp.com/azureops.org/wp-content/uploads/2024/05/image.png?resize=768%2C432&amp;ssl=1 768w, https://i0.wp.com/azureops.org/wp-content/uploads/2024/05/image.png?resize=450%2C253&amp;ssl=1 450w, https://i0.wp.com/azureops.org/wp-content/uploads/2024/05/image.png?resize=600%2C337&amp;ssl=1 600w" sizes="(max-width: 1034px) 100vw, 1034px" /></a></figure>



<p class="wp-block-paragraph">That&#8217;s it. We have seen how to create user assigned managed identity in Azure.</p>



<h2 class="wp-block-heading">See more</h2>



<iframe width="700" height="394" src="https://www.youtube.com/embed/t2h6xNVFQkc" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>



<div class="wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex">
<div class="is-style-fill wp-block-button"><a class="wp-block-button__link has-white-color has-blush-light-purple-gradient-background has-text-color has-background has-link-color wp-element-button" href="https://azureops.org/product/ssis-catalog-migration-wizard-pro/" target="_blank" rel="noreferrer noopener">Download Now</a></div>
</div>

    <div class="xs_social_share_widget xs_share_url after_content 		main_content  wslu-style-1 wslu-share-box-shaped wslu-fill-colored wslu-none wslu-share-horizontal wslu-theme-font-no wslu-main_content">

		
        <ul>
			        </ul>
    </div> 
<p>The post <a href="https://azureops.org/articles/create-user-assigned-managed-identity-in-azure/">Create user assigned managed identity in Azure</a> appeared first on <a href="https://azureops.org">AzureOps</a>.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">7114</post-id>	</item>
	</channel>
</rss>
