Skip to content

Fixing SQL Import Export issue with Managed Identity #28285

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

debalinaroy
Copy link
Contributor

Description

There exists an issue with Import Export using Managed Identity where it asks for SQL Authentication Password even though it is not required. This PR fixes the issue by making the password parameter from the Import Export cmdlet optional

Mandatory Checklist

  • SHOULD update ChangeLog.md file(s) appropriately
    • Update src/{{SERVICE}}/{{SERVICE}}/ChangeLog.md.
      • A snippet outlining the change(s) made in the PR should be written under the ## Upcoming Release header in the past tense.
    • Should not change ChangeLog.md if no new release is required, such as fixing test case only.
  • SHOULD regenerate markdown help files if there is cmdlet API change. Instruction
  • SHOULD have proper test coverage for changes in pull request.
  • SHOULD NOT adjust version of module manually in pull request

@Copilot Copilot AI review requested due to automatic review settings July 28, 2025 09:41
Copy link

Thanks for your contribution! The pull request validation has started. Please revisit this comment for updated status.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes an issue with SQL Import/Export cmdlets when using Managed Identity authentication where the password parameter was required even though it's not needed for this authentication type.

  • Made the AdministratorLoginPassword parameter optional in the base cmdlet class
  • Updated the service adapter to only decrypt and set the password when not using Managed Identity authentication
  • Updated unit tests to reflect the parameter changes

Reviewed Changes

Copilot reviewed 8 out of 34 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
ImportExportCmdletArmBase.cs Made AdministratorLoginPassword parameter optional by removing Mandatory=true and ValidateNotNullOrEmpty attributes
ImportExportDatabaseAdapter.cs Added conditional logic to only set password when authentication type is not ManagedIdentity
AzureSqlDatabaseImportExportTests.cs Updated unit tests to expect AdministratorLoginPassword as non-mandatory parameter
ChangeLog.md Added changelog entries documenting the fix for both export and import cmdlets
Other test files Updated test session records and test scripts (not core to the PR's functionality)

Comment on lines 21 to 22
* Fixed `New-AzSqlDatabaseExport` to use SQL Authentication with ManagedIdentity without any manadatory password
* Fixed `New-AzSqlDatabaseImport` to use SQL Authentication with ManagedIdentity without any manadatory password
Copy link
Preview

Copilot AI Jul 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a spelling error: 'manadatory' should be 'mandatory'.

Suggested change
* Fixed `New-AzSqlDatabaseExport` to use SQL Authentication with ManagedIdentity without any manadatory password
* Fixed `New-AzSqlDatabaseImport` to use SQL Authentication with ManagedIdentity without any manadatory password
* Fixed `New-AzSqlDatabaseExport` to use SQL Authentication with ManagedIdentity without any mandatory password
* Fixed `New-AzSqlDatabaseImport` to use SQL Authentication with ManagedIdentity without any mandatory password

Copilot uses AI. Check for mistakes.

Comment on lines 21 to 22
* Fixed `New-AzSqlDatabaseExport` to use SQL Authentication with ManagedIdentity without any manadatory password
* Fixed `New-AzSqlDatabaseImport` to use SQL Authentication with ManagedIdentity without any manadatory password
Copy link
Preview

Copilot AI Jul 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a spelling error: 'manadatory' should be 'mandatory'.

Suggested change
* Fixed `New-AzSqlDatabaseExport` to use SQL Authentication with ManagedIdentity without any manadatory password
* Fixed `New-AzSqlDatabaseImport` to use SQL Authentication with ManagedIdentity without any manadatory password
* Fixed `New-AzSqlDatabaseExport` to use SQL Authentication with ManagedIdentity without any mandatory password
* Fixed `New-AzSqlDatabaseImport` to use SQL Authentication with ManagedIdentity without any mandatory password

Copilot uses AI. Check for mistakes.

@@ -81,6 +81,11 @@ public AzureSqlDatabaseImportExportBaseModel Export(AzureSqlDatabaseImportExport
parameters.AuthenticationType = exportRequest.AuthenticationType.ToString().ToLowerInvariant();
}

if (exportRequest.AuthenticationType != AuthenticationType.ManagedIdentity)
{
parameters.AdministratorLoginPassword = AzureSqlServerAdapter.Decrypt(exportRequest.AdministratorLoginPassword);
Copy link
Preview

Copilot AI Jul 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider checking if AdministratorLoginPassword is null before attempting to decrypt it, as making the parameter optional means it could be null even for non-ManagedIdentity authentication types.

Suggested change
parameters.AdministratorLoginPassword = AzureSqlServerAdapter.Decrypt(exportRequest.AdministratorLoginPassword);
if (!string.IsNullOrEmpty(exportRequest.AdministratorLoginPassword))
{
parameters.AdministratorLoginPassword = AzureSqlServerAdapter.Decrypt(exportRequest.AdministratorLoginPassword);
}

Copilot uses AI. Check for mistakes.

@@ -124,6 +129,11 @@ public AzureSqlDatabaseImportExportBaseModel ImportNewDatabase(AzureSqlDatabaseI
parameters.AuthenticationType = importRequest.AuthenticationType.ToString().ToLowerInvariant();
}

if (importRequest.AuthenticationType != AuthenticationType.ManagedIdentity)
{
parameters.AdministratorLoginPassword = AzureSqlServerAdapter.Decrypt(importRequest.AdministratorLoginPassword);
Copy link
Preview

Copilot AI Jul 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider checking if AdministratorLoginPassword is null before attempting to decrypt it, as making the parameter optional means it could be null even for non-ManagedIdentity authentication types.

Suggested change
parameters.AdministratorLoginPassword = AzureSqlServerAdapter.Decrypt(importRequest.AdministratorLoginPassword);
if (importRequest.AdministratorLoginPassword != null)
{
parameters.AdministratorLoginPassword = AzureSqlServerAdapter.Decrypt(importRequest.AdministratorLoginPassword);
}

Copilot uses AI. Check for mistakes.

@YanaXu
Copy link
Contributor

YanaXu commented Jul 29, 2025

/azp run azure-powershell - security-tools

Copy link
Contributor

Azure Pipelines successfully started running 1 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants