Accessing Azure SQL Database from Azure Web App with VBScript and Azure Key Vault












1















How can I connect to SQL database hosted on Microsoft Azure without having credentials in plain text in my .asp files or config files in VBScript?



I want to have the database connection string stored in Azure Key Vault, and have the web app access the key vault to get the connection string and then connect to the database.



I have looked at a lot of Microsoft documentations but they are all in C#. My web app is all in VBScript and .asp files and I don't want to spend the time rebuilding the whole web app to ASP.NET/.aspx



Thank you










share|improve this question



























    1















    How can I connect to SQL database hosted on Microsoft Azure without having credentials in plain text in my .asp files or config files in VBScript?



    I want to have the database connection string stored in Azure Key Vault, and have the web app access the key vault to get the connection string and then connect to the database.



    I have looked at a lot of Microsoft documentations but they are all in C#. My web app is all in VBScript and .asp files and I don't want to spend the time rebuilding the whole web app to ASP.NET/.aspx



    Thank you










    share|improve this question

























      1












      1








      1


      1






      How can I connect to SQL database hosted on Microsoft Azure without having credentials in plain text in my .asp files or config files in VBScript?



      I want to have the database connection string stored in Azure Key Vault, and have the web app access the key vault to get the connection string and then connect to the database.



      I have looked at a lot of Microsoft documentations but they are all in C#. My web app is all in VBScript and .asp files and I don't want to spend the time rebuilding the whole web app to ASP.NET/.aspx



      Thank you










      share|improve this question














      How can I connect to SQL database hosted on Microsoft Azure without having credentials in plain text in my .asp files or config files in VBScript?



      I want to have the database connection string stored in Azure Key Vault, and have the web app access the key vault to get the connection string and then connect to the database.



      I have looked at a lot of Microsoft documentations but they are all in C#. My web app is all in VBScript and .asp files and I don't want to spend the time rebuilding the whole web app to ASP.NET/.aspx



      Thank you







      vb.net azure vbscript asp-classic azure-keyvault






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 10 '18 at 22:01









      Sunny YuSunny Yu

      83




      83
























          2 Answers
          2






          active

          oldest

          votes


















          0














          You don't need Azure Key Vault in this case.



          What you can do is to create a new App Setting in App Settings of Azure Web App, and make its value to be the connection string of your database. This will create an environment variable and you can access it with VBScript. This post shows how to access an environment variable with VBScript.






          share|improve this answer
























          • Thank you for the reply! However, I have a followup question/concern. I suppose environment variables aren't exposed to the client users correct? In other words, there is no way for a person to obtain the values of the environment variables, right? Thank you

            – Sunny Yu
            Nov 11 '18 at 21:37













          • Environment variables are the settings on the servers of your web app. It can only be accessed by the process or users that are on the servers. Your web app users won't be able to access it if you don't expose it via your web app. Environment variable

            – Chun Liu
            Nov 12 '18 at 1:31











          • How can I access the variables that are set under Azure Application Settings in VBScript? Like the variables under Application Settings and Connection Strings. It didn't work with the WScript.Shell object from the post you gave

            – Sunny Yu
            Nov 13 '18 at 18:32





















          0














          I found a way!



          If I want to use the environment variables set under App Settings:



          Set objWSH =  CreateObject("WScript.Shell")
          Set objUserVariables = objWSH.Environment("Process")
          Response.Write(objUserVariables("APPSETTING_testAppSet"))


          the prefix APPSETTING_ will be different if the variable is stored under Connection String



          One other way I was able to use is to store the DB connection string in the Azure Key Vault. And then use OAuth access token to access Azure Key Vault. In this method, you have to send a POST request to Azure with ClientID and ClientSecret in the request body, then you will get an access token from the HTTP response. After that, send a GET request to the Key Vault endpoint with the access token in the request header. Then you will get the value of the key vault secret from the HTTP response.



          Another way to do it is to use the MSI_ENDPOINT and MSI_SECRET and send the HTTP request to get the access token. And with that access token, you can access a key vault secret as well (you have to make sure that the Key Vault Access Policy is setup correctly).






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53243855%2faccessing-azure-sql-database-from-azure-web-app-with-vbscript-and-azure-key-vaul%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            You don't need Azure Key Vault in this case.



            What you can do is to create a new App Setting in App Settings of Azure Web App, and make its value to be the connection string of your database. This will create an environment variable and you can access it with VBScript. This post shows how to access an environment variable with VBScript.






            share|improve this answer
























            • Thank you for the reply! However, I have a followup question/concern. I suppose environment variables aren't exposed to the client users correct? In other words, there is no way for a person to obtain the values of the environment variables, right? Thank you

              – Sunny Yu
              Nov 11 '18 at 21:37













            • Environment variables are the settings on the servers of your web app. It can only be accessed by the process or users that are on the servers. Your web app users won't be able to access it if you don't expose it via your web app. Environment variable

              – Chun Liu
              Nov 12 '18 at 1:31











            • How can I access the variables that are set under Azure Application Settings in VBScript? Like the variables under Application Settings and Connection Strings. It didn't work with the WScript.Shell object from the post you gave

              – Sunny Yu
              Nov 13 '18 at 18:32


















            0














            You don't need Azure Key Vault in this case.



            What you can do is to create a new App Setting in App Settings of Azure Web App, and make its value to be the connection string of your database. This will create an environment variable and you can access it with VBScript. This post shows how to access an environment variable with VBScript.






            share|improve this answer
























            • Thank you for the reply! However, I have a followup question/concern. I suppose environment variables aren't exposed to the client users correct? In other words, there is no way for a person to obtain the values of the environment variables, right? Thank you

              – Sunny Yu
              Nov 11 '18 at 21:37













            • Environment variables are the settings on the servers of your web app. It can only be accessed by the process or users that are on the servers. Your web app users won't be able to access it if you don't expose it via your web app. Environment variable

              – Chun Liu
              Nov 12 '18 at 1:31











            • How can I access the variables that are set under Azure Application Settings in VBScript? Like the variables under Application Settings and Connection Strings. It didn't work with the WScript.Shell object from the post you gave

              – Sunny Yu
              Nov 13 '18 at 18:32
















            0












            0








            0







            You don't need Azure Key Vault in this case.



            What you can do is to create a new App Setting in App Settings of Azure Web App, and make its value to be the connection string of your database. This will create an environment variable and you can access it with VBScript. This post shows how to access an environment variable with VBScript.






            share|improve this answer













            You don't need Azure Key Vault in this case.



            What you can do is to create a new App Setting in App Settings of Azure Web App, and make its value to be the connection string of your database. This will create an environment variable and you can access it with VBScript. This post shows how to access an environment variable with VBScript.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 11 '18 at 13:27









            Chun LiuChun Liu

            38828




            38828













            • Thank you for the reply! However, I have a followup question/concern. I suppose environment variables aren't exposed to the client users correct? In other words, there is no way for a person to obtain the values of the environment variables, right? Thank you

              – Sunny Yu
              Nov 11 '18 at 21:37













            • Environment variables are the settings on the servers of your web app. It can only be accessed by the process or users that are on the servers. Your web app users won't be able to access it if you don't expose it via your web app. Environment variable

              – Chun Liu
              Nov 12 '18 at 1:31











            • How can I access the variables that are set under Azure Application Settings in VBScript? Like the variables under Application Settings and Connection Strings. It didn't work with the WScript.Shell object from the post you gave

              – Sunny Yu
              Nov 13 '18 at 18:32





















            • Thank you for the reply! However, I have a followup question/concern. I suppose environment variables aren't exposed to the client users correct? In other words, there is no way for a person to obtain the values of the environment variables, right? Thank you

              – Sunny Yu
              Nov 11 '18 at 21:37













            • Environment variables are the settings on the servers of your web app. It can only be accessed by the process or users that are on the servers. Your web app users won't be able to access it if you don't expose it via your web app. Environment variable

              – Chun Liu
              Nov 12 '18 at 1:31











            • How can I access the variables that are set under Azure Application Settings in VBScript? Like the variables under Application Settings and Connection Strings. It didn't work with the WScript.Shell object from the post you gave

              – Sunny Yu
              Nov 13 '18 at 18:32



















            Thank you for the reply! However, I have a followup question/concern. I suppose environment variables aren't exposed to the client users correct? In other words, there is no way for a person to obtain the values of the environment variables, right? Thank you

            – Sunny Yu
            Nov 11 '18 at 21:37







            Thank you for the reply! However, I have a followup question/concern. I suppose environment variables aren't exposed to the client users correct? In other words, there is no way for a person to obtain the values of the environment variables, right? Thank you

            – Sunny Yu
            Nov 11 '18 at 21:37















            Environment variables are the settings on the servers of your web app. It can only be accessed by the process or users that are on the servers. Your web app users won't be able to access it if you don't expose it via your web app. Environment variable

            – Chun Liu
            Nov 12 '18 at 1:31





            Environment variables are the settings on the servers of your web app. It can only be accessed by the process or users that are on the servers. Your web app users won't be able to access it if you don't expose it via your web app. Environment variable

            – Chun Liu
            Nov 12 '18 at 1:31













            How can I access the variables that are set under Azure Application Settings in VBScript? Like the variables under Application Settings and Connection Strings. It didn't work with the WScript.Shell object from the post you gave

            – Sunny Yu
            Nov 13 '18 at 18:32







            How can I access the variables that are set under Azure Application Settings in VBScript? Like the variables under Application Settings and Connection Strings. It didn't work with the WScript.Shell object from the post you gave

            – Sunny Yu
            Nov 13 '18 at 18:32















            0














            I found a way!



            If I want to use the environment variables set under App Settings:



            Set objWSH =  CreateObject("WScript.Shell")
            Set objUserVariables = objWSH.Environment("Process")
            Response.Write(objUserVariables("APPSETTING_testAppSet"))


            the prefix APPSETTING_ will be different if the variable is stored under Connection String



            One other way I was able to use is to store the DB connection string in the Azure Key Vault. And then use OAuth access token to access Azure Key Vault. In this method, you have to send a POST request to Azure with ClientID and ClientSecret in the request body, then you will get an access token from the HTTP response. After that, send a GET request to the Key Vault endpoint with the access token in the request header. Then you will get the value of the key vault secret from the HTTP response.



            Another way to do it is to use the MSI_ENDPOINT and MSI_SECRET and send the HTTP request to get the access token. And with that access token, you can access a key vault secret as well (you have to make sure that the Key Vault Access Policy is setup correctly).






            share|improve this answer




























              0














              I found a way!



              If I want to use the environment variables set under App Settings:



              Set objWSH =  CreateObject("WScript.Shell")
              Set objUserVariables = objWSH.Environment("Process")
              Response.Write(objUserVariables("APPSETTING_testAppSet"))


              the prefix APPSETTING_ will be different if the variable is stored under Connection String



              One other way I was able to use is to store the DB connection string in the Azure Key Vault. And then use OAuth access token to access Azure Key Vault. In this method, you have to send a POST request to Azure with ClientID and ClientSecret in the request body, then you will get an access token from the HTTP response. After that, send a GET request to the Key Vault endpoint with the access token in the request header. Then you will get the value of the key vault secret from the HTTP response.



              Another way to do it is to use the MSI_ENDPOINT and MSI_SECRET and send the HTTP request to get the access token. And with that access token, you can access a key vault secret as well (you have to make sure that the Key Vault Access Policy is setup correctly).






              share|improve this answer


























                0












                0








                0







                I found a way!



                If I want to use the environment variables set under App Settings:



                Set objWSH =  CreateObject("WScript.Shell")
                Set objUserVariables = objWSH.Environment("Process")
                Response.Write(objUserVariables("APPSETTING_testAppSet"))


                the prefix APPSETTING_ will be different if the variable is stored under Connection String



                One other way I was able to use is to store the DB connection string in the Azure Key Vault. And then use OAuth access token to access Azure Key Vault. In this method, you have to send a POST request to Azure with ClientID and ClientSecret in the request body, then you will get an access token from the HTTP response. After that, send a GET request to the Key Vault endpoint with the access token in the request header. Then you will get the value of the key vault secret from the HTTP response.



                Another way to do it is to use the MSI_ENDPOINT and MSI_SECRET and send the HTTP request to get the access token. And with that access token, you can access a key vault secret as well (you have to make sure that the Key Vault Access Policy is setup correctly).






                share|improve this answer













                I found a way!



                If I want to use the environment variables set under App Settings:



                Set objWSH =  CreateObject("WScript.Shell")
                Set objUserVariables = objWSH.Environment("Process")
                Response.Write(objUserVariables("APPSETTING_testAppSet"))


                the prefix APPSETTING_ will be different if the variable is stored under Connection String



                One other way I was able to use is to store the DB connection string in the Azure Key Vault. And then use OAuth access token to access Azure Key Vault. In this method, you have to send a POST request to Azure with ClientID and ClientSecret in the request body, then you will get an access token from the HTTP response. After that, send a GET request to the Key Vault endpoint with the access token in the request header. Then you will get the value of the key vault secret from the HTTP response.



                Another way to do it is to use the MSI_ENDPOINT and MSI_SECRET and send the HTTP request to get the access token. And with that access token, you can access a key vault secret as well (you have to make sure that the Key Vault Access Policy is setup correctly).







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 21 '18 at 20:07









                Sunny YuSunny Yu

                83




                83






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53243855%2faccessing-azure-sql-database-from-azure-web-app-with-vbscript-and-azure-key-vaul%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    To store a contact into the json file from server.js file using a class in NodeJS

                    Redirect URL with Chrome Remote Debugging Android Devices

                    Dieringhausen