<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Praveen Kumar Behara on Medium]]></title>
        <description><![CDATA[Stories by Praveen Kumar Behara on Medium]]></description>
        <link>https://medium.com/@praveenbehara?source=rss-392d1811056e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ztRpY2ODGRNtu7h9IaZA7A.jpeg</url>
            <title>Stories by Praveen Kumar Behara on Medium</title>
            <link>https://medium.com/@praveenbehara?source=rss-392d1811056e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 11:21:04 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@praveenbehara/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Leveraging Azure Devops Pipelines to pass secret / keys to a container running on Azure Web App]]></title>
            <link>https://medium.com/@praveenbehara/leveraging-azure-devops-pipelines-to-pass-secret-keys-to-a-container-running-on-azure-web-app-d918896df894?source=rss-392d1811056e------2</link>
            <guid isPermaLink="false">https://medium.com/p/d918896df894</guid>
            <category><![CDATA[azure-app-service]]></category>
            <category><![CDATA[storing-secrets]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[flask]]></category>
            <category><![CDATA[azure-devops-pipeline]]></category>
            <dc:creator><![CDATA[Praveen Kumar Behara]]></dc:creator>
            <pubDate>Fri, 03 Feb 2023 17:32:50 GMT</pubDate>
            <atom:updated>2024-11-08T12:11:48.066Z</atom:updated>
            <cc:license>http://creativecommons.org/licenses/by/4.0/</cc:license>
            <content:encoded><![CDATA[<h3>Deploying Python WebAPI code having secrets from Azure Devops to an Azure Web App</h3><p>Yeah, the title is a mouthful.. but that is the only way I could put it across.</p><figure><img alt="A chipmunk with its mouth full (a parody on the length of the article’s title )" src="https://cdn-images-1.medium.com/max/1024/0*MJiWr1T141wyVKXw" /><figcaption>Photo by <a href="https://unsplash.com/@unknown_613?utm_source=medium&amp;utm_medium=referral">alex lauzon</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4>How it started</h4><p>Basically, we had a small Python Web API project where we had to consume an Azure service. In order to connect to the service, we had to use (and therefore store) a “key” in our configuration. Even though it was a sort of PoC, client insisted that as per their IT rules, we have to encrypt the content and should not be a basic encoded string (otherwise, anyone can decode it. duh!!).</p><p>So, we pitched that we can probably use an Azure Key Vault service. But the problem still remained, since now we have to store the key to the key vault itself. (We still haven’t figured out how to use role-based access).</p><h4>Our Code Setup</h4><ol><li>Application is a simple Flask application that has some mock product APIs.</li><li>A Docker image is created using a corresponding <em>Dockerfile</em> and pushed into an Azure Container Registry.</li></ol><p>The sample code can be found <a href="https://github.com/praveenbehara/azure_devops_pipeline_example">here</a>.</p><h4>DevOps pipelines to the rescue</h4><p>A partner team suggested that we can probably store these “limited” configuration items as a variable inside the pipelines. The process is illustrated below.</p><figure><img alt="Azure DevOps Pipeline — secret variable creation process" src="https://cdn-images-1.medium.com/max/595/1*j3M0qFdpL96bBSuKIpDDDg.gif" /><figcaption>Azure DevOps Pipeline — secret variable creation process</figcaption></figure><p>The “<em>Keep this value secret</em>” encrypts the data, while the “<em>Let users override this value when running this pipeline</em>” option allows you to change the value during a manual run.</p><p>Now, all we have to do is expect these things as environment variables. Alas, I wished it was that easy. When we tried accessing the variable inside the executing container as an environment variable, we see that an environment variable has not been exposed.</p><p>This is when we catch the glimpse of a small note on the variable creation screen about “secret” variables right at the bottom.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/538/1*Sn4mve_5es_Pp0qn2bSjfQ.png" /></figure><h4>Changes to the pipeline</h4><p>The trick is to map this variable to an environment during the <em>Build </em>phase of the CI pipeline execution.</p><p>Note: You need to have “separate” <em>Build</em> and <em>Push</em> stages. You cannot use the “<em>Build and Push</em>” stage since it does not take Build arguments.</p><p>The Docker@2 code from the yaml file is shown below… The last <em>arguments</em> line is what we had to add.</p><pre>    - task: Docker@2<br>      displayName: Build the image<br>      inputs:<br>        command: build<br>        repository: $(imageRepository)<br>        dockerfile: $(dockerfilePath)<br>        containerRegistry: $(dockerRegistryServiceConnection)<br>        tags: |<br>          $(tag)<br>        arguments: &#39;--build-arg AZURE_OPENAI_KEY=$(AZURE_OPENAI_KEY)&#39;</pre><p>Btw, if someone is using the classic pipelines and stuck with using Docker@0, the parameters are slightly different. Here, we would need to specify <em>buildArguments</em>.</p><pre>  - task: Docker@0<br>    displayName: Build an image<br>    inputs:<br>      azureSubscriptionEndpoint: &lt;data masked&gt;<br>      azureContainerRegistry: &#39;&lt;data masked&gt;&#39;<br>      dockerFile: **/Dockerfile<br>      buildArguments: AZURE_OPENAI_KEY=$(AZURE_OPENAI_KEY)<br>      imageName: &lt;data masked&gt;:$(Build.BuildId)<br>      additionalImageTags: &lt;data masked&gt;</pre><p>Though, I am not 100% certain, if we use the classic editor UI, I believe you will configure something like this.</p><figure><img alt="Build Arguments textbox while using Classic Editor" src="https://cdn-images-1.medium.com/max/1024/1*COWdLCa3ojUxN8S5asWseA.png" /><figcaption>Build Arguments textbox while using Classic Editor</figcaption></figure><h4>Changes in the Dockerfile</h4><p>Add the following two lines to the Dockerfile just after the image import statement i.e. FROM &lt;image name&gt;</p><pre>ARG AZURE_OPENAI_KEY<br>ENV AZURE_OPENAI_KEY=$AZURE_OPENAI_KEY</pre><h4>Go time</h4><p>When the image is built, it would show the ARG as *** and hence there is no fear of logging this secret variable.</p><p>In the python code, we can access the secret variable data like any other environment variable.</p><pre>secret = os.getenv(&#39;AZURE_OPENAI_KEY&#39;)</pre><p>Hope I covered the aspects that you are expecting. If you felt that something is missing, please leave a comment.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d918896df894" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>