azure-cli icon indicating copy to clipboard operation
azure-cli copied to clipboard

Direct Sharing support for Azure Shared Image Gallery

Open axayjo opened this issue 5 years ago • 29 comments

Resource Provider CAPS, PIR, CRP

Description of Feature or Work Requested We now support direct sharing in Azure Shared Image Gallery. The feature allows you to share galleries with other subscriptions and tenants, without having to use Azure RBAC.

Since it's a new way of sharing, we need to make changes in 'az sig', 'az vm create' and 'az vmss create' commands. These are what we had in mind, but we can discuss the design in detail: Share Az sig update --permissions "private/groups/community" Az sig share --subscription-ids "subscription-id" --tenant-ids "tenant-id" --mgmtgrp-ids "managementgroup-ids" changes: Az sig share add --subscription-ids "subscription-id" --tenant-ids "tenant-id" #mgmtgrp will not be supported in this version Az sig share --reset - going from groups to private changes Az sig share reset

List galleries: Az sig group-list --scope "subscription/tenant/mgmtgrp" --location changes Az sig shared-gallery list --scope "subscription/tenant" --location

List image definition and version:

Az sig image-definition list --scope "subscription/tenant/mgmtgrp/community" --location changes Az sig shared-image-definition list --scope "subscription/tenant" --location Az sig share image-version list --scope "subscription/tenant/mgmtgrp/community" --location changes Az sig shared-image-version list --scope "subscription/tenant" --location #mgmtgrp/community will not be supported in this version Get: Az sig share image-definition show --name "is it gallery name or gallery unique name?" changes az sig shared-image-definition show --gallery-image-name "myGalleryImageName" --gallery-unique-name "galleryUniqueName" --location "myLocation" Or az sig shared-image-definition show –ids “resource id”

Minimum API Version Required

Swagger Link https://github.com/Azure/azure-rest-api-specs/blob/master/specification/compute/resource-manager/Microsoft.Compute/stable/2019-12-01/gallery.json updated: https://github.com/Azure/azure-rest-api-specs/blob/master/specification/compute/resource-manager/Microsoft.Compute/stable/2020-09-30/gallery.json and https://github.com/Azure/azure-rest-api-specs/blob/master/specification/compute/resource-manager/Microsoft.Compute/stable/2020-09-30/sharedGallery.json

Target Date First week of May

Updated commands according to discussion

see #17978

axayjo avatar Apr 05 '21 22:04 axayjo

Add it to S186.

qwordy avatar Apr 06 '21 02:04 qwordy

Could you provide the REST API to the command az sig share ? I don't see the corresponding API and arguments in the swagger file

xfz11 avatar Apr 14 '21 03:04 xfz11

From @kangsun-ctrl in SIG team, swagger file for direct sharing are https://github.com/Azure/azure-rest-api-specs/blob/master/specification/compute/resource-manager/Microsoft.Compute/stable/2020-09-30/gallery.json and https://github.com/Azure/azure-rest-api-specs/blob/master/specification/compute/resource-manager/Microsoft.Compute/stable/2020-09-30/sharedGallery.json Arguments are in SharingProfile and SharingUpdate.

xfz11 avatar Apr 19 '21 06:04 xfz11

Updating Shared Image Gallery commands example

Share

  • command: gallery update az sig update --permissions "private/groups "

  • command: Add/Remove sharing id to the sharing profile of a gallery. az sig share add/remove --subscription-ids "subscription-id" "subscription-id2" --tenant-ids "tenant-id"

  • command: reset sharing profile of a gallery. az sig share reset--gallery-name "myGalleryName" -g "myResourceGroup"

List galleries:

  • command: List shared galleries by subscription id or tenant id. az sig group-list --scope " tenant“ --location "myLocation"

List image definition and version: az sig share image-definition list --gallery-unique-name "galleryUniqueName" --location "myLocation" –scope "subscription/tenant " az sig share image-version list --gallery-image-name "myGalleryImageName" --gallery-unique-name "galleryUniqueName" --location "myLocation" --scope "subscription/tenant"

