Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
434 views
in Technique[技术] by (71.8m points)

Azure Storage - Restrict IP in SAS when using Stored Access Policy

In Azure Storage Accounts, I've started using the SAS (Shared Access Signature) and SAP (Stored Access Policy) to secure access to specific queues in Azure Storage Queues.

What I'd like to achieve is restricting specific IP's to specific queues (1.1.1.1 can access queueA but 2.2.2.2 can't).

Currently I've seen I can use the Storage Account level SAS to restrict IP's, as well as set restrictions in the Networking section of the Portal. These don't quite cut it.

(I am aware of the following question, but wasn't satisfied with the responses, which say to try setting the Networking of the Storage Account - Is it possible to filtre on IP address for Azure STORAGE SAS with ACCESS POLICY?)

Thanks

question from:https://stackoverflow.com/questions/65924663/azure-storage-restrict-ip-in-sas-when-using-stored-access-policy

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can use code to create a service SAS token for that queue(for example, the queue named queueA), then associate it with Stored Access Policy.

For example(please modify the code to meet your need):

        QueueClient queueClient = new QueueClient(connectionString, "queueA");

        //create a service SAS 
        QueueSasBuilder sasBuilder = new QueueSasBuilder()
        {
            QueueName = "queueA",

            //set the ip here
            IPRange = new SasIPRange(IPAddress.Parse("172.16.0.1"))
        };

        //associate the service SAS with the Stored Access Policy
        sasBuilder.Identifier = storedPolicyName;

        //then you can use this uri with sas token to operate this queue
        Uri sasUri = queueClient.GenerateSasUri(sasBuilder);

For more details, you can refer to this article(it's for blob storage, but you can easy to modify it for queue storage).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...