Skip to content

Commit 0f7fb0d

Browse files
authored
Merge pull request #208046 from dannyevers/74145-generate-sas-uri
74145 generate sas uri
2 parents 82688a0 + 3366088 commit 0f7fb0d

File tree

1 file changed

+76
-102
lines changed

1 file changed

+76
-102
lines changed
Lines changed: 76 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -1,173 +1,148 @@
11
---
22
title: Generate a SAS URI for a VM image
3-
description: Generate a shared access signature (SAS) URI for a virtual hard disks (VHD) in Azure Marketplace.
3+
description: Generate a shared access signature (SAS) URI for a virtual hard disk (VHD) in Azure Marketplace.
44
ms.service: marketplace
55
ms.subservice: partnercenter-marketplace-publisher
66
ms.topic: how-to
77
ms.author: amhindma
88
author: amhindma
9-
ms.date: 08/15/2022
9+
ms.date: 08/16/2022
1010
---
1111

1212
# Generate a SAS URI for a VM image
1313

1414
> [!NOTE]
15-
> You don't need a SAS URI to publish your VM. You can simply share an image in Partner Center. Refer to [Create a virtual machine using an approved base](azure-vm-use-approved-base.md) or [Create a virtual machine using your own image](azure-vm-use-own-image.md) instructions.
15+
> A Shared access signature (SAS) URI can be used to publish your virtual machine (VM). Alternatively, you can share an image in Partner Center via Azure compute gallery. Refer to [Create a virtual machine using an approved base](azure-vm-use-approved-base.md) or [Create a virtual machine using your own image](azure-vm-use-own-image.md) for further instructions.
1616
17-
Generating SAS URIs for your VHDs has these requirements:
17+
Before getting started, you will need the following:
1818

19-
- Only List and Read permissions are required. Don't provide Write or Delete access.
20-
- The duration for access (expiry date) should be a minimum of three weeks from when the SAS URI is created.
21-
- To protect against UTC time changes, set the start date to one day before the current date. For example, if the current date is June 16, 2020, select 6/15/2020.
19+
- A virtual machine
20+
- A [storage account](/azure/storage/common/storage-account-create?tabs=azure-portal) with a container for storing the virtual hard drive (VHD)
21+
- Your [storage account key](/azure/storage/common/storage-account-keys-manage?tabs=azure-portal#view-account-access-keys)
2222

23-
## Extract vhd from a VM
23+
## Extract VHD from a VM
2424

2525
> [!NOTE]
26-
> You can skip this step if you already have a vhd uploaded in a Storage Account.
26+
> You can skip this step if you already have a VHD uploaded to a storage account.
2727
28-
To extract the vhd from your VM, you need to take a snapshot of your VM disk and extract vhd from the snapshot.
28+
To extract the VHD from your VM, you need to first take a snapshot of your VM disk and then extract the VHD from the snapshot into your storage account.
2929

30-
Start by taking a snapshot of the VM disk:
30+
### Take a snapshot of your VM disk
3131

32-
1. Sign in to the Azure portal.
33-
2. Starting at the upper-left, select Create a resource, then search for and select Snapshot.
34-
3. In the Snapshot blade, select Create.
35-
4. Enter a Name for the snapshot.
36-
5. Select an existing resource group or enter the name for a new one.
37-
6. For Source disk, select the managed disk to snapshot.
38-
7. Select the Account type to use to store the snapshot. Use Standard HDD unless you need it stored on a high performing SSD.
39-
8. Select Create.
32+
1. Sign in to the [Azure portal](https://www.portal.azure.com/).
33+
1. Select **Create a resource**, then search for and select **Snapshot**.
34+
1. In the Snapshot blade, select **Create**.
35+
1. Select the **Subscription**. Select an existing resource group within the selected subscription or **Create new** and enter the name for a new resource group to be created. This is the resource group the snapshot will be associated to.
36+
1. Enter a **Name** for the snapshot.
37+
1. For **Source type**, select **Disk**.
38+
1. Select the **Source subscription**, which is the subscription that contains the VM disk. This may be different from the destination subscription of the new snapshot.
39+
1. For **Source disk**, select the managed disk to snapshot.
40+
1. For the **Storage type**, select **Standard HDD** unless you need it stored on a high performing SSD.
41+
1. Select **Review + Create**. Upon successful validation, select **Create**.
4042

41-
### Extract the VHD
43+
### Extract the VHD into your storage account
4244

43-
Use the following script to export the snapshot into a VHD in your storage account.
45+
Use the following script to export the snapshot into a VHD in your storage account. For each of parameters, insert your information accordingly.
4446

4547
```azurecli
4648
#Provide the subscription Id where the snapshot is created
47-
$subscriptionId=yourSubscriptionId
49+
subscriptionId=yourSubscriptionId
4850
4951
#Provide the name of your resource group where the snapshot is created
50-
$resourceGroupName=myResourceGroupName
52+
resourceGroupName=myResourceGroupName
5153
5254
#Provide the snapshot name
53-
$snapshotName=mySnapshot
55+
snapshotName=mySnapshot
5456
5557
#Provide Shared Access Signature (SAS) expiry duration in seconds (such as 3600)
5658
#Know more about SAS here: https://docs.microsoft.com/azure/storage/storage-dotnet-shared-access-signature-part-1
57-
$sasExpiryDuration=3600
59+
sasExpiryDuration=3600
5860
59-
#Provide storage account name where you want to copy the underlying VHD file. Currently, only general purpose v1 storage is supported.
60-
$storageAccountName=mystorageaccountname
61+
#Provide storage account name where you want to copy the underlying VHD file.
62+
storageAccountName=mystorageaccountname
6163
6264
#Name of the storage container where the downloaded VHD will be stored.
63-
$storageContainerName=mystoragecontainername
65+
storageContainerName=mystoragecontainername
6466
65-
#Provide the key of the storage account where you want to copy the VHD
66-
$storageAccountKey=mystorageaccountkey
67+
#Provide the access key for the storage account that you want to copy the VHD to.
68+
storageAccountKey=mystorageaccountkey
6769
6870
#Give a name to the destination VHD file to which the VHD will be copied.
69-
$destinationVHDFileName=myvhdfilename.vhd
71+
destinationVHDFileName=myvhdfilename.vhd
7072
7173
az account set --subscription $subscriptionId
7274
73-
$sas=$(az snapshot grant-access --resource-group $resourceGroupName --name $snapshotName --duration-in-seconds $sasExpiryDuration --query [accessSas] -o tsv)
75+
sas=$(az snapshot grant-access --resource-group $resourceGroupName --name $snapshotName --duration-in-seconds $sasExpiryDuration --query [accessSas] -o tsv)
7476
7577
az storage blob copy start --destination-blob $destinationVHDFileName --destination-container $storageContainerName --account-name $storageAccountName --account-key $storageAccountKey --source-uri $sas
7678
```
7779

78-
### Script explanation
79-
This script uses following commands to generate the SAS URI for a snapshot and copies the underlying VHD to a storage account using the SAS URI. Each command in the table links to command specific documentation.
80+
This script above uses the following commands to generate the SAS URI for a snapshot and copies the underlying VHD to a storage account using the SAS URI.
8081

8182
|Command |Notes |
8283
|---------|---------|
83-
| az disk grant-access | Generates read-only SAS that is used to copy the underlying VHD file to a storage account or download it to on-premises |
84-
| az storage blob copy start | Copies a blob asynchronously from one storage account to another. Use az storage blob show to check the status of the new blob. |
84+
| az disk grant-access | Generates read-only SAS that is used to copy the underlying VHD file to a storage account or download it to on-premises. |
85+
| az storage blob copy start | Copies a blob asynchronously from one storage account to another. Use [az storage blob show](/cli/azure/storage/blob#az-storage-blob-show) to check the status of the new blob. |
8586

86-
## Generate the SAS address
87+
## Generate the SAS URI
8788

88-
There are two common tools used to create a SAS address (URL):
89+
There are two common tools used to create a SAS address (URI):
8990

90-
1. **Azure Storage Explorer** – Available on the Azure portal.
91-
2. **Azure CLI** – Recommended for non-Windows operating systems and automated or continuous integration environments.
91+
- **Azure Storage browser** – Available on the Azure portal.
92+
- **Azure CLI** – Recommended for non-Windows operating systems and automated or continuous integration environments.
9293

93-
### Using Tool 1: Azure Storage Explorer
94+
### Using Tool 1: Azure Storage browser
9495

95-
1. Go to your **Storage Account**.
96-
2. Open **Storage Explorer**.
96+
1. Go to your **Storage account**.
97+
2. Open **Storage browser** and select **blob containers**.
98+
3. In your **Container**, right-click the VHD file and select **Generate SAS**.
99+
4. In the **Shared Access Signature** menu that appears, complete the following fields:
97100

98-
:::image type="content" source="media/create-vm/storge-account-explorer.png" alt-text="Storage account window.":::
99-
100-
3. In the **Container**, right-click the VHD file and select **Get Share Access Signature**.
101-
4. In the **Shared Access Signature** dialog box, complete the following fields:
102-
103-
1. Start time – Permission start date for VHD access. Provide a date that is one day before the current date.
104-
2. Expiry time – Permission expiration date for VHD access. Provide a date at least three weeks beyond the current date.
105-
3. Permissions – Select the Read and List permissions.
106-
4. Container-level – Check the Generate container-level shared access signature URI check box.
107-
108-
![Shared access signature dialog box.](media/vm/create-sas-uri-storage-explorer.png)
109-
110-
5. To create the associated SAS URI for this VHD, select **Create**.
111-
6. Copy the URI and save it to a text file in a secure location. This generated SAS URI is for container-level access. To make it specific, edit the text file to add the VHD name.
112-
7. Insert your VHD name after the vhds string in the SAS URI (include a forward slash). The final SAS URI should look like this:
113-
114-
`<blob-service-endpoint-url> + /vhds/ + <vhd-name>? + <sas-connection-string>`
115-
116-
8. Repeat these steps for each VHD in the plans you will publish.
101+
1. Permissions – Select read permissions. Don’t provide write or delete permissions.
102+
1. Start date/time – This is the permission start date for VHD access. To protect against UTC time changes, provide a date that is one day before the current date. For example, if the current date is July 15, 2022, set the date as 07/14/2022.
103+
1. Expiry date/time – This is the permission expiration date for VHD access. Provide a date at least three weeks beyond the current date.
104+
105+
5. To create the associated SAS URI for this VHD, select **Generate SAS token and URL**.
106+
6. Copy the Blob SAS URL and save it to a text file in a secure location.
107+
7. Repeat these steps for each VHD you want to publish.
117108

118109
### Using Tool 2: Azure CLI
119110

120-
1. Download and install [Microsoft Azure CL](/cli/azure/install-azure-cli)I. Versions are available for Windows, macOS, and various distros of Linux.
121-
2. Create a PowerShell file (.ps1 file extension), copy in the following code, then save it locally.
111+
1. In Azure CLI, run the following command.
122112

123113
```azurecli-interactive
124-
az storage container generate-sas --connection-string 'DefaultEndpointsProtocol=https;AccountName=<account-name>;AccountKey=<account-key>;EndpointSuffix=core.windows.net' --name <container-name> --permissions rl --start '<start-date>' --expiry '<expiry-date>'
114+
az storage container generate-sas --connection-string 'DefaultEndpointsProtocol=https;AccountName=<account-name>;AccountKey=<account-key>;EndpointSuffix=core.windows.net' --name <container-name> --permissions r --start '<start-date>' --expiry '<expiry-date>'
125115
```
126116
127-
3. Edit the file to use the following parameter values. Provide dates in UTC datetime format, such as 2020-04-01T00:00:00Z.
128-
129-
- account-name – Your Azure storage account name.
130-
- account-key – Your Azure storage account key.
131-
- start-date – Permission start date for VHD access. Provide a date one day before the current date.
132-
- expiry-date – Permission expiration date for VHD access. Provide a date at least three weeks after the current date.
133-
134-
Here's an example of proper parameter values (at the time of this writing):
135-
136-
```azurecli-interactive
137-
az storage container generate-sas --connection-string 'DefaultEndpointsProtocol=https;AccountName=st00009;AccountKey=6L7OWFrlabs7Jn23OaR3rvY5RykpLCNHJhxsbn9ON c+bkCq9z/VNUPNYZRKoEV1FXSrvhqq3aMIDI7N3bSSvPg==;EndpointSuffix=core.windows.net' --name <container-name> -- permissions rl --start '2020-04-01T00:00:00Z' --expiry '2021-04-01T00:00:00Z'
138-
```
139-
140-
4. Save the changes.
141-
5. Using one of the following methods, run this script with administrative privileges to create a SAS connection string for container-level access:
142-
143-
- Run the script from the console. In Windows, right-click the script and select **Run as administrator**.
144-
- Run the script from a PowerShell script editor such as [Windows PowerShell ISE](/powershell/scripting/components/ise/introducing-the-windows-powershell-ise). This screen shows the creation of a SAS connection string within this editor:
145-
146-
[![creation of a SAS connection string within the PowerShell editor](media/vm/create-sas-uri-power-shell-ise.png)](media/vm/create-sas-uri-power-shell-ise.png#lightbox)
147-
148-
6. Copy the SAS connection string and save it to a text file in a secure location. Edit this string to add the VHD location information to create the final SAS URI.
149-
7. In the Azure portal, go to the blob storage that includes the VHD associated with the new URI.
150-
8. Copy the URL of the blob service endpoint:
117+
Before running the command above, remember to insert the following parameter values.
151118
152-
![Copying the URL of the blob service endpoint.](media/vm/create-sas-uri-blob-endpoint.png)
119+
| Parameter value | Description |
120+
| --------------- | ----------- |
121+
| account-name | Your Azure storage account name. |
122+
| account-key | Your Azure storage account key. |
123+
| container-name | Your blob container that hosts the VHD file. |
124+
| start-date | This is the permission start date for VHD access. Provide a date one day before the current date. For example, if the current date is July 15, 2022, set the date as 07/14/2022. Provide dates in UTC date/time format (YYYY-MM-DDT00:00:00Z), such as 2022-04-01T00:00:00Z. |
125+
| expiry-date | This is the permission expiration date for VHD access. Provide a date at least three weeks after the current date. Provide dates in UTC date/time format (YYYY-MM-DDT00:00:00Z), such as 2022-04-01T00:00:00Z. |
153126
154-
9. Edit the text file with the SAS connection string from step 6. Create the complete SAS URI using this format:
127+
1. Copy the SAS connection string and save it to a text file in a secure location. Edit this string to add the VHD location information to create the final SAS URI.
128+
1. In the Azure portal, go to the blob container that includes the VHD associated with the new URI.
129+
1. Copy the URL of the blob service endpoint.
130+
1. Edit the text file with the SAS connection string from step 2. Create the complete SAS URI using this format. Be sure to insert a “?” between the endpoint URL and the connection string.
155131
156-
`<blob-service-endpoint-url> + /vhds/ + <vhd-name>? + <sas-connection-string>`
132+
`<blob-service-endpoint-url>?<sas-connection-string>`
157133
158134
### Virtual machine SAS failure messages
159135
160-
Following are common issues encountered when working with shared access signatures (which are used to identify and share the uploaded VHDs for your solution), along with suggested resolutions.
136+
This table shows the common errors encountered when providing a shared access signatures (SAS) URI in Partner Center, along with suggested resolutions.
161137
162138
| Issue | Failure Message | Fix |
163139
| --- | --- | --- |
164-
| *Failure in copying images* | | |
165-
| "?" is not found in SAS URI | `Failure: Copying Images. Not able to download blob using provided SAS Uri.` | Update the SAS URI using recommended tools. |
166-
| "st" and "se" parameters not in SAS URI | `Failure: Copying Images. Not able to download blob using provided SAS Uri.` | Update the SAS URI with proper **Start Date** and **End Date** values. |
167-
| "sp=rl" not in SAS URI | `Failure: Copying Images. Not able to download blob using provided SAS Uri.` | Update the SAS URI with permissions set as `Read` and `List`. |
168-
| SAS URI has white spaces in VHD name | `Failure: Copying Images. Not able to download blob using provided SAS Uri.` | Update the SAS URI to remove white spaces. |
140+
| "?" is not found in SAS URI | `Must be a valid Azure shared access signature URI.` | Ensure that the SAS URI provided uses the proper syntax and includes the “?”character.<br>Syntax: `<blob-service-endpoint-url>?<sas-connection-string>` |
141+
| "st" parameter not in SAS URI | `Specified SAS URL cannot be reached.` | Update the SAS URI with proper **Start Date** ("st") value. |
142+
| "se" parameter not in SAS URI | `The end date parameter (se) is required.` | Update the SAS URI with proper **End Date** (“se”) value. |
143+
| "sp=r" not in SAS URI | `Missing Permissions (sp) must include 'read' (r).` | Update the SAS URI with permissions set as `Read` (“sp=r”). |
169144
| SAS URI Authorization error | `Failure: Copying Images. Not able to download blob due to authorization error.` | Review and correct the SAS URI format. Regenerate if necessary. |
170-
| SAS URI "st" and "se" parameters do not have full date-time specification | `Failure: Copying Images. Not able to download blob due to incorrect SAS Uri.` | SAS URI **Start Date** and **End Date** parameters (`st` and `se` substrings) must have full date-time format, such as `11-02-2017T00:00:00Z`. Shortened versions are invalid (some commands in Azure CLI may generate shortened values by default). |
145+
| SAS URI "st" and "se" parameters do not have full date-time specification | `The start time parameter (st) is not a valid date string.`<br>OR<br>`The end date parameter (se) is not a valid date string.` | SAS URI **Start Date** and **End Date** parameters (“st” and “se” substrings) must have full date-time format (YYYY-MM-DDT00:00:00Z), such as 11-02-2017T00:00:00Z. Shortened versions are invalid (some commands in Azure CLI may generate shortened values by default). |
171146
172147
For details, see [Grant limited access to Azure Storage resources using shared access signatures (SAS)](../storage/common/storage-sas-overview.md).
173148
@@ -176,12 +151,11 @@ For details, see [Grant limited access to Azure Storage resources using shared a
176151
Check the SAS URI before publishing it on Partner Center to avoid any issues related to SAS URI post submission of the request. This process is optional but recommended.
177152
178153
- The URI includes your VHD image filename, including the filename extension `.vhd`.
179-
- `Sp=rl` appears near the middle of your URI. This string shows Read and List access is specified.
154+
- `Sp=r` appears near the middle of your URI. This string shows Read permission is granted.
180155
- When `sr=c` appears, this means that container-level access is specified.
181156
- Copy and paste the URI into a browser to test-download the blob (you can cancel the operation before the download completes).
182157
183158
## Next steps
184159
185-
- If you run into issues, see [VM SAS failure messages](azure-vm-sas-failure-messages.md)
186-
- [Sign in to Partner Center](https://go.microsoft.com/fwlink/?linkid=2165935)
187160
- [Create a virtual machine offer on Azure Marketplace](azure-vm-offer-setup.md)
161+
- [Sign in to Partner Center and publish your image by providing the SAS URI](https://go.microsoft.com/fwlink/?linkid=2165935)

0 commit comments

Comments
 (0)