Skip to main content

Shared Access Signature on Windows Azure - Overview

Until now we saw how we can work with Shared Access Signature on blobs, tables and queues on Windows Azure. In this post we will try to see how this mechanism works in more details.
The Shared Access Signature can be used from any language. Until now I have example only from C#, where we used the current API to make calls to generate and set the access policy. This is not the only way to generate and configure them. All this features are exposed on Windows Azure as a RES API that can be used very easily.
There are different ways to make the REST API calls; we can send the configuration items in the query string or in the body of the request. The most important think that we need to know is that each access policy that is created need to have a unique id (string) and a list of permissions. Each type of resources supports different permissions types:
  • Read – r
  • Add – a
  • Update – u
  • Delete - d
  • Process – p
  • List - l
For each resource that is used we need to define the permissions in a specific order. For example if we want to define for a table the add and the read permissions, we cannot defined the add permissions first and after that the read permissions. In the following I will order the permissions for each resource:
  • Table – raud
  • Container (blob container) – rwdl
  • Blob - rwd
  • Queue – raup
When we want to create a Shared Access Policy using the REST API we need to specify the following data (parameters):
  • REST URL
  • REST URL parameters
  • signedversion (sv)– represent the version of the Shared Access Policy. This need to use in the case you is using a Shared Access Policy version before 12/02/2012.
  • signedresource (sr, only for blobs) – define what resources from a blob are accessible. The supported values are “b” and “c”. When we specify “b” we grand access to the blob content and metadata. “c” need to be specify when we work with container, by using it we grand access to list of blobs and all blobs from that container.
  • tablename (tb, only for tables) – the name of the table that we want to share.
  • access policy – the access policy right on the given resource. We will talk about this resource later on.
  • signedidentifier (si) –unique identifier for each access policy that is defined. Using this id we can delete and update any access policy.
  • signature (sig) – the signature that is used to authenticate the request.
The access policy parameter is not form from only one parameter. This is a collection of parameters that need to be set. Using these parameters we defined the access policy rights. The following parameters need (can) be set for access policy:
  • signedstart (st) – the start time from when the access policy is valid
  • signedexpiry (se) – the end time of the access policy
  • signedpermissions (sp) – the permissions associated with the given resource
  • startpk (spk), startrk (srk), endpk (epk), endrk (erk) – only for tables, the start and end row key and partition key
If you are working with, the simple solution is to use the API directly from code. This will generate automatically the REST API calls. But we don’t need to create the calls by hand.
An interesting think about Shared Access Policy is the number of access policies that we can define. Each queue, table, blob or container can have maximum 5 access policies. For each access policies we can define how many access token we want.
A very common scenario when Shared Access Signature is used is when a consumer what to access a specific resources and we don’t want to manually creating the access policy for him. For this case we can define a service on a web role or on a worker role that create the access policy automatically.  Using this flow, it is very easy to control automatically the users that have access to a given resource. If the user needs to renew his token, the only think that need to do is to send a new request to the web role that generate the access token and renew the old one.
When we are using Shared Access Policy we should try to respect the following recommendations:
  • Don’t generate lifetime access token – Try not to have access token that expired in 10 year. The lifetime of an access token should be limited. If the token expired, than the user should request a new token (or you can have an automatically mechanism that renew the access policy).
  • Send the access token by HTTPS – Any user that has the access token can access your resources. Because of this try to use a secure connection when you send the access token to the consumer. A simple and safe way is HTTPS.
  • Clock skew – On different machines we can have different time. The maxim difference that is accepted between machines on Windows Azure is 300 seconds. If you set the start time of an access policy, try to have in mind this time period.
  • Group access policy – For each resource we can define maximum 5 access policies. Because of this we should group our access policies based on some logic. When we revoke an access policies, all access token for that access policy are invalidated.
In this post we saw we discuss about some particularities that Shared Access Policy have and how can be access using the REST API. This is a powerful feature and need to be used carefully, because we don’t want any person to have access our private data from blobs, tables or queues.

Tutorials about Shared Access Signature:
  1. Overview
  2. How to use Shared Access Signature with tables from Windows Azure
  3. How to use Shared Access Signature with blobs from Windows Azure
  4. How to use Shared Access Signature with queues from Windows Azure
  5. How to remove or edit a Shared Access Signature from Windows Azure 
  6. Some scenarios when we can use Shared Access Signature from Windows Azure

Comments

  1. What I would be interesting to know what are some real-life scenarios where shared-access signature is useful (in custom applications hosted on cloud that use tables, blobs or queues).

    ReplyDelete

Post a Comment

Popular posts from this blog

How to check in AngularJS if a service was register or not

There are cases when you need to check in a service or a controller was register in AngularJS.
For example a valid use case is when you have the same implementation running on multiple application. In this case, you may want to intercept the HTTP provider and add a custom step there. This step don’t needs to run on all the application, only in the one where the service exist and register.
A solution for this case would be to have a flag in the configuration that specify this. In the core you would have an IF that would check the value of this flag.
Another solution is to check if a specific service was register in AngularJS or not. If the service was register that you would execute your own logic.
To check if a service was register or not in AngularJS container you need to call the ‘has’ method of ‘inhector’. It will return TRUE if the service was register.
if ($injector.has('httpInterceptorService')) { $httpProvider.interceptors.push('httpInterceptorService&#…

ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded

Today blog post will be started with the following error when running DB tests on the CI machine:
threw exception: System.InvalidOperationException: The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer' registered in the application config file for the ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information. at System.Data.Entity.Infrastructure.DependencyResolution.ProviderServicesFactory.GetInstance(String providerTypeName, String providerInvariantName) This error happened only on the Continuous Integration machine. On the devs machines, everything has fine. The classic problem – on my machine it’s working. The CI has the following configuration:

TeamCity.NET 4.51EF 6.0.2VS2013
It seems that there …

Run native .NET application in Docker (.NET Framework 4.6.2)

Scope
The main scope of this post is to see how we can run a legacy application written in .NET Framework in Docker.

Context
First of all, let’s define what is a legacy application in our context. By a legacy application we understand an application that runs .NET Framework 3.5 or higher in a production environment where we don’t have any more the people or documentation that would help us to understand what is happening behind the scene.
In this scenarios, you might want to migrate the current solution from a standard environment to Docker. There are many advantages for such a migration, like:

Continuous DeploymentTestingIsolationSecurity at container levelVersioning ControlEnvironment Standardization
Until now, we didn’t had the possibility to run a .NET application in Docker. With .NET Core, there was support for .NET Core in Docker, but migration from a full .NET framework to .NET Core can be costly and even impossible. Not only because of lack of features, but also because once you…