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

Various issues with the operation names in the Microsoft.Sql provider

Open SiloReed opened this issue 9 years ago • 6 comments

Cmdlet(s)

Set-AzureRmSqlDatabase, Get-AzureRMProviderOperation

PowerShell Version

5.1.15063.413

Module Version

AzureRM.Sql 3.1.0

OS Version

10.0.15063.413

Description

I'm attempting to determine the least amount of privileges necessary to update the tags on a SQL Database. I'm using a service principal with a custom role assignment and role definition. It appears that the Set-AzureRmSqlDatabase cmdlet is using the 'Microsoft.Sql/servers/databases/write' operation but this operation is not returned by Get-AzureRMProviderOperation and cannot be set with New-AzureRMRoleDefinition. Further, there are operations in the 'SQL DB Contributors' role that can't be get or set.

Script/Steps for Reproduction

It appears that I have to include the "Microsoft.Sql/servers/databases/*" action in the custom role definition, else this exception is thrown by Set-AzureRmSqlDatabase:

AuthorizationFailed: The client 'cc5bf1cc-ced3-4912-9da0-92f3bfbb9f6c' with object id
'cc5bf1cc-ced3-4912-9da0-92f3bfbb9f6c' does not have authorization to perform action
'Microsoft.Sql/servers/databases/write' over scope '/subscriptions/########-####-####-####-############/resourceGroups/
rg-ODSTest/providers/Microsoft.Sql/servers/azrodstst01/databases/AZDWTST01'.
    + CategoryInfo          : CloseError: (:) [Set-AzureRmSqlDatabase], CloudException
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.Sql.Database.Cmdlet.SetAzureSqlDatabase
    + PSComputerName        : localhost

It seems odd that the operation in the exception is named 'Microsoft.Sql/servers/databases/write', yet this operation is not returned by this command:

Get-AzureRMProviderOperation Microsoft.Sql/* | Where Operation -like "Microsoft.Sql/servers/databases/write*" | Select Operation, Description 

If I try to include 'Microsoft.Sql/servers/databases/write' in the array of actions in the custom role definition, then the New-AzureRMRoleDefinition cmdlet throws this exception:

New-AzureRMRoleDefinition : InvalidActionOrNotAction: 'Microsoft.Sql/servers/databases/write' does not match any of the actions supported by the providers.

Executing:

(Get-AzureRmRoleDefinition -Name 'SQL DB Contributor').Actions

Shows an action named 'Microsoft.Sql/servers/read' yet this action is not returned by:

Get-AzureRMProviderOperation Microsoft.Sql/* | Where Operation -eq "Microsoft.Sql/servers/read" | Select Operation, Description

Likewise, this command returns NotActions that aren't returned by Get-AzureRMProviderOperation Microsoft.Sql/* :

(Get-AzureRmRoleDefinition -Name 'SQL DB Contributor').NotActions

Such as: 'Microsoft.Sql/servers/databases/auditingSettings/*' 'Microsoft.Sql/servers/databases/auditRecords/read'

SiloReed avatar Jun 20 '17 19:06 SiloReed

@akromm Hey Adam, would you mind taking a look at this issue?

cormacpayne avatar Jun 20 '17 20:06 cormacpayne

Hi @SiloReed, thanks for reporting this. I have investigated the issue and determined the cause. To fix this it will require some backend changes and deployment. I will update when I have a timeline for the expected fix.

Update: changed username

akromm-zz avatar Jun 20 '17 21:06 akromm-zz

@SiloReed ^

cormacpayne avatar Jun 20 '17 22:06 cormacpayne

@SiloReed I expect the fix to be rolled out hopefully by the end of next week (June 30).

akromm-zz avatar Jun 23 '17 17:06 akromm-zz

@SiloReed The fix has been rolled out worldwide and your issue should be resolved now. Can you try again and let me know if it is working for you?

akromm-zz avatar Jun 29 '17 16:06 akromm-zz

@akromm I re-tested and I can happily confirm that everything looks good on my end. Thanks!

SiloReed avatar Jun 30 '17 19:06 SiloReed