Skip to content

[SQL MI]Add support for Service principal and guest users in Set-AzSqlInstanceActiveDirectoryAdministrator cmdlet #12197

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

Merged
merged 19 commits into from
Jun 24, 2020

Conversation

amolagar5
Copy link
Contributor

@amolagar5 amolagar5 commented Jun 17, 2020

Added support for Service principal and guest users in Set-AzSqlInstanceActiveDirectoryAdministrator cmdlet

Checklist

  • I have read the Submitting Changes section of CONTRIBUTING.md
  • The title of the PR is clear and informative
  • The appropriate ChangeLog.md file(s) has been updated:
    • For any service, the ChangeLog.md file can be found at src/{{SERVICE}}/{{SERVICE}}/ChangeLog.md
    • A snippet outlining the change(s) made in the PR should be written under the ## Upcoming Release header -- no new version header should be added
  • The PR does not introduce breaking changes
  • If applicable, the changes made in the PR have proper test coverage
  • For public API changes to cmdlets:
    • a cmdlet design review was approved for the changes in this repository (Microsoft internal only)
    • the markdown help files have been regenerated using the commands listed here

@adxsdkps
Copy link
Collaborator

Can one of the admins verify this patch?

@amolagar5 amolagar5 requested a review from msJinLei June 17, 2020 13:20
@VeryEarly VeryEarly self-assigned this Jun 18, 2020
@VeryEarly
Copy link
Collaborator

VeryEarly commented Jun 18, 2020

  • Updated changelog.md
    please update ## Upcoming release session only

  • please add test cases to cover the new added logic

dmitarredz
dmitarredz previously approved these changes Jun 18, 2020
@amolagar5
Copy link
Contributor Author

  • Updated changelog.md
    please update ## Upcoming release session only
  • please add test cases to cover the new added logic

Hey @VeryEarly ,
will fix changeLog
can you please help me with tests. Exiting tests fail with this error. Manually scenario is working. Do we need to set some environment variable for this.
System.Management.Automation.ActionPreferenceStopException : The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: Unable to find a matching HTTP request for URL 'GET /0c1edf5d-e5c5-4aca-ab69-ef194134f44b/servicePrincipals?$filter=appId%20eq%20'52b6d571-5ff9-4b8f-92de-4a5b1bcdbbef'&api-version=1.6'. Calling method Item().
Stack Trace:
at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input)
at System.Management.Automation.PowerShell.Worker.ConstructPipelineAndDoWork(Runspace rs, Boolean performSyncInvoke)
at System.Management.Automation.PowerShell.Worker.CreateRunspaceIfNeededAndDoWork(Runspace rsToUse, Boolean isSync)
at System.Management.Automation.PowerShell.CoreInvokeHelper[TInput,TOutput](PSDataCollection1 input, PSDataCollection1 output, PSInvocationSettings settings)
at System.Management.Automation.PowerShell.CoreInvoke[TInput,TOutput](PSDataCollection1 input, PSDataCollection1 output, PSInvocationSettings settings)
at System.Management.Automation.PowerShell.CoreInvoke[TOutput](IEnumerable input, PSDataCollection`1 output, PSInvocationSettings settings)
at System.Management.Automation.PowerShell.Invoke(IEnumerable input, PSInvocationSettings settings)
at System.Management.Automation.PowerShell.Invoke()
at Microsoft.WindowsAzure.Commands.ScenarioTest.EnvironmentSetupHelper.RunPowerShellTest(String[] scripts) in D:\a\1\s\tools\ScenarioTest.ResourceManager\EnvironmentSetupHelper.cs:line 571
at Microsoft.Azure.Commands.ScenarioTest.SqlTests.SqlTestsBase.RunPowerShellTest(String[] scripts) in D:\a\1\s\src\Sql\Sql.Test\ScenarioTests\SqlTestsBase.cs:line 103
at Microsoft.Azure.Commands.Sql.Test.ScenarioTests.ManagedInstanceActiveDirectoryAdministratorTests.TestManagedInstanceActiveDirectoryAdministrator() in D:\a\1\s\src\Sql\Sql.Test\ScenarioTests\ManagedInstanceActiveDirectoryAdministratorTests.cs:line 42
Standard Output Messages:

@amolagar5
Copy link
Contributor Author

Hey @VeryEarly ,
will fix changeLog
can you please help me with tests. Exiting tests fail with this error. Manually scenario is working. Do we need to set some environment variable for this.
System.Management.Automation.ActionPreferenceStopException : The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: Unable to find a matching HTTP request for URL 'GET /0c1edf5d-e5c5-4aca-ab69-ef194134f44b/servicePrincipals?$filter=appId%20eq%20'52b6d571-5ff9-4b8f-92de-4a5b1bcdbbef'&api-version=1.6'. Calling method Item().
Stack Trace:
at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input)
at System.Management.Automation.PowerShell.Worker.ConstructPipelineAndDoWork(Runspace rs, Boolean performSyncInvoke)
at System.Management.Automation.PowerShell.Worker.CreateRunspaceIfNeededAndDoWork(Runspace rsToUse, Boolean isSync)
at System.Management.Automation.PowerShell.CoreInvokeHelper[TInput,TOutput](PSDataCollection1 input, PSDataCollection1 output, PSInvocationSettings settings)
at System.Management.Automation.PowerShell.CoreInvoke[TInput,TOutput](PSDataCollection1 input, PSDataCollection1 output, PSInvocationSettings settings)
at System.Management.Automation.PowerShell.CoreInvoke[TOutput](IEnumerable input, PSDataCollection`1 output, PSInvocationSettings settings)
at System.Management.Automation.PowerShell.Invoke(IEnumerable input, PSInvocationSettings settings)
at System.Management.Automation.PowerShell.Invoke()
at Microsoft.WindowsAzure.Commands.ScenarioTest.EnvironmentSetupHelper.RunPowerShellTest(String[] scripts) in D:\a\1\s\tools\ScenarioTest.ResourceManager\EnvironmentSetupHelper.cs:line 571
at Microsoft.Azure.Commands.ScenarioTest.SqlTests.SqlTestsBase.RunPowerShellTest(String[] scripts) in D:\a\1\s\src\Sql\Sql.Test\ScenarioTests\SqlTestsBase.cs:line 103
at Microsoft.Azure.Commands.Sql.Test.ScenarioTests.ManagedInstanceActiveDirectoryAdministratorTests.TestManagedInstanceActiveDirectoryAdministrator() in D:\a\1\s\src\Sql\Sql.Test\ScenarioTests\ManagedInstance

