Skip to content

Commit e543d36

Browse files
committed
anonymous blob access
1 parent c8f1326 commit e543d36

File tree

2 files changed

+36
-58
lines changed

2 files changed

+36
-58
lines changed

articles/storage/blobs/storage-manage-access-to-resources.md

Lines changed: 35 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ author: tamram
66

77
ms.service: storage
88
ms.topic: article
9-
ms.date: 04/30/2019
9+
ms.date: 09/19/2019
1010
ms.author: tamram
1111
ms.reviewer: cbrooks
1212
---
@@ -23,22 +23,15 @@ By default, a container and any blobs within it may be accessed only by a user t
2323

2424
You can configure a container with the following permissions:
2525

26-
* **No public read access:** The container and its blobs can be accessed only by the storage account owner. This is the default for all new containers.
27-
* **Public read access for blobs only:** Blobs within the container can be read by anonymous request, but container data is not available. Anonymous clients cannot enumerate the blobs within the container.
28-
* **Public read access for container and its blobs:** All container and blob data can be read by anonymous request. Clients can enumerate blobs within the container by anonymous request, but cannot enumerate containers within the storage account.
29-
30-
You can use the following to set container permissions:
31-
32-
* [Azure portal](https://portal.azure.com)
33-
* [Azure PowerShell](../common/storage-powershell-guide-full.md?toc=%2fazure%2fstorage%2fblobs%2ftoc.json)
34-
* [Azure CLI](../common/storage-azure-cli.md?toc=%2fazure%2fstorage%2fblobs%2ftoc.json#create-and-manage-blobs)
35-
* Programmatically, by using one of the storage client libraries or the REST API
26+
- **No public read access:** The container and its blobs can be accessed only by the storage account owner. This is the default for all new containers.
27+
- **Public read access for blobs only:** Blobs within the container can be read by anonymous request, but container data is not available. Anonymous clients cannot enumerate the blobs within the container.
28+
- **Public read access for container and its blobs:** All container and blob data can be read by anonymous request. Clients can enumerate blobs within the container by anonymous request, but cannot enumerate containers within the storage account.
3629

3730
### Set container public access level in the Azure portal
3831

3932
From the [Azure portal](https://portal.azure.com), you can update the public access level for one or more containers:
4033

41-
1. Navigate to your storage account in the Azure portal.
34+
1. Navigate to your storage account overview in the Azure portal.
4235
1. Under **Blob service** on the menu blade, select **Blobs**.
4336
1. Select the containers for which you want to set the public access level.
4437
1. Use the **Change access level** button to display the public access settings.
@@ -53,16 +46,28 @@ The following screenshot shows how to change the public access level for the sel
5346
5447
### Set container public access level with .NET
5548

56-
To set permissions for a container using C# and the Storage Client Library for .NET, first retrieve the container's existing permissions by calling the **GetPermissions** method. Then set the **PublicAccess** property for the **BlobContainerPermissions** object that is returned by the **GetPermissions** method. Finally, call the **SetPermissions** method with the updated permissions.
49+
To set permissions for a container using the Azure Storage client library for .NET, first retrieve the container's existing permissions by calling one of the following methods:
50+
51+
- [GetPermissions](/dotnet/api/microsoft.azure.storage.blob.cloudblobcontainer.getpermissions)
52+
- [GetPermissionsAsync](/dotnet/api/microsoft.azure.storage.blob.cloudblobcontainer.getpermissionsasync)
53+
54+
Next, set the **PublicAccess** property on the [BlobContainerPermissions](/dotnet/api/microsoft.azure.storage.blob.blobcontainerpermissions) object that is returned by the **GetPermissions** method.
55+
56+
Finally, call one of the following methods to update the container's permissions:
57+
58+
- [SetPermissions](/dotnet/api/microsoft.azure.storage.blob.cloudblobcontainer.setpermissions)
59+
- [SetPermissionsAsync](/dotnet/api/microsoft.azure.storage.blob.cloudblobcontainer.setpermissionsasync)
5760

5861
The following example sets the container's permissions to full public read access. To set permissions to public read access for blobs only, set the **PublicAccess** property to **BlobContainerPublicAccessType.Blob**. To remove all permissions for anonymous users, set the property to **BlobContainerPublicAccessType.Off**.
5962

6063
```csharp
61-
public static void SetPublicContainerPermissions(CloudBlobContainer container)
64+
private static async Task SetPublicContainerPermissions(CloudBlobContainer container)
6265
{
63-
BlobContainerPermissions permissions = container.GetPermissions();
66+
BlobContainerPermissions permissions = await container.GetPermissionsAsync();
6467
permissions.PublicAccess = BlobContainerPublicAccessType.Container;
65-
container.SetPermissions(permissions);
68+
await container.SetPermissionsAsync(permissions);
69+
70+
Console.WriteLine("Container {0} - permissions set to {1}", container.Name, permissions.PublicAccess);
6671
}
6772
```
6873

@@ -77,13 +82,15 @@ You can create a new service client object for anonymous access by providing the
7782
```csharp
7883
public static void CreateAnonymousBlobClient()
7984
{
80-
// Create the client object using the Blob storage endpoint.
81-
CloudBlobClient blobClient = new CloudBlobClient(new Uri(@"https://storagesample.blob.core.windows.net"));
85+
// Create the client object using the Blob storage endpoint for your account.
86+
CloudBlobClient blobClient = new CloudBlobClient(
87+
new Uri(@"https://storagesamples.blob.core.windows.net"));
8288

8389
// Get a reference to a container that's available for anonymous access.
8490
CloudBlobContainer container = blobClient.GetContainerReference("sample-container");
8591

86-
// Read the container's properties. Note this is only possible when the container supports full public read access.
92+
// Read the container's properties.
93+
// Note this is only possible when the container supports full public read access.
8794
container.FetchAttributes();
8895
Console.WriteLine(container.Properties.LastModified);
8996
Console.WriteLine(container.Properties.ETag);
@@ -98,9 +105,11 @@ If you have the URL to a container that is anonymously available, you can use it
98105
public static void ListBlobsAnonymously()
99106
{
100107
// Get a reference to a container that's available for anonymous access.
101-
CloudBlobContainer container = new CloudBlobContainer(new Uri(@"https://storagesample.blob.core.windows.net/sample-container"));
108+
CloudBlobContainer container = new CloudBlobContainer(
109+
new Uri(@"https://storagesamples.blob.core.windows.net/sample-container"));
102110

103111
// List blobs in the container.
112+
// Note this is only possible when the container supports full public read access.
104113
foreach (IListBlobItem blobItem in container.ListBlobs())
105114
{
106115
Console.WriteLine(blobItem.Uri);
@@ -115,45 +124,14 @@ If you have the URL to a blob that is available for anonymous access, you can re
115124
```csharp
116125
public static void DownloadBlobAnonymously()
117126
{
118-
CloudBlockBlob blob = new CloudBlockBlob(new Uri(@"https://storagesample.blob.core.windows.net/sample-container/logfile.txt"));
119-
blob.DownloadToFile(@"C:\Temp\logfile.txt", System.IO.FileMode.Create);
127+
CloudBlockBlob blob = new CloudBlockBlob(
128+
new Uri(@"https://storagesamples.blob.core.windows.net/sample-container/logfile.txt"));
129+
blob.DownloadToFile(@"C:\Temp\logfile.txt", FileMode.Create);
120130
}
121131
```
122132

123-
## Features available to anonymous users
124-
125-
The following table shows which operations may be called anonymously when a container is configured for public access.
126-
127-
| REST Operation | Public read access to container | Public read access to blobs only |
128-
| --- | --- | --- |
129-
| List Containers | Authorized requests only | Authorized requests only |
130-
| Create Container | Authorized requests only | Authorized requests only |
131-
| Get Container Properties | Anonymous requests allowed | Authorized requests only |
132-
| Get Container Metadata | Anonymous requests allowed | Authorized requests only |
133-
| Set Container Metadata | Authorized requests only | Authorized requests only |
134-
| Get Container ACL | Authorized requests only | Authorized requests only |
135-
| Set Container ACL | Authorized requests only | Authorized requests only |
136-
| Delete Container | Authorized requests only | Authorized requests only |
137-
| List Blobs | Anonymous requests allowed | Authorized requests only |
138-
| Put Blob | Authorized requests only | Authorized requests only |
139-
| Get Blob | Anonymous requests allowed | Anonymous requests allowed |
140-
| Get Blob Properties | Anonymous requests allowed | Anonymous requests allowed |
141-
| Set Blob Properties | Authorized requests only | Authorized requests only |
142-
| Get Blob Metadata | Anonymous requests allowed | Anonymous requests allowed |
143-
| Set Blob Metadata | Authorized requests only | Authorized requests only |
144-
| Put Block | Authorized requests only | Authorized requests only |
145-
| Get Block List (committed blocks only) | Anonymous requests allowed | Anonymous requests allowed |
146-
| Get Block List (uncommitted blocks only or all blocks) | Authorized requests only | Authorized requests only |
147-
| Put Block List | Authorized requests only | Authorized requests only |
148-
| Delete Blob | Authorized requests only | Authorized requests only |
149-
| Copy Blob | Authorized requests only | Authorized requests only |
150-
| Snapshot Blob | Authorized requests only | Authorized requests only |
151-
| Lease Blob | Authorized requests only | Authorized requests only |
152-
| Put Page | Authorized requests only | Authorized requests only |
153-
| Get Page Ranges | Anonymous requests allowed | Anonymous requests allowed |
154-
| Append Blob | Authorized requests only | Authorized requests only |
155-
156133
## Next steps
157134

158-
* [Authorization for the Azure Storage Services](https://docs.microsoft.com/rest/api/storageservices/authorization-for-the-azure-storage-services)
159-
* [Using Shared Access Signatures (SAS)](../common/storage-sas-overview.md?toc=%2fazure%2fstorage%2fblobs%2ftoc.json)
135+
- [Authorizing access to Azure Storage](../common/storage-auth.md)
136+
- [Grant limited access to Azure Storage resources using shared access signatures (SAS)](../common/storage-sas-overview.md)
137+
- [Blob Service REST API](/rest/api/storageservices/blob-service-rest-api)

articles/storage/common/storage-encryption-keys-cli.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ author: tamram
66

77
ms.service: storage
88
ms.topic: article
9-
ms.date: 06/24/2019
9+
ms.date: 09/17/2019
1010
ms.author: tamram
1111
ms.reviewer: cbrooks
1212
ms.subservice: common

0 commit comments

Comments
 (0)