Until few months ago, Shared Access Signature (SAS) could be used only wilt Azure Storage (Blobs, Tables and Queues). From now one we can use SAS with Service Bus. We can define SAS to use in combination with topics, queues or notification hub
This security feature is pretty great, especially when you have an application that use 3rd party. You don’t need any more to share with 3rd parties the account name and key. From now one you can give them a unique token that give them access to some part of your namespace services and also limit what kind of operation they are allow to do.
In this moment you are allow to define only 12 rules in a namespace, but in the near future I expect to be able to define more than 12 rules.
The access rights that can be controlled in this moment are:
The interesting thing is how the rules are defined. The rules are defined over a URL. This means that you can define a rule over a namespace or over a specific topic or queue. The SAS will be valid for all resources under the specific URL.
When you generate a SAS rule, two keys will be generated for the same rules. Both keys can be used in the same time. This is done to help customers in the moment when they need to generate new keys and they don’t want to block the access to Service Bus.
The SAS rules can be defined and manage not only from code (using REST API) but also from the management portal of Azure. The portal can be very helpful when you are in the development phase or you have some issues with SAS and you want to check what rules are already defined.
How to create a SAS from code
First step is to create a SharedAccessAuthorizationRule and set the specific rights.
Once the rule is created, you can add it to the queue, topic or notification hub using the description class
How to use a SAS key
Once you created the rule and have the name and the key of the rule, you will be able to use them in the moment when you create the MessagingFactory.
Enjoy!
This security feature is pretty great, especially when you have an application that use 3rd party. You don’t need any more to share with 3rd parties the account name and key. From now one you can give them a unique token that give them access to some part of your namespace services and also limit what kind of operation they are allow to do.
In this moment you are allow to define only 12 rules in a namespace, but in the near future I expect to be able to define more than 12 rules.
The access rights that can be controlled in this moment are:
- Listen – to be able to receive message
- Send – to be able to send messages
- Manage – to be able to manage the resource
The interesting thing is how the rules are defined. The rules are defined over a URL. This means that you can define a rule over a namespace or over a specific topic or queue. The SAS will be valid for all resources under the specific URL.
When you generate a SAS rule, two keys will be generated for the same rules. Both keys can be used in the same time. This is done to help customers in the moment when they need to generate new keys and they don’t want to block the access to Service Bus.
The SAS rules can be defined and manage not only from code (using REST API) but also from the management portal of Azure. The portal can be very helpful when you are in the development phase or you have some issues with SAS and you want to check what rules are already defined.
How to create a SAS from code
First step is to create a SharedAccessAuthorizationRule and set the specific rights.
SharedAccessAuthorizationRule saar = new SharedAccessAuthorizationRule(
“myFooName”,
SharedAccessAuthorizationRule.GenerateRandomKey(),
new[] {
AccessRights.Manage,
AccessRights.Listen,
AccessRights.Send }));
GenerateRandomKey method is used to generate random keys.Once the rule is created, you can add it to the queue, topic or notification hub using the description class
QueueDescription qd = …
qd.Autothorization.Add(saar);
Don’t forget to save the name of the name and the key of the rule.How to use a SAS key
Once you created the rule and have the name and the key of the rule, you will be able to use them in the moment when you create the MessagingFactory.
MessagingFactory mf = MessagingFactory.Create(
"uri,
TokenProvider.CreateSharedAccessSignatureTokenProvider"myFooName", "myFooKey"));
QueueClient queue = mf.CreateQueueClient("myFooQueue");
Enjoy!
I am creating a client-server application and need to let the clients create a subscription to a topic. But creating a subscription client seems like it needs the Manage right. Is it possible to create a subscription client only having the Listen right?
ReplyDeleteNo, it is not possible. You need Manage rights to create a subscription.
Delete