@msJinLei @dingmeng-xue any idea about this. looks like tests scenarios not working with service principals.

@VeryEarly
Copy link
Collaborator

Hey @VeryEarly ,
will fix changeLog
can you please help me with tests. Exiting tests fail with this error. Manually scenario is working. Do we need to set some environment variable for this.
System.Management.Automation.ActionPreferenceStopException : The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: Unable to find a matching HTTP request for URL 'GET /0c1edf5d-e5c5-4aca-ab69-ef194134f44b/servicePrincipals?$filter=appId%20eq%20'52b6d571-5ff9-4b8f-92de-4a5b1bcdbbef'&api-version=1.6'. Calling method Item().
Stack Trace:
at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input)
at System.Management.Automation.PowerShell.Worker.ConstructPipelineAndDoWork(Runspace rs, Boolean performSyncInvoke)
at System.Management.Automation.PowerShell.Worker.CreateRunspaceIfNeededAndDoWork(Runspace rsToUse, Boolean isSync)
at System.Management.Automation.PowerShell.CoreInvokeHelper[TInput,TOutput](PSDataCollection1 input, PSDataCollection1 output, PSInvocationSettings settings)
at System.Management.Automation.PowerShell.CoreInvoke[TInput,TOutput](PSDataCollection1 input, PSDataCollection1 output, PSInvocationSettings settings)
at System.Management.Automation.PowerShell.CoreInvoke[TOutput](IEnumerable input, PSDataCollection`1 output, PSInvocationSettings settings)
at System.Management.Automation.PowerShell.Invoke(IEnumerable input, PSInvocationSettings settings)
at System.Management.Automation.PowerShell.Invoke()
at Microsoft.WindowsAzure.Commands.ScenarioTest.EnvironmentSetupHelper.RunPowerShellTest(String[] scripts) in D:\a\1\s\tools\ScenarioTest.ResourceManager\EnvironmentSetupHelper.cs:line 571
at Microsoft.Azure.Commands.ScenarioTest.SqlTests.SqlTestsBase.RunPowerShellTest(String[] scripts) in D:\a\1\s\src\Sql\Sql.Test\ScenarioTests\SqlTestsBase.cs:line 103
at Microsoft.Azure.Commands.Sql.Test.ScenarioTests.ManagedInstanceActiveDirectoryAdministratorTests.TestManagedInstanceActiveDirectoryAdministrator() in D:\a\1\s\src\Sql\Sql.Test\ScenarioTests\ManagedInstance

@msJinLei @dingmeng-xue any idea about this. looks like tests scenarios not working with service principals.

In your updated code, there are API calls to get serviceprincipal, so please re-record testcase: https://github.com/Azure/azure-powershell/blob/amagarwa/dev/sqlmiaddSPGuestuserSupport/src/Sql/Sql.Test/ScenarioTests/ManagedInstanceActiveDirectoryAdministratorTests.ps1

@amolagar5
Copy link
Contributor Author

Hey @VeryEarly ,
will fix changeLog
can you please help me with tests. Exiting tests fail with this error. Manually scenario is working. Do we need to set some environment variable for this.
System.Management.Automation.ActionPreferenceStopException : The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: Unable to find a matching HTTP request for URL 'GET /0c1edf5d-e5c5-4aca-ab69-ef194134f44b/servicePrincipals?$filter=appId%20eq%20'52b6d571-5ff9-4b8f-92de-4a5b1bcdbbef'&api-version=1.6'. Calling method Item().
Stack Trace:
at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input)
at System.Management.Automation.PowerShell.Worker.ConstructPipelineAndDoWork(Runspace rs, Boolean performSyncInvoke)
at System.Management.Automation.PowerShell.Worker.CreateRunspaceIfNeededAndDoWork(Runspace rsToUse, Boolean isSync)
at System.Management.Automation.PowerShell.CoreInvokeHelper[TInput,TOutput](PSDataCollection1 input, PSDataCollection1 output, PSInvocationSettings settings)
at System.Management.Automation.PowerShell.CoreInvoke[TInput,TOutput](PSDataCollection1 input, PSDataCollection1 output, PSInvocationSettings settings)
at System.Management.Automation.PowerShell.CoreInvoke[TOutput](IEnumerable input, PSDataCollection`1 output, PSInvocationSettings settings)
at System.Management.Automation.PowerShell.Invoke(IEnumerable input, PSInvocationSettings settings)
at System.Management.Automation.PowerShell.Invoke()
at Microsoft.WindowsAzure.Commands.ScenarioTest.EnvironmentSetupHelper.RunPowerShellTest(String[] scripts) in D:\a\1\s\tools\ScenarioTest.ResourceManager\EnvironmentSetupHelper.cs:line 571
at Microsoft.Azure.Commands.ScenarioTest.SqlTests.SqlTestsBase.RunPowerShellTest(String[] scripts) in D:\a\1\s\src\Sql\Sql.Test\ScenarioTests\SqlTestsBase.cs:line 103
at Microsoft.Azure.Commands.Sql.Test.ScenarioTests.ManagedInstanceActiveDirectoryAdministratorTests.TestManagedInstanceActiveDirectoryAdministrator() in D:\a\1\s\src\Sql\Sql.Test\ScenarioTests\ManagedInstance

