Skip to content

Microsoft Azure Articles..

Strategy with Speed ensures Success!

  • About Me

Tag: private endpoint

Accessing Storage Account from VNET

January 13, 2020March 29, 2020 ~ Jean Paul ~ Leave a comment

In Azure, we can create Storage Account which is having a default Public URL.  Even though Credential Protection is there – Still it is exposed to Public Access.  This may cause issues with Enterprise Customers.

In this post we can see how to protect the Storage Account by preventing Public Access & Only allowing Access from VNET.

Pre-Requisites

For our experiment please create the following resources in same region:

  • App Service
  • Virtual Network (VNET)
    • Add a new Subnet named Frontend
  • Storage Account
    • Create a container named “my-blobs”
    • Upload a blob named readme.txt into the container

Create Sample Application

Create an Web API Sample Application which Reads data from a Blob Storage using code below.

Add namespaces Microsoft.Azure.Storage.Blob, Azure.Storage.Blob packages.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Azure.Storage.Blobs;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;

namespace jp_test_mvc.Controllers
{
     [ApiController]
     [Route(“[controller]”)]
     public class BlobController : ControllerBase
     {
         private readonly ILogger<WeatherForecastController> _logger;

        public BlobController(ILogger<WeatherForecastController> logger)
         {
             _logger = logger;
         }

        [HttpGet]
         public async string Get()
         {
             string result = string.Empty;

            try
             {
                 BlobServiceClient blobServiceClient = new BlobServiceClient(“connectionString”);
                 BlobContainerClient containerClient = blobServiceClient.GetBlobContainerClient(“my-blobs”);
                 BlobClient blobClient = containerClient.GetBlobClient(“readme.txt”);

                var response = await blobClient.DownloadAsync();
                 using (var streamReader = new StreamReader(response.Value.Content))
                 {
                     while (!streamReader.EndOfStream)
                         result += await streamReader.ReadLineAsync();
                 }
             }
             catch (Exception ex)
             {
                 result = ex.ToString();
             }

            return result;
         }
     }
}

Test the Application

Test the application URL & You should get the following result.

https://localhost:44309/blob

image

Modify the Storage Account Settings

Now go to the Storage Account > Firewall settings & Change the option to Selected Network option.  Save changes.

Test the application now & You should get the Exception below.

image

Add the VNET

Go to App Service > Networking > Configure VNET > Select Frontend Subnet
Go to Storage Account > Firewall > Add existing Virtual Network > Select Frontend

Test Again

Save Changes & Test Again
Now you should get the Contents of the Blob back as shown below.

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 35 other followers

Azure Cheatsheet

7 Habits

By month

  • September 2021 (1)
  • June 2020 (3)
  • May 2020 (6)
  • April 2020 (5)
  • March 2020 (8)
  • February 2020 (7)
  • January 2020 (9)
  • December 2019 (12)
  • November 2019 (5)
  • October 2019 (6)
  • September 2019 (2)
  • August 2019 (1)
  • June 2019 (1)
  • January 2019 (1)
  • November 2018 (1)
  • October 2018 (2)
  • September 2018 (5)
  • August 2018 (7)
  • July 2018 (6)
  • June 2018 (1)
  • May 2018 (1)
  • April 2018 (1)
  • March 2018 (3)
  • January 2018 (15)
  • December 2017 (1)

Search

Create a free website or blog at WordPress.com.
Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy
  • Follow Following
    • Microsoft Azure Articles..
    • Join 35 other followers
    • Already have a WordPress.com account? Log in now.
    • Microsoft Azure Articles..
    • Customize
    • Follow Following
    • Sign up
    • Log in
    • Report this content
    • View site in Reader
    • Manage subscriptions
    • Collapse this bar