URI and SAS Parameters – Azure Storage

If you take the blob service, the default endpoint will be https://<storage-account-name>.blob.core.windows.net. For example, if the name of the storage account is mystorage01, the blob endpoint will be https://mystorage01.blob.core.windows.net. You can divide the URI into two parts: storage resource URI and the SAS token (see Figure 6.11).

FIGURE 6.11 Storage URI

Let’s take a sample URI to explain the parameters. The following is an example URI:

https://mystorage01.blob.core.windows.net/?restype=service&comp=properties&sv=2015-04-05&ss=bf&srt=s&st=2015-04-29T22%3A18%3A26Z&se=2015-04-30T02%3A23%3A26Z&sr=b&sp=rw&sip=168.1.5.60-168.1.5.70&spr=https&sig=F%6GRVAZ5Cdj2Pw4txxxxx

Refer to Table 6.5 to understand each of the parameters.

TABLE 6.5 Understanding URI Parameters

ParameterURI portionDescription
Resource URIhttps://mystorage01.blob.core.windows.net/?restype=service&comp=propertiesThe blob endpoint; to get the service properties, you can make a GET call to this endpoint.
Storage services versionsv=2015-04-05The version of the storage service.
Servicesss=bfSAS applies to two services b=blob and f=file.
Resource typessrt=sAccess is granted for service-level operations, s=service.
Start timest=2015-04-29T22%3A18%3A26ZStart time of the SAS in UTC.
Expiry timese=2015-04-30T02%3A23%3A26ZExpiry time in UTC.
Resourcesr=bSelected resource is a blob.
Permissionssp=rwPermission to read and write.
IP rangesip=168.1.5.60-168.1.5.70The IP address range.
Protocolspr=httpsOnly HTTPS requests are permitted.
Signaturesig=F%6GRVAZ5Cdj2Pw4txxxxxSignature that is used to authenticate access to the blob. The signature is an HMAC computed over a string-to-sign and key using the SHA256 algorithm and then encoded using Base64 encoding.

In the next exercise, you will use the SAS to access the blob you stored in Exercise 6.1. If you have deleted the storage account, you need to re-create a new storage account and a public container and upload an image to the container. Try copying the link of the image and check if you can access the image. If everything is configured correctly, you should be able to see the image in the browser. We will reuse the container and blob to demonstrate how the SAS keys work.

EXERCISE 6.2
 Working with SAS Keys

  1. Sign in to the Azure Portal and search for Storage Accounts.
  2. Open the storage account you created in Exercise 6.1. If you don’t have a storage account, create a new one using the steps outlined in Exercise 6.1.
  3. Open the existing container and verify you can see the blob. If you are working with a new container, make sure you upload an image to the container for testing.
  4. Click Change Access Level at the top and change it to Private. Changing it to Private will block all anonymous access to the container. Click OK to save the changes.  
  1. Click the stored blob and copy the link. Try accessing the link from the browser. You will get a ResourceNotFound error. This is because you have blocked all anonymous access to the container by setting the access level to Private.
  2. Remember the SAS key that you copied earlier. If not, generate a new SAS key with all the permissions shown in Figure 6.9.
  3. Append the SAS URL to the end of the link you pasted earlier and check if you are able to access the object stored in the storage account. As you can see, with SAS in the URL, you are able to see the image.

If you need, you can customize the parameters in the SAS key and generate a different URL based on your requirements. Next, we will cover Storage Service Encryption, which is responsible for protecting data at rest.

Leave a Reply

Your email address will not be published. Required fields are marked *