-
Notifications
You must be signed in to change notification settings - Fork 227
Add service account management for Reporting Services #2402
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
Changes from 7 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
8b8a28e
Add service account management for Reporting Services
johlju f161621
Enhance Set-SqlDscRSUrlReservation with Recreate mode and update tests
johlju 698125b
Refactor Get-SqlDscRSServiceAccount tests to simplify assertions and …
johlju 3579c5c
Update documentation for Get-SqlDscRSConfiguration to clarify CIM ins…
johlju e7d4cc1
Update parameter set in Set-SqlDscRSServiceAccount tests to include n…
johlju d9dcd41
Refactor tests for Set-SqlDscRSServiceAccount and Set-SqlDscRSUrlRese…
johlju d84e3ec
Add CommonTestHelper module import to BeforeAll in integration tests
johlju 633b587
Rename job 'Test_HQRM' to 'Test_QA' and add 'HQRM Test' job with arti…
johlju 7ba9c79
Split the `Test_HQRM` pipeline job into two parallel jobs (`Test_QA` …
johlju 087eff7
Add test to restart Reporting Services service after URL reservation …
johlju e8062d9
Add integration tests for database rights assignment and update servi…
johlju 72ec4ca
Refactor service account handling in database rights tests to use act…
johlju 3fe77af
Add test to create SQL Server login for new service account in databa…
johlju 19dd26e
Fix parameter usage in New-SqlDscLogin for granting database rights t…
johlju 6882dc3
Refactor database rights test to remove unnecessary error handling fo…
johlju 23430fd
Update dependencies for Reporting Services and BI Report Server integ…
johlju 3df8228
Add Get-SqlDscRSLogPath function and related tests for SQL Server Rep…
johlju 13a3722
Add integration tests for reinitializing Reporting Services after ser…
johlju 56f4c47
Enhance Request-SqlDscRSDatabaseRightsScript to validate UserName for…
johlju f1a6d52
Refactor error handling in Get-SqlDscRSLogPath function for improved …
johlju 413f09d
Enhance logging in Post.ServiceAccountChange.RS tests to include erro…
johlju b6bc2a1
Add New-SqlDscRSEncryptionKey and Remove-SqlDscRSEncryptionKey functi…
johlju 60532e2
Fix exception type for invalid UserName format in Request-SqlDscRSDat…
johlju 527ba0e
Enhance Remove-SqlDscRSEncryptionKey test to include encrypted inform…
johlju e322210
Enhance Remove-SqlDscRSEncryptionKey function to improve error handli…
johlju 7724eb7
Enhance Remove-SqlDscRSEncryptionKey tests to validate successful rem…
johlju 6b0e79f
Skip integration tests for SQL Server 2017 due to encryption key vali…
johlju 12dde57
Refactor error handling in encryption key functions and update integr…
johlju dd99447
Add wiki article for troubleshooting Power BI Report Server and SQL S…
johlju 4223ca2
Add troubleshooting guide for Power BI Report Server and SQL Server R…
johlju 765559b
Add Remove-SqlDscRSEncryptedInformation function and related tests; r…
johlju 1df2dcf
Refactor error handling in Remove-SqlDscRSEncryptedInformation and Re…
johlju 0b257fd
Add localization strings for Remove-SqlDscRSEncryptedInformation and …
johlju File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| <# | ||
| .SYNOPSIS | ||
| Gets the service account for SQL Server Reporting Services. | ||
|
|
||
| .DESCRIPTION | ||
| Gets the Windows service account for SQL Server Reporting Services or | ||
| Power BI Report Server from the `MSReportServer_ConfigurationSetting` | ||
| CIM instance. | ||
|
|
||
| This command returns the current service account name that is being | ||
| used by the Reporting Services Windows service. | ||
|
|
||
| The configuration CIM instance can be obtained using the | ||
| `Get-SqlDscRSConfiguration` command and passed via the pipeline. | ||
|
|
||
| .PARAMETER Configuration | ||
| Specifies the `MSReportServer_ConfigurationSetting` CIM instance for | ||
| the Reporting Services instance. This can be obtained using the | ||
| `Get-SqlDscRSConfiguration` command. This parameter accepts pipeline | ||
| input. | ||
|
|
||
| .EXAMPLE | ||
| Get-SqlDscRSConfiguration -InstanceName 'SSRS' | Get-SqlDscRSServiceAccount | ||
|
|
||
| Gets the service account for the Reporting Services instance 'SSRS'. | ||
|
|
||
| .EXAMPLE | ||
| $config = Get-SqlDscRSConfiguration -InstanceName 'SSRS' | ||
| Get-SqlDscRSServiceAccount -Configuration $config | ||
|
|
||
| Gets the service account using a stored configuration object. | ||
|
|
||
| .INPUTS | ||
| `Microsoft.Management.Infrastructure.CimInstance` | ||
|
|
||
| Accepts MSReportServer_ConfigurationSetting CIM instance via pipeline. | ||
|
|
||
| .OUTPUTS | ||
| `System.String` | ||
|
|
||
| Returns the service account name. | ||
|
|
||
| .NOTES | ||
| This is a convenience wrapper around accessing the | ||
| `WindowsServiceIdentityActual` property of the configuration CIM | ||
| instance. | ||
|
|
||
| .LINK | ||
| https://docs.microsoft.com/en-us/sql/reporting-services/wmi-provider-library-reference/msreportserver-configurationsetting-properties | ||
| #> | ||
| function Get-SqlDscRSServiceAccount | ||
| { | ||
| [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('UseSyntacticallyCorrectExamples', '', Justification = 'Because the examples use pipeline input the rule cannot validate.')] | ||
| [CmdletBinding()] | ||
| [OutputType([System.String])] | ||
| param | ||
| ( | ||
| [Parameter(Mandatory = $true, ValueFromPipeline = $true)] | ||
| [System.Object] | ||
| $Configuration | ||
| ) | ||
|
|
||
| process | ||
| { | ||
| $instanceName = $Configuration.InstanceName | ||
|
|
||
| Write-Verbose -Message ($script:localizedData.Get_SqlDscRSServiceAccount_Getting -f $instanceName) | ||
|
|
||
| return $Configuration.WindowsServiceIdentityActual | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,213 @@ | ||
| <# | ||
| .SYNOPSIS | ||
| Sets the service account for SQL Server Reporting Services. | ||
|
|
||
| .DESCRIPTION | ||
| Sets the Windows service account for SQL Server Reporting Services or | ||
| Power BI Report Server by calling the `SetWindowsServiceIdentity` | ||
| method on the `MSReportServer_ConfigurationSetting` CIM instance. | ||
|
|
||
| This command changes the Windows service account that the Reporting | ||
| Services service runs under. Sets file permissions on files and folders | ||
| in the report server installation directory. The account requires | ||
| LogonAsService rights in Windows, the specified account will be granted | ||
| this right. | ||
|
|
||
| The configuration CIM instance can be obtained using the | ||
| `Get-SqlDscRSConfiguration` command and passed via the pipeline. | ||
|
|
||
| .PARAMETER Configuration | ||
| Specifies the `MSReportServer_ConfigurationSetting` CIM instance for | ||
| the Reporting Services instance. This can be obtained using the | ||
| `Get-SqlDscRSConfiguration` command. This parameter accepts pipeline | ||
| input. | ||
|
|
||
| .PARAMETER Credential | ||
| Specifies the credentials for the new service account. The username | ||
| should be in the format 'DOMAIN\Username' for domain accounts or | ||
| 'Username' for local accounts. | ||
|
|
||
| .PARAMETER UseBuiltInAccount | ||
| Indicates that the account specified is a built-in Windows account | ||
| such as 'NT AUTHORITY\NetworkService' or 'NT AUTHORITY\LocalSystem'. | ||
| When this switch is used, only the username portion of the Credential | ||
| is used and the password is ignored. | ||
|
|
||
| .PARAMETER RestartService | ||
| If specified, restarts the Reporting Services service after changing | ||
| the service account. The service must be restarted for the change to | ||
| take effect. | ||
|
|
||
| .PARAMETER PassThru | ||
| If specified, returns the configuration CIM instance after setting | ||
| the service account. | ||
|
|
||
| .PARAMETER Force | ||
| If specified, suppresses the confirmation prompt. | ||
|
|
||
| .PARAMETER SuppressUrlReservationWarning | ||
| If specified, suppresses the warning message about URL reservations | ||
| needing to be updated when the service account changes. | ||
|
|
||
| .EXAMPLE | ||
| $credential = Get-Credential | ||
| Get-SqlDscRSConfiguration -InstanceName 'SSRS' | Set-SqlDscRSServiceAccount -Credential $credential -RestartService | ||
|
|
||
| Sets the service account for Reporting Services and restarts the service. | ||
|
|
||
| .EXAMPLE | ||
| $credential = New-Object System.Management.Automation.PSCredential('NT AUTHORITY\NetworkService', (New-Object System.Security.SecureString)) | ||
| Get-SqlDscRSConfiguration -InstanceName 'SSRS' | Set-SqlDscRSServiceAccount -Credential $credential -UseBuiltInAccount -Force | ||
|
|
||
| Sets the service account to NetworkService without confirmation. | ||
|
|
||
| .EXAMPLE | ||
| $credential = Get-Credential | ||
| Get-SqlDscRSConfiguration -InstanceName 'SSRS' | Set-SqlDscRSServiceAccount -Credential $credential -PassThru | ||
|
|
||
| Sets the service account and returns the configuration CIM instance. | ||
|
|
||
| .INPUTS | ||
| `Microsoft.Management.Infrastructure.CimInstance` | ||
|
|
||
| Accepts MSReportServer_ConfigurationSetting CIM instance via pipeline. | ||
|
|
||
| .OUTPUTS | ||
| None. By default, this command does not generate any output. | ||
|
|
||
| .OUTPUTS | ||
| `Microsoft.Management.Infrastructure.CimInstance` | ||
|
|
||
| When PassThru is specified, returns the MSReportServer_ConfigurationSetting | ||
| CIM instance. | ||
|
|
||
| .NOTES | ||
| The Reporting Services service must be restarted for the change to take | ||
| effect. Use the -RestartService parameter or manually restart the service. | ||
|
|
||
| URL reservations are created for the current service account. | ||
| Changing the service account requires updating all URL | ||
| reservations. | ||
|
|
||
| .LINK | ||
| https://docs.microsoft.com/en-us/sql/reporting-services/wmi-provider-library-reference/configurationsetting-method-setwindowsserviceidentity | ||
| #> | ||
| function Set-SqlDscRSServiceAccount | ||
| { | ||
| [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('UseSyntacticallyCorrectExamples', '', Justification = 'Because the examples use pipeline input the rule cannot validate.')] | ||
| [CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'High')] | ||
| [OutputType([System.Object])] | ||
| param | ||
| ( | ||
| [Parameter(Mandatory = $true, ValueFromPipeline = $true)] | ||
| [System.Object] | ||
| $Configuration, | ||
|
|
||
| [Parameter(Mandatory = $true)] | ||
| [System.Management.Automation.PSCredential] | ||
| $Credential, | ||
|
|
||
| [Parameter()] | ||
| [System.Management.Automation.SwitchParameter] | ||
| $UseBuiltInAccount, | ||
|
|
||
| [Parameter()] | ||
| [System.Management.Automation.SwitchParameter] | ||
| $RestartService, | ||
|
|
||
| [Parameter()] | ||
| [System.Management.Automation.SwitchParameter] | ||
| $PassThru, | ||
|
|
||
| [Parameter()] | ||
| [System.Management.Automation.SwitchParameter] | ||
| $Force, | ||
|
|
||
| [Parameter()] | ||
| [System.Management.Automation.SwitchParameter] | ||
| $SuppressUrlReservationWarning | ||
| ) | ||
|
|
||
| process | ||
| { | ||
| if ($Force.IsPresent -and -not $Confirm) | ||
| { | ||
| $ConfirmPreference = 'None' | ||
| } | ||
|
|
||
| $instanceName = $Configuration.InstanceName | ||
| $serviceName = $Configuration.ServiceName | ||
|
|
||
| $userName = $Credential.UserName | ||
|
|
||
| Write-Verbose -Message ($script:localizedData.Set_SqlDscRSServiceAccount_Setting -f $userName, $instanceName) | ||
|
|
||
| $descriptionMessage = $script:localizedData.Set_SqlDscRSServiceAccount_ShouldProcessDescription -f $userName, $instanceName | ||
| $confirmationMessage = $script:localizedData.Set_SqlDscRSServiceAccount_ShouldProcessConfirmation -f $userName | ||
| $captionMessage = $script:localizedData.Set_SqlDscRSServiceAccount_ShouldProcessCaption | ||
|
|
||
| if ($PSCmdlet.ShouldProcess($descriptionMessage, $confirmationMessage, $captionMessage)) | ||
| { | ||
| $passwordPlainText = '' | ||
|
|
||
| if (-not $UseBuiltInAccount.IsPresent) | ||
| { | ||
| $passwordBstr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($Credential.Password) | ||
|
|
||
| try | ||
| { | ||
| $passwordPlainText = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($passwordBstr) | ||
| } | ||
| finally | ||
| { | ||
| [System.Runtime.InteropServices.Marshal]::ZeroFreeBSTR($passwordBstr) | ||
| } | ||
| } | ||
|
|
||
| $invokeRsCimMethodParameters = @{ | ||
| CimInstance = $Configuration | ||
| MethodName = 'SetWindowsServiceIdentity' | ||
| Arguments = @{ | ||
| UseBuiltInAccount = $UseBuiltInAccount.IsPresent | ||
| Account = $userName | ||
| Password = $passwordPlainText | ||
| } | ||
| } | ||
|
|
||
| $currentServiceAccount = $Configuration.WindowsServiceIdentityActual | ||
|
|
||
| try | ||
| { | ||
| $null = Invoke-RsCimMethod @invokeRsCimMethodParameters -ErrorAction 'Stop' | ||
|
|
||
| if (-not $SuppressUrlReservationWarning.IsPresent -and $currentServiceAccount -ne $userName) | ||
| { | ||
| Write-Warning -Message ($script:localizedData.Set_SqlDscRSServiceAccount_UrlReservationWarning -f $currentServiceAccount, $userName) | ||
| } | ||
|
|
||
| if ($RestartService.IsPresent) | ||
| { | ||
| Write-Verbose -Message ($script:localizedData.Set_SqlDscRSServiceAccount_RestartingService -f $serviceName) | ||
|
|
||
| Restart-SqlDscRSService -ServiceName $serviceName -Force | ||
| } | ||
| } | ||
| catch | ||
| { | ||
| $PSCmdlet.ThrowTerminatingError( | ||
| [System.Management.Automation.ErrorRecord]::new( | ||
| ($script:localizedData.Set_SqlDscRSServiceAccount_FailedToSet -f $instanceName, $_.Exception.Message), | ||
| 'SSRSSA0001', | ||
| [System.Management.Automation.ErrorCategory]::InvalidOperation, | ||
| $Configuration | ||
| ) | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| if ($PassThru.IsPresent) | ||
| { | ||
| return $Configuration | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.