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

Set-AzSqlDatabaseVulnerabilityAssessmentRuleBaseline not working properly with single rule

Open MonikaReddy-MSFT opened this issue 6 years ago • 5 comments

The BaselineResult parameter cannot accept single line of input. Say Set-AzSqlDatabaseVulnerabilityAssessmentRuleBaseline -ResourceGroupName $rgname -ServerName $serverName -DatabaseName $databasename -RuleId "VA2108" ` -BaselineResult @( 'Principal1' , 'db_ddladmin', 'SQL_USER','DATABASE')

Result showing in portal is not parsing correctly https://user-images.githubusercontent.com/37126106/83715214-bfa97580-a5e1-11ea-8d6b-fd2dd3dcf90e.png

https://github.com/MicrosoftDocs/azure-docs-powershell/issues/1421

MonikaReddy-MSFT avatar Jun 08 '20 16:06 MonikaReddy-MSFT

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @azureSQLGitHub.

ghost avatar Jun 09 '20 02:06 ghost

I have added SQL team. @MonikaReddy-MSFT , could you share the debug message for Set-AzSqlDatabaseVulnerabilityAssessmentRuleBaseline? You need to set $DebugPreference="Continue" and execute your cmdlet again.

dingmeng-xue avatar Jun 09 '20 02:06 dingmeng-xue

@dingmeng-xue - This information is provided to us - This is a potential issue with the following cmdlet Set-AzSqlDatabaseVulnerabilityAssessmentRuleBaseline where the cmdlet requires at least two parameters for the BaselineResult. Customer has been requested to open an issue on this repository specifically, as it is a PowerShell issue and not an issue with the MicrosoftDocs page (per issue 56304).

MonikaReddy-MSFT avatar Jun 09 '20 21:06 MonikaReddy-MSFT

I've noticed this same issue when attempting to use the Set-AzSqlDatabaseVulnerabilityAssessmentRuleBaseline command.

If I use it while passing a single sub-array in the baseline like so

$baselineResult = @(
    @('SCHEMA', 'dbo', 'EXECUTE', 'EXTERNAL_GROUP', 'External Group Name')
)

Set-AzSqlDatabaseVulnerabilityAssessmentRuleBaseline `
    -ResourceGroupName 'fs***************rg' `
    -ServerName 'fs**************w' `
    -DatabaseName 'Configuration' `
    -RuleId 'VA2032' `
    -BaselineResult $baselineResult `
    -Debug

it has the following debug output, which incorrectly sets the baseline in a manner seen in the above picture

DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
PUT

Absolute Uri:
https://management.azure.com/subscriptions/3a***********76/resourceGroups/fs*******************rg/providers/Microsoft.Sql/servers/fs***************vw/databases/Co*********on/vulnerabilityAssessments/default/rules/VA2032/baselines/default?api-version=2017-03-01-preview

Headers:
x-ms-client-request-id        : 10393db3-2824-4cb2-b946-3a1b9c65f535
Accept-Language               : en-US

Body:
{
  "properties": {
    "baselineResults": [
      {
        "result": [
          "SCHEMA"
        ]
      },
      {
        "result": [
          "dbo"
        ]
      },
      {
        "result": [
          "EXECUTE"
        ]
      },
      {
        "result": [
          "EXTERNAL_GROUP"
        ]
      },
      {
        "result": [
          "External Group Name"
        ]
      }
    ]
  }
}


DEBUG: ============================ HTTP RESPONSE ============================

Status Code:
OK

Headers:
Cache-Control                 : no-cache
Pragma                        : no-cache
x-ms-request-id               : 4ba576c1-a95a-43a9-ab65-a85481906083
Server                        : Microsoft-HTTPAPI/2.0
x-ms-ratelimit-remaining-subscription-writes: 1198
x-ms-correlation-request-id   : 0b2dda97-e914-4e21-92b0-59308ef83629
x-ms-routing-request-id       : NORTHCENTRALUS:20200806T155135Z:0b2dda97-e914-4e21-92b0-59308ef83629
Strict-Transport-Security     : max-age=31536000; includeSubDomains
X-Content-Type-Options        : nosniff
Date                          : Thu, 06 Aug 2020 15:51:34 GMT

Body:
{
  "properties": {
    "baselineResults": [
      {
        "result": [
          "SCHEMA"
        ]
      },
      {
        "result": [
          "dbo"
        ]
      },
      {
        "result": [
          "EXECUTE"
        ]
      },
      {
        "result": [
          "EXTERNAL_GROUP"
        ]
      },
      {
        "result": [
          "External Group Name"
        ]
      }
    ]
  },
  "id": "/subscriptions/3a***********76/resourceGroups/fs*******************rg/providers/Microsoft.Sql/servers/fs***************vw/databases/Co*********on/vulnerabilityAssessments/Default/rules/VA2032/baselines/default",
  "name": "Default",
  "type": "Microsoft.Sql/servers/databases/vulnerabilityAssessments/rules/baselines"
}

However, if multiple sub-arrays are supplied in the baseline result to set,

$baselineResult = @(
    @('SCHEMA', 'dbo', 'EXECUTE', 'EXTERNAL_GROUP', 'External Group Name'),
    @('SCHEMA', 'dbo','EXECUTE', 'EXTERNAL_GROUP', 'Another Group Name')
)

Set-AzSqlDatabaseVulnerabilityAssessmentRuleBaseline `
    -ResourceGroupName 'fs***************rg' `
    -ServerName 'fs**************w' `
    -DatabaseName 'Configuration' `
    -RuleId 'VA2032' `
    -BaselineResult $baselineResult `
    -Debug

The debug output shows the array's being correctly passed to the rest API

DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
PUT

Absolute Uri:
https://management.azure.com/subscriptions/3a***********76/resourceGroups/fs*******************rg/providers/Microsoft.Sql/servers/fs***************vw/databases/Co*********on/vulnerabilityAssessments/default/rules/VA2032/baselines/default?api-version=2017-03-01-preview

Headers:
x-ms-client-request-id        : d6d0cb83-a3f9-40fb-8491-ea4f3439be3d
Accept-Language               : en-US

Body:
{
  "properties": {
    "baselineResults": [
      {
        "result": [
          "SCHEMA",
          "dbo",
          "EXECUTE",
          "EXTERNAL_GROUP",
          "External Group Name"
        ]
      },
      {
        "result": [
          "SCHEMA",
          "dbo",
          "EXECUTE",
          "EXTERNAL_GROUP",
          "Another Group Name"
        ]
      }
    ]
  }
}


DEBUG: ============================ HTTP RESPONSE ============================

Status Code:
OK

Headers:
Cache-Control                 : no-cache
Pragma                        : no-cache
x-ms-request-id               : f49cec16-404d-4077-8cee-bdab33bcd6f8
Server                        : Microsoft-HTTPAPI/2.0
x-ms-ratelimit-remaining-subscription-writes: 1199
x-ms-correlation-request-id   : 3f748bc5-4d69-4639-b9c1-b6891f4b21c6
x-ms-routing-request-id       : NORTHCENTRALUS:20200806T155518Z:3f748bc5-4d69-4639-b9c1-b6891f4b21c6
Strict-Transport-Security     : max-age=31536000; includeSubDomains
X-Content-Type-Options        : nosniff
Date                          : Thu, 06 Aug 2020 15:55:18 GMT

Body:
{
  "properties": {
    "baselineResults": [
      {
        "result": [
          "SCHEMA",
          "dbo",
          "EXECUTE",
          "EXTERNAL_GROUP",
          "External Group Name"
        ]
      },
      {
        "result": [
          "SCHEMA",
          "dbo",
          "EXECUTE",
          "EXTERNAL_GROUP",
          "Another Group Name"
        ]
      }
    ]
  },
  "id": "/subscriptions/3a***********76/resourceGroups/fs*******************rg/providers/Microsoft.Sql/servers/fs***************vw/databases/Co*********on/vulnerabilityAssessments/Default/rules/VA2032/baselines/default",
  "name": "Default",
  "type": "Microsoft.Sql/servers/databases/vulnerabilityAssessments/rules/baselines"
}



DEBUG: AzureQoSEvent: CommandName - Set-AzSqlDatabaseVulnerabilityAssessmentRuleBaseline; IsSuccess - True; Duration - 00:00:00.8417485;
DEBUG: Finish sending metric.
DEBUG: 10:55:19 AM - SetAzureSqlDatabaseVulnerabilityAssessmentRuleBaseline end processing.

jonarmstrong avatar Aug 06 '20 15:08 jonarmstrong

This can be worked around by NOT using the default powershell array type and using a [System.Collections.ArrayList] instead, like so

$arrayList = [System.Collections.ArrayList]::new()
$arrayList.Add(@('SCHEMA', 'dbo', 'EXECUTE', 'EXTERNAL_GROUP', 'External Group Name'))

Set-AzSqlDatabaseVulnerabilityAssessmentRuleBaseline `
    -ResourceGroupName 'fs***************rg' `
    -ServerName 'fs**************w' `
    -DatabaseName 'Configuration' `
    -RuleId 'VA2032' `
    -BaselineResult $arrayList `
    -Debug

which yield the following debug output, which shows the array being correctly passed to the rest API

DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
PUT

Absolute Uri:
https://management.azure.com/subscriptions/3a***********76/resourceGroups/fs*******************rg/providers/Microsoft.Sql/servers/fs***************vw/databases/Co*********on/vulnerabilityAssessments/default/rules/VA2032/baselines/default?api-version=2017-03-01-preview

Headers:
x-ms-client-request-id        : d069b25b-eef4-4bc4-a721-7c97e5419f82
Accept-Language               : en-US

Body:
{
  "properties": {
    "baselineResults": [
      {
        "result": [
          "SCHEMA",
          "dbo",
          "EXECUTE",
          "EXTERNAL_GROUP",
          "External Group Name"
        ]
      }
    ]
  }
}


DEBUG: ============================ HTTP RESPONSE ============================

Status Code:
OK

Headers:
Cache-Control                 : no-cache
Pragma                        : no-cache
x-ms-request-id               : 9c424880-914f-42da-ba51-a5a49414627d
Server                        : Microsoft-HTTPAPI/2.0
x-ms-ratelimit-remaining-subscription-writes: 1199
x-ms-correlation-request-id   : 58c2e1fc-881b-4f76-b9c8-dda36a476380
x-ms-routing-request-id       : NORTHCENTRALUS:20200806T160843Z:58c2e1fc-881b-4f76-b9c8-dda36a476380
Strict-Transport-Security     : max-age=31536000; includeSubDomains
X-Content-Type-Options        : nosniff
Date                          : Thu, 06 Aug 2020 16:08:43 GMT

Body:
{
  "properties": {
    "baselineResults": [
      {
        "result": [
          "SCHEMA",
          "dbo",
          "EXECUTE",
          "EXTERNAL_GROUP",
          "External Group Name"
        ]
      }
    ]
  },
  "id": "/subscriptions/3a***********76/resourceGroups/fs*******************rg/providers/Microsoft.Sql/servers/fs***************vw/databases/Co*********on/vulnerabilityAssessments/Default/rules/VA2032/baselines/default",
  "name": "Default",
  "type": "Microsoft.Sql/servers/databases/vulnerabilityAssessments/rules/baselines"
}



DEBUG: AzureQoSEvent: CommandName - Set-AzSqlDatabaseVulnerabilityAssessmentRuleBaseline; IsSuccess - True; Duration - 00:00:00.7078764;
DEBUG: Finish sending metric.
DEBUG: 11:08:44 AM - SetAzureSqlDatabaseVulnerabilityAssessmentRuleBaseline end processing.

jonarmstrong avatar Aug 06 '20 16:08 jonarmstrong