Get:

  • command: Get a shared gallery by subscription id or tenant id az sig share image-definition show --gallery-image-name "myGalleryImageName" --gallery-unique-name "galleryUniqueName" --location "myLocation" Or az sig share image-definition show –ids “resource id”

Changes Word 'share' is added in the middle of commands sig image-definition and sig image-definition to avoid influencing existing commands behavior.

xfz11 avatar Apr 30 '21 05:04 xfz11

Question: Swagger defined the list API parameter sharedTo to be a single value enum, so --scope can only be set as tenant or None. The designed commands require the option can be set as subscription/tenant

Response from service developer @kangsun-ctrl :

az sig group-list --scope " subscription|tenant“ --location "myLocation" For list call, in scope, we have subscription and tenant. And the subscription is the default scope, so in backend and swagger, user do not need to specify ‘sharedTo=tenant’ when they just want to list by subscriptionId. And if they want to list by tenant, then they need to specify ‘sharedTo=tenant’. Just in CLI, we want users to specify subscription or tenant. For get call, user do not need to specify scope and both subscriptionId and tenantid will be passed in. So we return the result as long as it is shared to user’s tenant or user’s subscription.

Solution: CLI allows users to set the --scope option to be subscription/tenant, but if user doesn't set the option or set it to be subscription, cli request the API with sharedTo parameters to be None.

Potential Problem CLI commands behavior doesn't align with Swagger. So it can not be auto-generated and has to be manually maintained

xfz11 avatar Apr 30 '21 05:04 xfz11

@kangsun-ctrl az sig group-list --scope tenant will cause a error:

# Request URL: 'https://management.azure.com/subscriptions/0b1f6471-1bf0-4dda-aec3-cb9272f09590/providers/Microsoft.Compute/locations/eastus/sharedGalleries?api-version=2020-09-30&sharedTo=tenant'

"error": {
  "code": "InternalOperationError",
  "message": "Getting dht entry '54826b22-38d6-4fb2-bad9-b7b93a3e9c5a' from dht table 'TenantSharingDHT' failed using CrpPir Client"
}

This error message will be really confusing for customers. To tell users the cause of error will be much user-friendlier

xfz11 avatar Apr 30 '21 08:04 xfz11

@kangsun-ctrl az sig group-list --scope tenant will cause a error:

# Request URL: 'https://management.azure.com/subscriptions/0b1f6471-1bf0-4dda-aec3-cb9272f09590/providers/Microsoft.Compute/locations/eastus/sharedGalleries?api-version=2020-09-30&sharedTo=tenant'

"error": {
  "code": "InternalOperationError",
  "message": "Getting dht entry '54826b22-38d6-4fb2-bad9-b7b93a3e9c5a' from dht table 'TenantSharingDHT' failed using CrpPir Client"
}

This error message will be really confusing for customers. To tell users the cause of error will be much user-friendlier

I already have a pull request out for this. https://msazure.visualstudio.com/One/_git/Compute-CPlat-PIR/pullrequest/4406008

kangsun-ctrl avatar Apr 30 '21 16:04 kangsun-ctrl

@xfz11 if we restrict az sig group-list --scope tenant to only 'tenant', will there still be an issue? How difficult is it to manually maintain?

olayemio avatar Apr 30 '21 17:04 olayemio

@xfz11 if we restrict az sig group-list --scope tenant to only 'tenant', will there still be an issue? How difficult is it to manually maintain?

It seems that mgmtgrp/community scope will be supported in the future, then CLI developers should add them manually. But if we align with Swagger, setting --scope to be only tenant as Swagger defined, then we can use codegen tool to automatically generate code. For this feature, manual maintaining will not cost much efforts. But it a trend to embrace codegen since maintaining all tremendous commands manually will be not realistic with the growing number of feature requests.

xfz11 avatar May 01 '21 05:05 xfz11

@xfz11 if we restrict az sig group-list --scope tenant to only 'tenant', will there still be an issue? How difficult is it to manually maintain?

It seems that mgmtgrp/community scope will be supported in the future, then CLI developers should add them manually. But if we align with Swagger, setting --scope to be only tenant as Swagger defined, then we can use codegen tool to automatically generate code. For this feature, manual maintaining will not cost much efforts. But it a trend to embrace codegen since maintaining all tremendous commands manually will be not realistic with the growing number of feature requests.