@msJinLei @dingmeng-xue any idea about this. looks like tests scenarios not working with service principals.

In your updated code, there are API calls to get serviceprincipal, so please re-record testcase: https://github.com/Azure/azure-powershell/blob/amagarwa/dev/sqlmiaddSPGuestuserSupport/src/Sql/Sql.Test/ScenarioTests/ManagedInstanceActiveDirectoryAdministratorTests.ps1

I see. that is the difficult part, last time I tried for 3 days and could not get it to work. Last dev has lef the team. :(, let me check if we want to re-record or just disable the test until we has a resource to fix test.

…to amagarwa/dev/sqlmiaddSPGuestuserSupport
After trying multiple times to re-record it, I had no luck.
…to amagarwa/dev/sqlmiaddSPGuestuserSupport
@amolagar5
Copy link
Contributor Author

amolagar5 commented Jun 22, 2020

  • Updated changelog.md
    please update ## Upcoming release session only
  • please add test cases to cover the new added logic

@VeryEarly I have marked the test as skip. I debugged more and looks like its the token that 's going with graph call, its wrong and using https://management.core.windows.net/ and not https://graph.windows.net/, looks like in debugging all places I added my token are called fine. so puzzling. When calling ActiveDirectoryClient.FilterGroups(filter).Where(gr => string.Equals(gr.DisplayName, displayName, StringComparison.OrdinalIgnoreCase)); in MockScenario, it picks up wrong token. Wondering if problem is in ActiveDirectoryClient itself not supporting mock tests.

If know how mock tests with AAD will work, I can schedule a meeting and show you what I am doing to get it working and understand what else can I do to make it work.

@VeryEarly
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link
Contributor

Azure Pipelines successfully started running 3 pipeline(s).

@VeryEarly VeryEarly merged commit a77b31e into master Jun 24, 2020
@wyunchi-ms wyunchi-ms deleted the amagarwa/dev/sqlmiaddSPGuestuserSupport branch January 10, 2024 02:01
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.

5 participants