@xfz11 Actually I think if you will do it manually, then it is better to map scope=subscription to swagger with no sharedTo option, and map scope=tenant to swagger with sharedTo=tenant. It will be more clear for customer. Codegen is cool, we will keep it in mind and try to align our future development with CLI Codegen.

kangsun-ctrl avatar May 01 '21 05:05 kangsun-ctrl

@kangsun-ctrl Of course we can manually add the commands if you persist, I just raise the potential problem for discussion. Actually the key point is that present Swagger may be not clear enough to let users know what will happen calling the API. sharedTo is just described as The query parameter to decide what shared galleries to fetch when doing listing operations. and defined as a single value enum. Users will be not sure how to request by 'subscription' or what will happen if sharedTo is set to be None. I still think it is necessary to update Swagger now or later. Add subscription as the enum value as it is. And you can use default data field to specify the default value. That would make more sense.

xfz11 avatar May 01 '21 08:05 xfz11

For awareness, we change the commands

az sig share update --operation-type "Add" --groups type="Subscriptions" ids="34a4ab42" ids="380fd389" 
az sig share update --operation-type "Remove" --groups type="Subscriptions" ids="34a4ab42" ids="380fd389" 
az sig share update --operation-type "Reset"

to

az sig share add/remove  --subscription-ids "subscription-id" "subscription-id2" --tenant-ids "tenant-id" 
az sig share reset

for better user experience, which also corresponds with initial commands design

xfz11 avatar May 10 '21 11:05 xfz11

@xfz11 if customers want to specify multiple ids is this correct az sig share add --subscription-ids "subscription-id1" "subscription-id2" --tenant-ids "tenant-id1" "tenant-id2" --groups type="AADTenants" ids="c24c76a"

also can you explain what the --groups-type="AADTenants" ids="c24c76a" part means. Sorry if I'm asking a question you already answered before.

olayemio avatar May 10 '21 15:05 olayemio

@olayemio Sorry for the typos, I update the command without --groups-type="AADTenants" ids="c24c76a"

xfz11 avatar May 11 '21 01:05 xfz11

@xfz11 For List galleries: Can we change it to: az sig share list --scope " tenant“ --location "myLocation" That way it will be more consistent with other shared gallery resource list. @olayemio Hey Yemi, what do you think of this one?

kangsun-ctrl avatar May 11 '21 02:05 kangsun-ctrl

@kangsun-ctrl I like the suggestion you have for List galleries

olayemio avatar May 11 '21 14:05 olayemio

@kangsun-ctrl I'm not sure what you mean by designing the command to be 'share list --scope'. It seems that the command will share a list within the scope. But in fact, you just want to list the galleries instead of sharing. Maybe you should reconsider the commands design to make it easier to understand for customers

xfz11 avatar May 12 '21 05:05 xfz11

Since it may confuse customers that list command contains a verb 'share', and group-list seems to be not consistent with other commands. I'd like to change command az sig share image-definition list/show, az sig share image-version list/show , az sig group-list to az sig shared-image-definition list/show, az sig shared-image-version list/show , az sig shared-gallery list Then the commands would be more approachable and consistent. @kangsun-ctrl @olayemio What do you think of the changes?

xfz11 avatar May 18 '21 03:05 xfz11

Since it may confuse customers that list command contains a verb 'share', I'd like to change command az sig share image-definition list/show, az sig share image-version list/show to az sig shared-image-definition list/show, az sig shared-image-version list/show Then the commands would be more approachable. @kangsun-ctrl @olayemio What do you think of the changes?

This is a good point. I like this idea since our backend resource is 'Gallery'/'SharedGallery'

kangsun-ctrl avatar May 18 '21 03:05 kangsun-ctrl

Hi @xfz11 and @kangsun-ctrl , my proposal would be az sig image-definition --scope "subscription" --region "eastus list/show"

I don't want customers to look at the API and think shared-image-definition and image-definition are different resources.

olayemio avatar May 19 '21 18:05 olayemio